Skip to content

Commit

Permalink
Update Danger and Octokit
Browse files Browse the repository at this point in the history
  • Loading branch information
steprescott committed Apr 6, 2020
1 parent ea889cc commit 855ca89
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 175 deletions.
5 changes: 3 additions & 2 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"license": "MIT",
"dependencies": {
"@octokit/app": "^3.0.2",
"@octokit/rest": "^17.1.4",
"@peril/utils": "^1.0.2",
"@sentry/node": "^5.5.0",
"@slack/client": "^4.5.0",
Expand Down Expand Up @@ -83,7 +84,7 @@
"cookie": "^0.3.1",
"cookie-parser": "^1.4.3",
"cors": "^2.8.4",
"danger": "9.1.3",
"danger": "10.1.0",
"danger-plugin-spellcheck": "^1.2.3",
"danger-plugin-yarn": "^1.3.2",
"dotenv": "^5.0.1",
Expand Down Expand Up @@ -171,4 +172,4 @@
"git add"
]
}
}
}
2 changes: 1 addition & 1 deletion api/source/api/graphql/github/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import GitHub from "@octokit/rest"
import { Octokit as GitHub } from "@octokit/rest"
import { getTemporaryAccessTokenForInstallation } from "../../github"

export const octokitForInstallation = async (installationID: number) => {
Expand Down
12 changes: 8 additions & 4 deletions api/source/danger/append_peril.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as NodeGithub from "@octokit/rest"
import { Octokit as NodeGithub } from "@octokit/rest"

import { PerilDSL } from "danger/distribution/dsl/DangerDSL"
import { GitHubUtilsDSL } from "danger/distribution/dsl/GitHubDSL"
Expand All @@ -17,7 +17,6 @@ import { RuntimeEnvironment } from "../db/runtimeEnv"
import { PerilRunnerBootstrapJSON } from "../runner/triggerSandboxRun"
import { generateTaskSchedulerForInstallation } from "../tasks/scheduleTask"
import { InstallationToRun } from "./danger_runner"

/**
* Generates a GH API for Peril-based work
*
Expand Down Expand Up @@ -58,9 +57,14 @@ const recreateGitHubUtils = (api: NodeGithub): GitHubUtilsDSL => ({

const [owner, repo] = repoSlug.split("/")
try {
// response of getContents() can be one of 4 things. We are interested in file responses only
// https://developer.github.com/v3/repos/contents/#get-contents
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)
if (Array.isArray(response.data)) {
return ""
}
if (response && response.data && response.data.content) {
const buffer = new Buffer(response.data.content, response.data.encoding)
return buffer.toString()
} else {
return ""
Expand Down
Loading

0 comments on commit 855ca89

Please sign in to comment.