Skip to content

Commit

Permalink
Merge branch 'master' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Oct 8, 2019
2 parents 416fb56 + 4fda336 commit 8e9d3d1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
4 changes: 3 additions & 1 deletion lib/success.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ module.exports = async (pluginConfig, context) => {
logger.log('Added labels %O to issue #%d', labels, issue.number);
}
} catch (error) {
if (error.status === 404) {
if (error.status === 403) {
logger.error('Not allowed to add a comment to the issue #%d.', issue.number);
} else if (error.status === 404) {
logger.error("Failed to add a comment to the issue #%d as it doesn't exist.", issue.number);
} else {
errors.push(error);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"fs-extra": "^8.0.0",
"globby": "^10.0.0",
"http-proxy-agent": "^2.1.0",
"https-proxy-agent": "^2.2.1",
"https-proxy-agent": "^3.0.0",
"issue-parser": "^4.0.0",
"lodash": "^4.17.4",
"mime": "^2.4.3",
Expand All @@ -40,7 +40,7 @@
"codecov": "^3.5.0",
"nock": "^11.1.0",
"nyc": "^14.1.1",
"proxy": "^0.2.4",
"proxy": "^1.0.0",
"proxyquire": "^2.0.0",
"semantic-release": "^16.0.0-beta",
"server-destroy": "^1.0.1",
Expand Down
32 changes: 24 additions & 8 deletions test/success.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,18 +394,23 @@ test.serial('Do not add comment and labels to PR/issues from other repo', async
t.true(github.isDone());
});

test.serial('Ignore missing issues/PRs', async t => {
test.serial('Ignore missing and forbidden issues/PRs', async t => {
const owner = 'test_user';
const repo = 'test_repo';
const env = {GITHUB_TOKEN: 'github_token'};
const failTitle = 'The automated release is failing 🚨';
const pluginConfig = {failTitle};
const prs = [
{number: 1, pull_request: {}, state: 'closed'},
{number: 2, pull_request: {}, body: 'Fixes #3', state: 'closed'},
{number: 2, pull_request: {}, body: 'Fixes #4', state: 'closed'},
{number: 3, pull_request: {}, body: 'Fixes #5', state: 'closed'},
];
const options = {branch: 'master', repositoryUrl: `https://github.com/${owner}/${repo}.git`};
const commits = [{hash: '123', message: 'Commit 1 message\n\n Fix #1'}, {hash: '456', message: 'Commit 2 message'}];
const commits = [
{hash: '123', message: 'Commit 1 message\n\n Fix #1'},
{hash: '456', message: 'Commit 2 message'},
{hash: '789', message: 'Commit 3 message'},
];
const nextRelease = {version: '1.0.0'};
const releases = [{name: 'GitHub release', url: 'https://github.com/release'}];
const github = authenticate(env)
Expand All @@ -421,16 +426,24 @@ test.serial('Ignore missing issues/PRs', async t => {
.reply(200, [{sha: commits[0].hash}])
.get(`/repos/${owner}/${repo}/pulls/2/commits`)
.reply(200, [{sha: commits[1].hash}])
.get(`/repos/${owner}/${repo}/pulls/3/commits`)
.reply(200, [{sha: commits[2].hash}])
.post(`/repos/${owner}/${repo}/issues/1/comments`, {body: /This PR is included/})
.reply(200, {html_url: 'https://github.com/successcomment-1'})
.post(`/repos/${owner}/${repo}/issues/1/labels`, '["released"]')
.reply(200, {})
.post(`/repos/${owner}/${repo}/issues/2/comments`, {body: /This PR is included/})
.times(3)
.reply(404)
.post(`/repos/${owner}/${repo}/issues/3/comments`, {body: /This issue has been resolved/})
.reply(200, {html_url: 'https://github.com/successcomment-3'})
.post(`/repos/${owner}/${repo}/issues/3/labels`, '["released"]')
.post(`/repos/${owner}/${repo}/issues/3/comments`, {body: /This PR is included/})
.reply(403)
.post(`/repos/${owner}/${repo}/issues/4/comments`, {body: /This issue has been resolved/})
.reply(200, {html_url: 'https://github.com/successcomment-4'})
.post(`/repos/${owner}/${repo}/issues/4/labels`, '["released"]')
.reply(200, {})
.post(`/repos/${owner}/${repo}/issues/5/comments`, {body: /This issue has been resolved/})
.reply(200, {html_url: 'https://github.com/successcomment-5'})
.post(`/repos/${owner}/${repo}/issues/5/labels`, '["released"]')
.reply(200, {})
.get(
`/search/issues?q=${escape('in:title')}+${escape(`repo:${owner}/${repo}`)}+${escape('type:issue')}+${escape(
Expand All @@ -443,9 +456,12 @@ test.serial('Ignore missing issues/PRs', async t => {

t.true(t.context.log.calledWith('Added comment to issue #%d: %s', 1, 'https://github.com/successcomment-1'));
t.true(t.context.log.calledWith('Added labels %O to issue #%d', ['released'], 1));
t.true(t.context.log.calledWith('Added comment to issue #%d: %s', 3, 'https://github.com/successcomment-3'));
t.true(t.context.log.calledWith('Added labels %O to issue #%d', ['released'], 3));
t.true(t.context.log.calledWith('Added comment to issue #%d: %s', 4, 'https://github.com/successcomment-4'));
t.true(t.context.log.calledWith('Added labels %O to issue #%d', ['released'], 4));
t.true(t.context.log.calledWith('Added comment to issue #%d: %s', 5, 'https://github.com/successcomment-5'));
t.true(t.context.log.calledWith('Added labels %O to issue #%d', ['released'], 5));
t.true(t.context.error.calledWith("Failed to add a comment to the issue #%d as it doesn't exist.", 2));
t.true(t.context.error.calledWith('Not allowed to add a comment to the issue #%d.', 3));
t.true(github.isDone());
});

Expand Down

0 comments on commit 8e9d3d1

Please sign in to comment.