Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const getPerilPlatformForDSL = (type: RunType, github: GitHubType | null, githubEvent: any): Platform => {
if (type === RunType.pr && github) {
return github
} else {
const repoSlug = reposlugFromEvent(githubEvent) || "danger/peril"
const ref = refFromEvent(githubEvent)
// This bit of faffing ensures that as the gh utils expands we get
// compiler errors in peril
const utils: GitHubUtilsDSL | null = github && {
fileContents: fileContentsGenerator(github.api.getExternalAPI(), repoSlug, ref),
createUpdatedIssueWithID: createUpdatedIssueWithIDGenerator(github.api.getExternalAPI()),
createOrAddLabel: createOrAddLabel(undefined, github.api.getExternalAPI()),
createOrUpdatePR: createOrUpdatePR(undefined, github.api.getExternalAPI()),
// Not sure what this looks like for non-PR events
fileLinks: (paths, _, __, ___) => paths.join(", "),
}
const nullFunc: any = () => ""
const platform: Platform = {
name: "Peril",
getFileContents: github ? github.getFileContents.bind(github) : nullFunc,
// Checks Support should *not* be available if we're not in a GH PR
platformResultsPreMapper: undefined,
// deprecated, and not used to my knowledge
handlePostingResults: () =>
github ? github.handlePostingResults && github.handlePostingResults.bind(github) : nullFunc,
const response = await api.repos.getContents({ repo, owner, path, ref })
if (response && response.data && response.data.type === "file") {
const buffer = Buffer.from(response.data.content, response.data.encoding)
return buffer.toString()
} else {
return ""
}
} catch {
return ""
}
},
createUpdatedIssueWithID: createUpdatedIssueWithIDGenerator(api),
// TODO: Is this right?
// Do I need to move the PR object into here if needed?
createOrAddLabel: createOrAddLabel(undefined as any, api),
createOrUpdatePR: createOrUpdatePR(undefined as any, api),
})