Skip to content

Commit

Permalink
Merge branch 'master' into feature/github-issue-template-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickkempff committed Nov 5, 2018
2 parents 69dfb6a + f11723a commit e16d2d7
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 40 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

## Master

- Fix #614 - Posting status updates to Github using issue workflow broken - [@sgtcoolguy][]
- Fix vertical alignment in GitHub issue template - [@patrickkempff][]

# 5.0.1, err. 6.0.0
Expand Down
17 changes: 13 additions & 4 deletions source/danger-incoming-process-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@
},
"private": {
"description": "Is the repo publicly accessible?",
"type": "{boolean}"
"type": "boolean"
}
},
"type": "object"
Expand Down Expand Up @@ -982,15 +982,24 @@
},
"created_files": {
"description": "Newly created filepaths relative to the git root",
"type": "{string[]}"
"items": {
"type": "string"
},
"type": "array"
},
"deleted_files": {
"description": "Removed filepaths relative to the git root",
"type": "{string[]}"
"items": {
"type": "string"
},
"type": "array"
},
"modified_files": {
"description": "Filepaths with changes relative to the git root",
"type": "{string[]}"
"items": {
"type": "string"
},
"type": "array"
}
},
"type": "object"
Expand Down
3 changes: 0 additions & 3 deletions source/dsl/GitDSL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,16 @@ export interface JSONDiff {
export interface GitJSONDSL {
/**
* Filepaths with changes relative to the git root
* @type {string[]}
*/
readonly modified_files: string[]

/**
* Newly created filepaths relative to the git root
* @type {string[]}
*/
readonly created_files: string[]

/**
* Removed filepaths relative to the git root
* @type {string[]}
*/
readonly deleted_files: string[]

Expand Down
1 change: 0 additions & 1 deletion source/dsl/GitHubDSL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ export interface GitHubRepo {

/**
* Is the repo publicly accessible?
* @type {boolean}
*/
private: boolean

Expand Down
10 changes: 7 additions & 3 deletions source/platforms/github/GitHubAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,17 +344,21 @@ export class GitHubAPI {
return res.ok ? res.json() : { labels: [] }
}

updateStatus = async (passed: boolean, message: string, url?: string): Promise<any> => {
updateStatus = async (passed: boolean | "pending", message: string, url?: string): Promise<any> => {
const repo = this.repoMetadata.repoSlug

const prJSON = await this.getPullRequestInfo()
const ref = prJSON.head.sha
let state = passed ? "success" : "failure"
if (passed === "pending") {
state = "pending"
}
const res = await this.post(
`repos/${repo}/statuses/${ref}`,
{},
{
state: passed ? "success" : "failure",
context: process.env["PERIL_INTEGRATION_ID"] ? "Peril" : "Danger",
state: state,
context: process.env["PERIL_BOT_USER_ID"] ? "Peril" : "Danger",
target_url: url || "http://danger.systems/js",
description: message,
}
Expand Down
76 changes: 76 additions & 0 deletions source/platforms/github/_tests/_github_api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,82 @@ describe("API testing", () => {
await expect(api.postInlinePRComment("", "", "", 0)).rejects.toEqual(expectedJSON)
})

it("updateStatus('pending') success", async () => {
api.fetch = jest.fn().mockReturnValue({ ok: true })
api.getPullRequestInfo = await requestWithFixturedJSON("github_pr.json")

await expect(api.updateStatus("pending", "message")).resolves.toEqual(true)
expect(api.fetch).toHaveBeenCalledWith(
"https://api.github.com/repos/artsy/emission/statuses/cfa8fb80d2b65f4c4fa0b54d25352a3a0ff58f75",
{
headers: {
Authorization: "token ABCDE",
"Content-Type": "application/json",
},
method: "POST",
body: '{"state":"pending","context":"Danger","target_url":"http://danger.systems/js","description":"message"}',
},
undefined
)
})

it("updateStatus(false) success", async () => {
api.fetch = jest.fn().mockReturnValue({ ok: true })
api.getPullRequestInfo = await requestWithFixturedJSON("github_pr.json")

await expect(api.updateStatus(false, "message")).resolves.toEqual(true)
expect(api.fetch).toHaveBeenCalledWith(
"https://api.github.com/repos/artsy/emission/statuses/cfa8fb80d2b65f4c4fa0b54d25352a3a0ff58f75",
{
headers: {
Authorization: "token ABCDE",
"Content-Type": "application/json",
},
method: "POST",
body: '{"state":"failure","context":"Danger","target_url":"http://danger.systems/js","description":"message"}',
},
undefined
)
})

it("updateStatus(true, 'message', 'http://example.org') success", async () => {
api.fetch = jest.fn().mockReturnValue({ ok: true })
api.getPullRequestInfo = await requestWithFixturedJSON("github_pr.json")

await expect(api.updateStatus(true, "message", "http://example.org")).resolves.toEqual(true)
expect(api.fetch).toHaveBeenCalledWith(
"https://api.github.com/repos/artsy/emission/statuses/cfa8fb80d2b65f4c4fa0b54d25352a3a0ff58f75",
{
headers: {
Authorization: "token ABCDE",
"Content-Type": "application/json",
},
method: "POST",
body: '{"state":"success","context":"Danger","target_url":"http://example.org","description":"message"}',
},
undefined
)
})

it("updateStatus(true) failed", async () => {
api.fetch = jest.fn().mockReturnValue({ ok: false })
api.getPullRequestInfo = await requestWithFixturedJSON("github_pr.json")

await expect(api.updateStatus(true, "message")).resolves.toEqual(false)
expect(api.fetch).toHaveBeenCalledWith(
"https://api.github.com/repos/artsy/emission/statuses/cfa8fb80d2b65f4c4fa0b54d25352a3a0ff58f75",
{
headers: {
Authorization: "token ABCDE",
"Content-Type": "application/json",
},
method: "POST",
body: '{"state":"success","context":"Danger","target_url":"http://danger.systems/js","description":"message"}',
},
undefined
)
})

it("deleteCommentWithID", async () => {
api.fetch = jest.fn().mockReturnValue({ status: 204 })
await api.deleteCommentWithID(123)
Expand Down
27 changes: 2 additions & 25 deletions source/platforms/github/comms/issueCommenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,8 @@ export const GitHubIssueCommenter = (api: GitHubAPI) => {
* Fails the current build, if status setting succeeds
* then return true.
*/

updateStatus: async (passed: boolean | "pending", message: string, url?: string): Promise<boolean> => {
const ghAPI = api.getExternalAPI()

const prJSON = await api.getPullRequestInfo()
const ref = prJSON.head
try {
await ghAPI.repos.createStatus({
repo: ref.repo.name,
owner: ref.repo.owner.login,
sha: ref.sha,
state: passed ? "success" : "failure",
context: process.env["PERIL_BOT_USER_ID"] ? "Peril" : "Danger",
target_url: url || "http://danger.systems/js",
description: message,
})
return true
} catch (error) {
// @ts-ignore
if (global.verbose) {
console.log("Got an error with creating a commit status", error)
}
return false
}
},
updateStatus: async (passed: boolean | "pending", message: string, url?: string): Promise<boolean> =>
api.updateStatus(passed, message, url),

/**
* Gets inline comments for current PR
Expand Down
4 changes: 0 additions & 4 deletions source/platforms/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,15 @@ export type Comment = {
/**
* UUID for the comment
*
* @type {string}
*/
id: string
/**
* Textual representation of comment
*
* @type {string} body string
*/
body: string
/**
* Was this posted by the account Danger has access to?
*
* @type {boolean} true if Danger can edit
*/
ownedByDanger: boolean
}
Expand Down

0 comments on commit e16d2d7

Please sign in to comment.