Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Allow edge-case repos to skip Danger rules. E.g. in Artsy, our analytics and marketing repos
// do not need the same level of thought as an larger engineering project would.
if (repoIsIgnored(settings.repoName, installation)) {
res.status(204).send({ message: `Skipping peril run due to repo being in ignored`, iID: installationID })
return
}
const runs = runsForEvent(event, action, installation, req.body, settings)
const name = action ? `${event}.${action}` : event
const maybeRepo = req.body.repository ? `on ${req.body.repository.full_name}` : ""
if (runs.length) {
logger.info("")
logger.info(`## ${name} on ${installation.login} ${maybeRepo}`)
logger.info(
` ${runs.length} run${runs.length > 1 ? "s" : ""} needed: ${sentence(runs.map(r => r.referenceString))}`
)
} else {
logger.info(`${name} on ${installation.login || "heroku"} skipped`)
}
await runEverything(event, runs, settings, installation, req, res, next)
}
fileLinks: (paths: string[], useBasename: boolean = true, repoSlug: string, branch?: string): string => {
if (!repoSlug) {
throw new Error("Need a repo slug")
}
const ref = branch || "master"
const toHref = (path: string) => `https://github.com/${repoSlug}/blob/${ref}/${path}`
// As we should only be getting paths we can ignore the nullability
const hrefs = paths.map(p => href(toHref(p), useBasename ? basename(p) : p)) as string[]
return sentence(hrefs)
},
) => {
if (installation.installationSlackUpdateWebhookURL) {
let filteredLogs = replaceAllKeysInString(globals, logs.log)
filteredLogs = replaceAllKeysInString(installation.envVars, filteredLogs)
// Doesn't matter if it fails, so long as it's logged. Shouldn't take down the server.
try {
const webhook = new IncomingWebhook(installation.installationSlackUpdateWebhookURL)
await webhook.send({
unfurl_links: false,
username: `Peril for ${installation.login}`,
text: message,
attachments: [
{
title: `${logs.event} - ${sentence(logs.filenames)}`,
text: `\`\`\`\n${filteredLogs}\n\`\`\``,
},
],
})
} catch (error) {
logger.error(`Sending a slack logs failed for ${installation.login}`)
}
}
}