Skip to content

Commit 4fda336

Browse files
committedOct 8, 2019
fix: do not fail if forbidden to aadd a comment to an issue
1 parent 7e56da8 commit 4fda336

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed
 

‎lib/success.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ module.exports = async (pluginConfig, context) => {
104104
logger.log("Skip comment and labels on issue #%d as it's open: %s", issue.number);
105105
}
106106
} catch (error) {
107-
if (error.status === 404) {
107+
if (error.status === 403) {
108+
logger.error('Not allowed to add a comment to the issue #%d.', issue.number);
109+
} else if (error.status === 404) {
108110
logger.error("Failed to add a comment to the issue #%d as it doesn't exist.", issue.number);
109111
} else {
110112
errors.push(error);

‎test/success.test.js

+27-9
Original file line numberDiff line numberDiff line change
@@ -447,18 +447,23 @@ test.serial('Do not add comment and labels to PR/issues from other repo', async
447447
t.true(github.isDone());
448448
});
449449

450-
test.serial('Ignore missing issues/PRs', async t => {
450+
test.serial('Ignore missing and forbidden issues/PRs', async t => {
451451
const owner = 'test_user';
452452
const repo = 'test_repo';
453453
const env = {GITHUB_TOKEN: 'github_token'};
454454
const failTitle = 'The automated release is failing 🚨';
455455
const pluginConfig = {failTitle};
456456
const prs = [
457457
{number: 1, pull_request: {}, state: 'closed'},
458-
{number: 2, pull_request: {}, body: 'Fixes #3', state: 'closed'},
458+
{number: 2, pull_request: {}, body: 'Fixes #4', state: 'closed'},
459+
{number: 3, pull_request: {}, body: 'Fixes #5', state: 'closed'},
459460
];
460461
const options = {branch: 'master', repositoryUrl: `https://github.com/${owner}/${repo}.git`};
461-
const commits = [{hash: '123', message: 'Commit 1 message\n\n Fix #1'}, {hash: '456', message: 'Commit 2 message'}];
462+
const commits = [
463+
{hash: '123', message: 'Commit 1 message\n\n Fix #1'},
464+
{hash: '456', message: 'Commit 2 message'},
465+
{hash: '789', message: 'Commit 3 message'},
466+
];
462467
const nextRelease = {version: '1.0.0'};
463468
const releases = [{name: 'GitHub release', url: 'https://github.com/release'}];
464469
const github = authenticate(env)
@@ -474,18 +479,28 @@ test.serial('Ignore missing issues/PRs', async t => {
474479
.reply(200, [{sha: commits[0].hash}])
475480
.get(`/repos/${owner}/${repo}/pulls/2/commits`)
476481
.reply(200, [{sha: commits[1].hash}])
482+
.get(`/repos/${owner}/${repo}/pulls/3/commits`)
483+
.reply(200, [{sha: commits[2].hash}])
477484
.post(`/repos/${owner}/${repo}/issues/1/comments`, {body: /This PR is included/})
478485
.reply(200, {html_url: 'https://github.com/successcomment-1'})
479486
.post(`/repos/${owner}/${repo}/issues/1/labels`, '["released"]')
480487
.reply(200, {})
481488
.post(`/repos/${owner}/${repo}/issues/2/comments`, {body: /This PR is included/})
482489
.times(3)
483490
.reply(404)
484-
.get(`/repos/${owner}/${repo}/issues/3`)
491+
.post(`/repos/${owner}/${repo}/issues/3/comments`, {body: /This PR is included/})
492+
.reply(403)
493+
.get(`/repos/${owner}/${repo}/issues/4`)
485494
.reply(200, {state: 'closed'})
486-
.post(`/repos/${owner}/${repo}/issues/3/comments`, {body: /This issue has been resolved/})
487-
.reply(200, {html_url: 'https://github.com/successcomment-3'})
488-
.post(`/repos/${owner}/${repo}/issues/3/labels`, '["released"]')
495+
.get(`/repos/${owner}/${repo}/issues/5`)
496+
.reply(200, {state: 'closed'})
497+
.post(`/repos/${owner}/${repo}/issues/4/comments`, {body: /This issue has been resolved/})
498+
.reply(200, {html_url: 'https://github.com/successcomment-4'})
499+
.post(`/repos/${owner}/${repo}/issues/4/labels`, '["released"]')
500+
.reply(200, {})
501+
.post(`/repos/${owner}/${repo}/issues/5/comments`, {body: /This issue has been resolved/})
502+
.reply(200, {html_url: 'https://github.com/successcomment-5'})
503+
.post(`/repos/${owner}/${repo}/issues/5/labels`, '["released"]')
489504
.reply(200, {})
490505
.get(
491506
`/search/issues?q=${escape('in:title')}+${escape(`repo:${owner}/${repo}`)}+${escape('type:issue')}+${escape(
@@ -498,9 +513,12 @@ test.serial('Ignore missing issues/PRs', async t => {
498513

499514
t.true(t.context.log.calledWith('Added comment to issue #%d: %s', 1, 'https://github.com/successcomment-1'));
500515
t.true(t.context.log.calledWith('Added labels %O to issue #%d', ['released'], 1));
501-
t.true(t.context.log.calledWith('Added comment to issue #%d: %s', 3, 'https://github.com/successcomment-3'));
502-
t.true(t.context.log.calledWith('Added labels %O to issue #%d', ['released'], 3));
516+
t.true(t.context.log.calledWith('Added comment to issue #%d: %s', 4, 'https://github.com/successcomment-4'));
517+
t.true(t.context.log.calledWith('Added labels %O to issue #%d', ['released'], 4));
518+
t.true(t.context.log.calledWith('Added comment to issue #%d: %s', 5, 'https://github.com/successcomment-5'));
519+
t.true(t.context.log.calledWith('Added labels %O to issue #%d', ['released'], 5));
503520
t.true(t.context.error.calledWith("Failed to add a comment to the issue #%d as it doesn't exist.", 2));
521+
t.true(t.context.error.calledWith('Not allowed to add a comment to the issue #%d.', 3));
504522
t.true(github.isDone());
505523
});
506524

0 commit comments

Comments
 (0)
Please sign in to comment.