How to use the danger/distribution/runner/runners/inline.runDangerfileEnvironment function in danger

To help you get started, we’ve selected a few danger examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github danger / peril / api / source / runner / run.ts View on Github external
for (const path of input.paths) {
    const rep = dangerRepresentationForPath(path)

    const defaultRepoSlug = payload.dsl.github.pr.base.repo.full_name
    const dangerfileContent = await getGitHubFileContentsFromLocation(token, rep, defaultRepoSlug)
    contents.push(dangerfileContent)
  }

  // Because it's not feasible to get stderr from hyper
  process.stderr.write = process.stdout.write

  // Run it
  runtimeEnv = await inlineRunner.createDangerfileRuntimeEnvironment(context)
  // Use custom module resolution inside the danger env
  const restoreOriginalModuleLoader = overrideRequire(shouldUseGitHubOverride, customGitHubResolveRequest(token))
  const results = await inlineRunner.runDangerfileEnvironment(paths, contents, runtimeEnv)
  restoreOriginalModuleLoader()

  // Give a small summary
  logger.info(
    `f: ${results.fails.length} w: ${results.warnings.length} m: ${results.messages.length} md: ${
      results.markdowns.length
    }`
  )

  // Wait till the end of the process to print out the results. Will
  // only post the results when the process has succeeded, leaving the
  // host process to create a message from the logs.
  exitHook((callback: () => void) => {
    const endTime = new Date().getTime()
    const duration = (startTime - endTime) / 1000
    logger.info(`Danger run finished in ${duration}, sending results`)
github danger / peril / api / source / runner / run.ts View on Github external
logger.info(`Process finished, sending results`)
    postResultsCall(
      input.perilSettings.perilAPIRoot,
      input.perilSettings.perilJWT,
      input.perilSettings.event,
      input.paths,
      1234,
      process.env.HYPER_CALL_ID || ""
    ).then(callback)
  })

  runtimeEnv = await inlineRunner.createDangerfileRuntimeEnvironment(context)

  // Use custom module resolution inside the danger env
  const restoreOriginalModuleLoader = overrideRequire(shouldUseGitHubOverride, customGitHubResolveRequest(token))
  await inlineRunner.runDangerfileEnvironment(paths, contents, runtimeEnv, payload.webhook)

  // Restore the original module loader.
  restoreOriginalModuleLoader()
}