Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add in handling for PR milestoned/demilestoned events #343

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"typescript-json-schema": "^0.23.0"
},
"engines": {
"node": "9"
"node": ">=8 <=9"
},
"jest": {
"transform": {
Expand Down
54 changes: 54 additions & 0 deletions source/danger/_tests/_danger_run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,60 @@ describe("for PRs", () => {
])
})

describe("for issues.* events that are actually pull-requests", () => {
it("returns PR rules when the issues.milestoned is actually a PR", () => {
const rules = { pull_request: ['pr.js'], issues: ['issue.js'] }
const payload = {
issue: {
number: 123,
title: 'My PR',
pull_request: {
"url": "https://api.github.com/repos/MyRepo/MyProject/pulls/123",
"html_url": "https://github.com/MyRepo/MyProject/pull/123",
"diff_url": "https://github.com/MyRepo/MyProject/pull/123.diff",
"patch_url": "https://github.com/MyRepo/MyProject/pull/123.patch"
}
}
}

expect(dangerRunForRules("issues", "milestoned", rules, payload)).toEqual([
{
action: "milestoned",
branch: "master",
dangerfilePath: "pr.js",
dslType: RunType.pr,
event: "pull_request",
feedback: RunFeedback.commentable,
referenceString: "pr.js",
repoSlug: undefined,
},
])
})

it("returns issue rules when the issues.milestoned is actually a issue", () => {
const rules = { pull_request: ['pr.js'], issues: ['issue.js'] }
const payload = {
issue: {
number: 123,
title: 'My issue',
}
}

expect(dangerRunForRules("issues", "milestoned", rules, payload)).toEqual([
{
action: "milestoned",
branch: "master",
dangerfilePath: "issue.js",
dslType: RunType.import,
event: "issues",
feedback: RunFeedback.commentable,
referenceString: "issue.js",
repoSlug: undefined,
},
])
})
})

// Same semantics
it("returns a PR run when all sub events are globbed in the rules", () => {
const rules = { "pull_request.*": "dangerfile.js" }
Expand Down
7 changes: 7 additions & 0 deletions source/danger/danger_run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ export const dangerRunForRules = (
return []
}

if (event === 'issues') {
// check if it is really a pull request
if (_.get(webhook, 'issue.pull_request')) {
event = 'pull_request'
}
}

// These are the potential keys that could trigger a run
const directKey = event
const globsKey = event + ".*"
Expand Down
1 change: 1 addition & 0 deletions source/github/events/github_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export const runEverything = async (
const eventRuns = runs.filter(r => r.dslType === RunType.import)

// Loop through all PRs, which are require difference DSL logic compared to simple GH webhook events
// TODO a re-mapped PR from an issue event won't have pr.head so how do we handle that in this method?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orta so the issue with my approach here is that the payload from github on the event does not contain the ".head" node. This would be the same issue I'll run into for issue #342 as well. Is there a means to do a "blind" trigger of a PR in peril?

const prResults = await runPRRun(eventName, prRuns, settings, token, req.body.pull_request || req.body)
if (prResults) {
allResults.push(prResults)
Expand Down