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 githubAPIForCommentable = (token: string, repoSlug: string, issueNumber: number | null) => {
const githubAPI = new GitHubAPI({ repoSlug, pullRequestID: String(issueNumber) }, token)
githubAPI.additionalHeaders = {
Accept: "application/vnd.github.machine-man-preview+json",
}
// How can I get this from an API, if we cannot use /me ?
// https://api.github.com/repos/PerilTest/PerilPRTester/issues/5/comments
// Talked to GH - they know it's an issue.
githubAPI.getUserID = () => Promise.resolve(parseInt(PERIL_BOT_USER_ID as string, 10))
return githubAPI
}
const action = pr.action
const installationID = pr.installation.id
switch (action) {
case "opened":
case "synchronize":
case "closed":
let installation = await getInstallation(installationID)
if (!installation) {
res.status(404).send(`Could not find installation with id: ${installationID}`)
return
}
const token = await getTemporaryAccessTokenForInstallation(installation)
const githubAPI = new GitHubAPI({ repoSlug: pr.repository.full_name, pullRequestID: String(pr.number) }, token)
githubAPI.additionalHeaders = { Accept: "application/vnd.github.machine-man-preview+json" }
// How can I get this from an API, if we cannot use /me ?
// https://api.github.com/repos/PerilTest/PerilPRTester/issues/5/comments
githubAPI.getUserID = () => Promise.resolve(24758014)
const skipOrgCheck = !installation.settings.onlyForOrgMembers
const userIsInOrg = installation.settings.onlyForOrgMembers
&& await isUserInOrg(pr.sender as any, pr.organization.login, githubAPI)
if (skipOrgCheck || userIsInOrg) {
res.status(200).send("Found installation")
const dangerfile = installation.settings.filepathForDangerfile || "dangerfile.js"
runDangerAgainstInstallation(dangerfile, pr, githubAPI)
}
export const fixturedAPI = (repoSlug?: string, pullRequestID?: string): GitHubType => {
repoSlug = repoSlug || "artsy/emission"
pullRequestID = pullRequestID || "1"
const api = new GitHubAPI({ repoSlug, pullRequestID }, "ABCDE")
const platform = GitHub(api)
api.getPullRequestInfo = requestWithFixturedJSON("github_pr.json")
api.getPullRequestDiff = requestWithFixturedContent("github_diff.diff")
api.getPullRequestCommits = requestWithFixturedJSON("github_commits.json")
api.getReviewerRequests = requestWithFixturedJSON("github_requested_reviewers.json")
api.getReviews = requestWithFixturedJSON("github_reviews.json")
api.getIssue = requestWithFixturedJSON("github_issue.json")
return platform
}