Skip to content

Commit

Permalink
fix: prevent duplicate comments on PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg authored and gr2m committed Feb 24, 2018
1 parent 33d560a commit fb352f7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
17 changes: 6 additions & 11 deletions lib/success.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,18 @@ module.exports = async (
debug('found pull requests: %O', prs.map(pr => pr.number));

// Parse the release commits message and PRs body to find resolved issues/PRs via comment keyworkds
const issues = uniqBy(
[...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;
}, [])
.filter(issue => !prs.find(pr => pr.number === issue.number)),
'number'
);
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;
}, []);

debug('found issues via comments: %O', issues);

const errors = [];

await Promise.all(
[...prs, ...issues].map(async issue => {
uniqBy([...prs, ...issues], 'number').map(async issue => {
const body = successComment
? template(successComment)({branch, lastRelease, commits, nextRelease, releases, issue})
: getSuccessComment(issue, releaseInfos, nextRelease);
Expand Down
7 changes: 5 additions & 2 deletions test/success.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ test.serial('Make multiple search queries if necessary', async t => {
{hash: repeat('d', 40), message: 'Commit 4 message'},
{hash: repeat('e', 40), message: 'Commit 5 message'},
{hash: repeat('f', 40), message: 'Commit 6 message'},
{hash: repeat('g', 40), message: 'Commit 6 message'},
];
const nextRelease = {version: '1.0.0'};
const releases = [{name: 'GitHub release', url: 'https://github.com/release'}];
Expand All @@ -120,8 +121,10 @@ test.serial('Make multiple search queries if necessary', async t => {
}+${commits[3].hash}+${commits[4].hash}`
)
.reply(200, {items: [prs[0], prs[1], prs[2], prs[3], prs[4]]})
.get(`/search/issues?q=${escape(`repo:${owner}/${repo}`)}+${escape('type:pr')}+${commits[5].hash}`)
.reply(200, {items: [prs[5]]})
.get(
`/search/issues?q=${escape(`repo:${owner}/${repo}`)}+${escape('type:pr')}+${commits[5].hash}+${commits[6].hash}`
)
.reply(200, {items: [prs[5], prs[1]]})
.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/2/comments`, {body: /This PR is included/})
Expand Down

0 comments on commit fb352f7

Please sign in to comment.