Skip to content

Commit

Permalink
adding diff headers to request when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
felipesabino committed Aug 25, 2017
1 parent 73b44e0 commit f822cb4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
19 changes: 11 additions & 8 deletions source/platforms/github/GitHubAPI.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { api as fetch } from "../../api/fetch"
import { RepoMetaData } from "../../ci_source/ci_source"
import { GitHubPRDSL, GitHubUser } from "../../dsl/GitHubDSL"
import * as GitHubNodeAPI from "github"
import * as debug from "debug"
import * as find from "lodash.find"
import * as v from "voca"
import * as node_fetch from "node-fetch"
import * as parse from "parse-link-header"
import * as v from "voca"

import * as node_fetch from "node-fetch"
import * as GitHubNodeAPI from "github"
import * as debug from "debug"
import { GitHubPRDSL, GitHubUser } from "../../dsl/GitHubDSL"

import { RepoMetaData } from "../../ci_source/ci_source"
import { dangerSignaturePostfix } from "../../runner/templates/githubIssueTemplate"
import { api as fetch } from "../../api/fetch"

// The Handle the API specific parts of the github

Expand Down Expand Up @@ -209,7 +210,9 @@ export class GitHubAPI {
async getPullRequestDiff(): Promise<string> {
const prJSON = await this.getPullRequestInfo()
const diffURL = prJSON["diff_url"]
const res = await this.get(diffURL)
const res = await this.get(diffURL, {
accept: "application/vnd.github.v3.diff",
})

return res.ok ? res.text() : ""
}
Expand Down
29 changes: 28 additions & 1 deletion source/platforms/github/_tests/_github_api.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GitHubAPI } from "../GitHubAPI"
import { FakeCI } from "../../../ci_source/providers/Fake"
import { GitHubAPI } from "../GitHubAPI"
import { requestWithFixturedJSON } from "../../_tests/_github.test"

const fetchJSON = (api, params): Promise<any> => {
Expand All @@ -12,6 +12,19 @@ const fetchJSON = (api, params): Promise<any> => {
})
}

const fetchText = (api, params): Promise<any> => {
return Promise.resolve({
ok: true,
text: () =>
Promise.resolve(
JSON.stringify({
api,
...params,
})
),
})
}

const fetch = (api, params): Promise<any> => {
return Promise.resolve({
api,
Expand Down Expand Up @@ -58,6 +71,20 @@ describe("API testing", () => {

expect(api.patch).toHaveBeenCalledWith("repos/artsy/emission/issues/comments/123", {}, { body: "Hello!" })
})

it("getPullRequestDiff", async () => {
api.getPullRequestInfo = await requestWithFixturedJSON("github_pr.json")
api.fetch = fetchText
let text = await api.getPullRequestDiff()
expect(JSON.parse(text)).toMatchObject({
api: "https://github.com/artsy/emission/pull/327.diff",
headers: {
Authorization: "token ABCDE",
accept: "application/vnd.github.v3.diff",
"Content-Type": "application/json",
},
})
})
})

describe("Peril", () => {
Expand Down

0 comments on commit f822cb4

Please sign in to comment.