How to use the danger/distribution/runner/jsonToDSL.jsonToDSL 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
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) {
    const rep = dangerRepresentationForPath(path)

    const defaultRepoSlug = payload.dsl.github.pr.base.repo.full_name
    const dangerfileContent = await getGitHubFileContentsFromLocation(token, rep, defaultRepoSlug)
    contents.push(dangerfileContent)
  }
github danger / peril / api / source / github / events / createPRDSL.ts View on Github external
export const createPRDSL = async (githubAPI: GitHubAPI) => {
  const jsonDSL = await createPRJSONDSL(githubAPI)
  // Danger JS expects the Github access token to be set on
  // settings.github.accessToken, so put it there if we have one
  if (githubAPI.token !== undefined) {
    jsonDSL.settings.github.accessToken = githubAPI.token
  }
  return await jsonToDSL(jsonDSL, source)
}