How to use the danger/distribution/platforms/GitHub.GitHub 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 / github / events / createPRDSL.ts View on Github external
export const createPRJSONDSL = async (githubAPI: GitHubAPI) => {
  const gh = GitHub(githubAPI)
  const platform = getPerilPlatformForDSL(RunType.pr, gh, {})
  // These are what Danger JS uses to pass info to sub-commands
  // peril scopes all of its settings elsewhere, so a blank is fine
  const cliArgs = {} as any
  return await jsonDSLGenerator(platform, source, cliArgs)
}
github danger / peril / api / source / danger / danger_runner.ts View on Github external
export async function runDangerForInstallation(
  eventName: string,
  contents: string[],
  references: DangerfileReferenceString[],
  api: GitHubAPI | null,
  type: RunType,
  installationRun: InstallationToRun,
  payload: Payload
) {
  // We need this for things like repo slugs, PR IDs etc
  // https://github.com/danger/danger-js/blob/master/source/ci_source/ci_source.js

  const DSL = payload.dsl
  const gh = api ? GitHub(api) : null
  const platform = getPerilPlatformForDSL(type, gh, payload.dsl)

  const exec = await executorForInstallation(platform, vm2, installationRun.settings)

  const localDangerfilePaths = references.map(ref =>
    path.resolve("./" + perilPrefix + ref)
  )

  // Allow custom peril funcs to come from the task/scheduler DSL
  if (runtimeEnvironment === RuntimeEnvironment.Standalone) {
    const perilFromRunOrTask = DSL && (DSL as any).peril
    const peril = await perilObjectForInstallation(installationRun, process.env, perilFromRunOrTask)

    const token = gh ? gh.api.token : "";

    const restoreOriginalModuleLoader = overrideRequire(shouldUseGitHubOverride,
github danger / peril / api / source / runner / run.ts View on Github external
const runDangerPR = async (
  installation: InstallationToRun,
  input: PerilRunnerBootstrapJSON,
  payload: ValidatedPayload
) => {
  if (!payload.dsl.github) {
    logger.error("PR payload did not have a github")
    return
  }

  const token = payload.dsl.settings.github.accessToken
  const pr = payload.dsl.github.pr

  const perilGHAPI = githubAPIForCommentable(token, pr.base.repo.full_name, pr.number)
  const perilGH = GitHub(perilGHAPI)

  const platform = getPerilPlatformForDSL(RunType.pr, perilGH, payload.dsl)
  const exec = executorForInstallation(platform, inlineRunner, input.perilSettings)

  // Set up the Danger runtime env
  const runtimeDSL = await jsonToDSL(payload.dsl, source)
  const context = contextForDanger(runtimeDSL)
  const peril = await perilObjectForInstallation(installation, input.perilSettings.envVars, input)
  await appendPerilContextToDSL(installation.iID, token, context, peril)

  // Provide a prefix to files so that we know what requires are based on a dangerfile relative path
  const paths = input.paths.map(p => `${perilPrefix}${p}`)

  // Grab all the contents before to pass into the runner
  const contents: string[] = []
  for (const path of input.paths) {
github danger / peril / api / source / api / pr / dsl.ts View on Github external
// This has to be set for public usage.
  if (!PERIL_ORG_INSTALLATION_ID) {
    throw new Error("You can't support PR DSLs without setting up the PERIL_ORG_INSTALLATION_ID")
  }

  const token = await getTemporaryAccessTokenForInstallation(PERIL_ORG_INSTALLATION_ID)

  const ghDetails = {
    fullName: query.owner + "/" + query.repo,
    prID: query.number,
  }

  const githubAPI = githubAPIForCommentable(token, ghDetails.fullName, ghDetails.prID)

  const gh = GitHub(githubAPI)
  const platform = getPerilPlatformForDSL(RunType.pr, gh, {})

  const exec = await executorForInstallation(platform, inline, {})
  const dangerDSL = await exec.dslForDanger()

  // Remove this to reduce data
  if (dangerDSL.github) {
    dangerDSL.github.api = {} as any
  }

  // TODO: include Danger version number in JSON
  return res.status(400).jsonp({
    danger: dangerDSL,
    status: "OK",
  })
}
github danger / peril / api / source / github / events / utils / commenting.ts View on Github external
export const commentOnResults = async (
  dslType: RunType,
  results: DangerResults,
  token: string,
  settings: GitHubRunSettings,
  installationSettings: GitHubInstallationSettings
) => {
  const githubAPI = githubAPIForCommentable(token, settings.repoName!, settings.commentableID)
  const gh = GitHub(githubAPI)
  const platform = getPerilPlatformForDSL(dslType, gh, {})
  const exec = executorForInstallation(platform, vm2, installationSettings)

  // Don't pass a git dsl object here since we don't have one
  // This means inline comments won't work
  await exec.handleResults(results)
}
github danger / peril / api / source / api / _tests / fixtureAPI.ts View on Github external
export const fixturedAPI = (repoSlug?: string, pullRequestID?: string): GitHubType => {
  repoSlug = repoSlug || "artsy/emission"
  pullRequestID = pullRequestID || "1"
  const api = new GitHubAPI({ repoSlug, pullRequestID }, "ABCDE")
  const platform = GitHub(api)

  api.getPullRequestInfo = requestWithFixturedJSON("github_pr.json")
  api.getPullRequestDiff = requestWithFixturedContent("github_diff.diff")
  api.getPullRequestCommits = requestWithFixturedJSON("github_commits.json")
  api.getReviewerRequests = requestWithFixturedJSON("github_requested_reviewers.json")
  api.getReviews = requestWithFixturedJSON("github_reviews.json")
  api.getIssue = requestWithFixturedJSON("github_issue.json")

  return platform
}