-
Notifications
You must be signed in to change notification settings - Fork 7
Act on the issue a community pull request closes #103
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
41d3731
Act on the issue a community pull request closes
akolson 1e7f33a
Ask an unlinked pull request to link its issue
akolson 7e6b058
Join the link guidance in the script, not inside the constant
akolson 06370d9
Send the reply before requesting review and adding the label
akolson 658d4d3
Say what a plain mention fails to link
akolson f511df3
Describe each automation on its own, and in the order it acts
akolson 71d65a5
Keep the Slack notice when the review request or the label fails
akolson fcb3eb6
Name the linked issue by url, and report a failed close
akolson 90f0bd1
Let the Slack step run after a partial failure
akolson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,239 @@ | ||
| const test = require('node:test'); | ||
| const assert = require('node:assert/strict'); | ||
|
|
||
| const contributorPrReply = require('./contributor-pr-reply'); | ||
| const { LABEL_COMMUNITY_REVIEW, RTIBBLESBOT_USERNAME } = require('./constants'); | ||
|
|
||
| const AUTHOR = 'outsider'; | ||
|
|
||
| function fakeContext(author = AUTHOR) { | ||
| return { | ||
| repo: { owner: 'learningequality', repo: 'kolibri' }, | ||
| payload: { | ||
| pull_request: { | ||
| number: 42, | ||
| html_url: 'https://github.com/learningequality/kolibri/pull/42', | ||
| title: 'Fix it', | ||
| user: { login: author }, | ||
| }, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| function fakeCore() { | ||
| const outputs = {}; | ||
| const warnings = []; | ||
| const failures = []; | ||
| return { | ||
| outputs, | ||
| warnings, | ||
| failures, | ||
| info() {}, | ||
| warning(message) { | ||
| warnings.push(message); | ||
| }, | ||
| setFailed(message) { | ||
| failures.push(message); | ||
| }, | ||
| setOutput(name, value) { | ||
| outputs[name] = value; | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| function fakeGithub(linkedIssues = [], { graphqlError } = {}) { | ||
| const calls = { comments: [], updates: [], reviewers: [], labels: [], order: [] }; | ||
| return { | ||
| calls, | ||
| graphql: async () => { | ||
| if (graphqlError) { | ||
| throw new Error(graphqlError); | ||
| } | ||
| return { | ||
| repository: { | ||
| pullRequest: { | ||
| closingIssuesReferences: { | ||
| nodes: linkedIssues.map(issue => ({ | ||
| number: issue.number, | ||
| title: `Issue ${issue.number}`, | ||
| url: `https://github.com/learningequality/kolibri/issues/${issue.number}`, | ||
| assignees: { nodes: issue.assignees.map(login => ({ login })) }, | ||
| })), | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
| }, | ||
| rest: { | ||
| issues: { | ||
| createComment: async ({ issue_number, body }) => { | ||
| calls.comments.push({ issue_number, body }); | ||
| calls.order.push('comment'); | ||
| return { data: { html_url: 'https://github.com/learningequality/kolibri/pull/42#c1' } }; | ||
| }, | ||
| addLabels: async ({ labels }) => { | ||
| calls.labels.push(...labels); | ||
| calls.order.push('label'); | ||
| }, | ||
| }, | ||
| pulls: { | ||
| update: async ({ pull_number, state }) => { | ||
| calls.updates.push({ pull_number, state }); | ||
| calls.order.push('close'); | ||
| }, | ||
| requestReviewers: async ({ reviewers }) => { | ||
| calls.reviewers.push(...reviewers); | ||
| calls.order.push('review'); | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| async function run(github, context = fakeContext()) { | ||
| const core = fakeCore(); | ||
| await contributorPrReply({ github, context, core }); | ||
| return core; | ||
| } | ||
|
|
||
| test('a linked issue assigned to someone else closes the pull request', async () => { | ||
| const github = fakeGithub([{ number: 7, assignees: ['someone-else'] }]); | ||
| const core = await run(github); | ||
|
|
||
| assert.deepEqual(github.calls.updates, [{ pull_number: 42, state: 'closed' }]); | ||
| assert.equal(github.calls.comments.length, 1); | ||
| assert.match(github.calls.comments[0].body, /issues\/7 is assigned to someone else/); | ||
| assert.match(core.outputs.slack_notification, /Closed/); | ||
| assert.deepEqual(github.calls.reviewers, []); | ||
| assert.deepEqual(github.calls.labels, []); | ||
| assert.deepEqual(core.failures, []); | ||
| }); | ||
|
|
||
| test('the closing message replaces the standard reply', async () => { | ||
| const github = fakeGithub([{ number: 7, assignees: ['someone-else'] }]); | ||
| await run(github); | ||
|
|
||
| assert.doesNotMatch(github.calls.comments[0].body, /For the review process to begin/); | ||
| }); | ||
|
|
||
| test('a failed close still reports to Slack', async () => { | ||
| const github = fakeGithub([{ number: 7, assignees: ['someone-else'] }]); | ||
| github.rest.pulls.update = async () => { | ||
| throw new Error('Resource not accessible'); | ||
| }; | ||
| const core = await run(github); | ||
|
|
||
| assert.equal(github.calls.comments.length, 1); | ||
| assert.match(core.outputs.slack_notification, /Failed to close/); | ||
|
rtibblesbot marked this conversation as resolved.
|
||
| assert.equal(core.failures.length, 1); | ||
| }); | ||
|
|
||
| test('a cross-repo linked issue is named by its url', async () => { | ||
| const github = fakeGithub([{ number: 7, assignees: ['someone-else'] }]); | ||
| const core = await run(github); | ||
|
|
||
| assert.match(github.calls.comments[0].body, /https:\/\/github\.com\/.+\/issues\/7/); | ||
| assert.match(core.outputs.slack_notification, /issues\/7/); | ||
| }); | ||
|
|
||
| test('a linked issue assigned to the author requests review and adds the label', async () => { | ||
| const github = fakeGithub([{ number: 7, assignees: [AUTHOR] }]); | ||
| const core = await run(github); | ||
|
|
||
| assert.deepEqual(github.calls.reviewers, [RTIBBLESBOT_USERNAME]); | ||
| assert.deepEqual(github.calls.labels, [LABEL_COMMUNITY_REVIEW]); | ||
| assert.deepEqual(github.calls.updates, []); | ||
| assert.match(github.calls.comments[0].body, /For the review process to begin/); | ||
| assert.match(core.outputs.slack_notification, /Reply sent/); | ||
| }); | ||
|
|
||
| test('the reply is sent before the review request and the label', async () => { | ||
| const github = fakeGithub([{ number: 7, assignees: [AUTHOR] }]); | ||
| await run(github); | ||
|
|
||
| assert.deepEqual(github.calls.order, ['comment', 'review', 'label']); | ||
| }); | ||
|
|
||
| test('a failed review request still leaves the reply in place', async () => { | ||
| const github = fakeGithub([{ number: 7, assignees: [AUTHOR] }]); | ||
| github.rest.pulls.requestReviewers = async () => { | ||
| throw new Error('Reviewer cannot be requested'); | ||
| }; | ||
| const core = await run(github); | ||
|
|
||
| assert.equal(github.calls.comments.length, 1); | ||
| assert.equal(core.failures.length, 1); | ||
| assert.match(core.outputs.slack_notification, /Reply sent/); | ||
| }); | ||
|
|
||
| test('the author counts as assigned alongside other assignees', async () => { | ||
| const github = fakeGithub([{ number: 7, assignees: ['someone-else', AUTHOR] }]); | ||
| await run(github); | ||
|
|
||
| assert.deepEqual(github.calls.updates, []); | ||
| assert.deepEqual(github.calls.reviewers, [RTIBBLESBOT_USERNAME]); | ||
| }); | ||
|
|
||
| test('an issue assigned to the author outweighs another assigned elsewhere', async () => { | ||
| const github = fakeGithub([ | ||
| { number: 7, assignees: ['someone-else'] }, | ||
| { number: 8, assignees: [AUTHOR] }, | ||
| ]); | ||
| await run(github); | ||
|
|
||
| assert.deepEqual(github.calls.updates, []); | ||
| assert.deepEqual(github.calls.reviewers, [RTIBBLESBOT_USERNAME]); | ||
| }); | ||
|
|
||
| test('no linked issue leaves the pull request alone', async () => { | ||
| const github = fakeGithub([]); | ||
| const core = await run(github); | ||
|
|
||
| assert.deepEqual(github.calls.updates, []); | ||
| assert.deepEqual(github.calls.reviewers, []); | ||
| assert.deepEqual(github.calls.labels, []); | ||
| assert.equal(github.calls.comments.length, 1); | ||
| assert.match(core.outputs.slack_notification, /Reply sent/); | ||
| }); | ||
|
|
||
| test('a linked issue with no assignee leaves the pull request alone', async () => { | ||
| const github = fakeGithub([{ number: 7, assignees: [] }]); | ||
| await run(github); | ||
|
|
||
| assert.deepEqual(github.calls.updates, []); | ||
| assert.deepEqual(github.calls.reviewers, []); | ||
| assert.deepEqual(github.calls.labels, []); | ||
| }); | ||
|
|
||
| test('an unlinked pull request is asked to link an issue', async () => { | ||
| const github = fakeGithub([]); | ||
| await run(github); | ||
|
|
||
| assert.match(github.calls.comments[0].body, /link one under \*\*References\*\*/); | ||
| }); | ||
|
|
||
| test('a linked pull request is not asked to link an issue', async () => { | ||
| const github = fakeGithub([{ number: 7, assignees: [] }]); | ||
| await run(github); | ||
|
|
||
| assert.doesNotMatch(github.calls.comments[0].body, /link one under/); | ||
| }); | ||
|
|
||
| test('a failed lookup falls back to the standard reply', async () => { | ||
| const github = fakeGithub([], { graphqlError: 'API down' }); | ||
| const core = await run(github); | ||
|
|
||
| assert.deepEqual(github.calls.updates, []); | ||
| assert.deepEqual(github.calls.reviewers, []); | ||
| assert.equal(github.calls.comments.length, 1); | ||
| assert.equal(core.warnings.length, 1); | ||
| assert.match(core.warnings[0], /API down/); | ||
| assert.deepEqual(core.failures, []); | ||
| }); | ||
|
|
||
| test('a failed lookup does not ask the author to link an issue', async () => { | ||
| const github = fakeGithub([], { graphqlError: 'API down' }); | ||
| await run(github); | ||
|
|
||
| assert.doesNotMatch(github.calls.comments[0].body, /link one under/); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.