Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const runDangerEvent = async (
installation: InstallationToRun,
input: PerilRunnerBootstrapJSON,
payload: ValidatedPayload
) => {
// Pull out the metadata from the JSON to load up the danger process
const token = payload.dsl.settings.github.accessToken
// TODO: Why aren't we using these? and is it related to #367
// const context = contextForDanger(runtimeDSL)
// const runtimeDSL = await jsonToDSL(payload.dsl, source)
const context = contextForDanger({ github: payload.dsl.github } as any)
const peril = await perilObjectForInstallation(installation, input.perilSettings.envVars, input)
// Attach Peril + the octokit API to the DSL
await appendPerilContextToDSL(installation.iID, token, context, peril)
for (const path of input.paths) {
const rep = dangerRepresentationForPath(path)
if (!rep.repoSlug) {
logger.error(`No repo slug in ${path} given for event based run, which can't really be supported.`)
return
}
}
// Start getting the details for what code to eval.
export async function runDangerAgainstFileInline(
filepath: string[],
contents: string[],
installationRun: InstallationToRun,
exec: Executor,
peril: PerilDSL,
payload: Payload
) {
const dangerDSL = payload.dsl as any | undefined
const context = contextForDanger(dangerDSL)
const dangerRuntimeEnv = await exec.runner.createDangerfileRuntimeEnvironment(context)
if (dangerRuntimeEnv.sandbox) {
// Mutates runtimeEnv.sandbox
await appendPerilContextToDSL(installationRun.iID, undefined, dangerRuntimeEnv.sandbox, peril)
}
let results: DangerResults
try {
results = await exec.runner.runDangerfileEnvironment(filepath, contents, dangerRuntimeEnv, payload.webhook)
} catch (error) {
results = resultsForCaughtError(filepath.join(","), contents.join("\n---\n"), error)
}
return results
}
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)
}