Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
}
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)
}