Skip to content

Commit

Permalink
fix: do not comment on other repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg authored and gr2m committed Feb 25, 2018
1 parent fb352f7 commit d3e5f66
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/success.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {uniqBy, template} = require('lodash');
const {isUndefined, uniqBy, template} = require('lodash');
const parseGithubUrl = require('parse-github-url');
const AggregateError = require('aggregate-error');
const issueParser = require('issue-parser')('github');
Expand Down Expand Up @@ -32,7 +32,11 @@ module.exports = async (
// Parse the release commits message and PRs body to find resolved issues/PRs via comment keyworkds
const issues = [...prs.map(pr => pr.body), ...commits.map(commit => commit.message)].reduce((issues, message) => {
return message
? issues.concat(issueParser(message).actions.map(action => ({number: parseInt(action.issue, 10)})))
? issues.concat(
issueParser(message)
.actions.filter(action => isUndefined(action.slug) || action.slug === `${owner}/${repo}`)
.map(action => ({number: parseInt(action.issue, 10)}))
)
: issues;
}, []);

Expand Down
35 changes: 35 additions & 0 deletions test/success.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,41 @@ test.serial('Do not add comment if no PR is associated with release commits', as
t.true(github.isDone());
});

test.serial('Do not add comment to PR/issues from other repo', async t => {
const owner = 'test_user';
const repo = 'test_repo';
process.env.GITHUB_TOKEN = 'github_token';
const failTitle = 'The automated release is failing 🚨';
const pluginConfig = {failTitle};
const options = {branch: 'master', repositoryUrl: `https://github.com/${owner}/${repo}.git`};
const commits = [
{hash: '123', message: 'Commit 1 message\n\n Fix other/other#1'},
{hash: '456', message: `Commit 2 message Fix ${owner}/${repo}#2`},
{hash: '789', message: 'Commit 3 message Closes other/other#3'},
];
const nextRelease = {version: '1.0.0'};
const releases = [{name: 'GitHub release', url: 'https://github.com/release'}];
const github = authenticate()
.get(
`/search/issues?q=${escape(`repo:${owner}/${repo}`)}+${escape('type:pr')}+${commits
.map(commit => commit.hash)
.join('+')}`
)
.reply(200, {items: []})
.post(`/repos/${owner}/${repo}/issues/2/comments`, {body: /This issue has been resolved/})
.reply(200, {html_url: 'https://github.com/successcomment-2'})
.get(
`/search/issues?q=${escape('in:title')}+${escape(`repo:${owner}/${repo}`)}+${escape('type:issue')}+${escape(
'state:open'
)}+${escape(failTitle)}`
)
.reply(200, {items: []});

await success(pluginConfig, {options, commits, nextRelease, releases, logger: t.context.logger});

t.true(github.isDone());
});

test.serial('Add custom comment', async t => {
const owner = 'test_user';
const repo = 'test_repo';
Expand Down

0 comments on commit d3e5f66

Please sign in to comment.