diff --git a/package.json b/package.json index a812dfe3..bf07e655 100644 --- a/package.json +++ b/package.json @@ -124,7 +124,7 @@ "typescript-json-schema": "^0.23.0" }, "engines": { - "node": "9" + "node": ">=8 <=9" }, "jest": { "transform": { diff --git a/source/danger/_tests/_danger_run.test.ts b/source/danger/_tests/_danger_run.test.ts index 819ffdd1..8c52ce28 100644 --- a/source/danger/_tests/_danger_run.test.ts +++ b/source/danger/_tests/_danger_run.test.ts @@ -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" } diff --git a/source/danger/danger_run.ts b/source/danger/danger_run.ts index 311de977..7165911d 100644 --- a/source/danger/danger_run.ts +++ b/source/danger/danger_run.ts @@ -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 + ".*" diff --git a/source/github/events/github_runner.ts b/source/github/events/github_runner.ts index ca04bbd1..15218bb4 100644 --- a/source/github/events/github_runner.ts +++ b/source/github/events/github_runner.ts @@ -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? const prResults = await runPRRun(eventName, prRuns, settings, token, req.body.pull_request || req.body) if (prResults) { allResults.push(prResults)