Skip to content

Commit

Permalink
Merge pull request #338 from danger/use_diff
Browse files Browse the repository at this point in the history
Use the diff url from the PR API instead of a version header to work with Peril
  • Loading branch information
orta committed Aug 17, 2017
2 parents 1d5c2f7 + 721c838 commit 72b7c6c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

// TODO

### 2.0.0-alpha.8

* Uses the GitHub `diff_url` instead of the `diff` version header, as it conflicted with Peril - orta
* Handle exceptions in Dangerfile and report them as failures in Danger results - macklinu

### 2.0.0-alpha.6-7
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "danger",
"version": "2.0.0-alpha.7",
"version": "2.0.0-alpha.8",
"description": "Unit tests for Team Culture",
"main": "distribution/danger.js",
"typings": "distribution/danger.d.ts",
Expand Down
13 changes: 7 additions & 6 deletions source/platforms/github/GitHubAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,9 @@ export class GitHubAPI {
}

async getPullRequestDiff(): Promise<string> {
const repo = this.repoMetadata.repoSlug
const prID = this.repoMetadata.pullRequestID
const res = await this.get(`repos/${repo}/pulls/${prID}`, {
accept: "application/vnd.github.v3.diff",
})
const prJSON = await this.getPullRequestInfo()
const diffURL = prJSON["diff_url"]
const res = await this.get(diffURL)

return res.ok ? res.text() : ""
}
Expand Down Expand Up @@ -282,8 +280,11 @@ export class GitHubAPI {
headers["Authorization"] = `token ${this.token}`
}

const containsBase = path.startsWith("http")
const baseUrl = process.env["DANGER_GITHUB_API_BASE_URL"] || "https://api.github.com"
return this.fetch(`${baseUrl}/${path}`, {
const url = containsBase ? path : `${baseUrl}/${path}`

return this.fetch(url, {
method: method,
body: body,
headers: {
Expand Down
2 changes: 1 addition & 1 deletion source/platforms/github/GitHubGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export default async function gitDSLForGitHub(api: GitHubAPI): Promise<GitDSL> {

const pr = await api.getPullRequestInfo()
const diff = await api.getPullRequestDiff()
const getCommits = await api.getPullRequestCommits()

const fileDiffs: any[] = parseDiff(diff)

Expand Down Expand Up @@ -166,6 +165,7 @@ export default async function gitDSLForGitHub(api: GitHubAPI): Promise<GitDSL> {
}
}

const getCommits = await api.getPullRequestCommits()
return {
modified_files: modifiedDiffs.map(d => d.to),
created_files: addedDiffs.map(d => d.to),
Expand Down

0 comments on commit 72b7c6c

Please sign in to comment.