Skip to content

Commit fb352f7

Browse files
pvdlggr2m
authored andcommitted
fix: prevent duplicate comments on PRs
1 parent 33d560a commit fb352f7

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

lib/success.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,18 @@ module.exports = async (
3030
debug('found pull requests: %O', prs.map(pr => pr.number));
3131

3232
// Parse the release commits message and PRs body to find resolved issues/PRs via comment keyworkds
33-
const issues = uniqBy(
34-
[...prs.map(pr => pr.body), ...commits.map(commit => commit.message)]
35-
.reduce((issues, message) => {
36-
return message
37-
? issues.concat(issueParser(message).actions.map(action => ({number: parseInt(action.issue, 10)})))
38-
: issues;
39-
}, [])
40-
.filter(issue => !prs.find(pr => pr.number === issue.number)),
41-
'number'
42-
);
33+
const issues = [...prs.map(pr => pr.body), ...commits.map(commit => commit.message)].reduce((issues, message) => {
34+
return message
35+
? issues.concat(issueParser(message).actions.map(action => ({number: parseInt(action.issue, 10)})))
36+
: issues;
37+
}, []);
4338

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

4641
const errors = [];
4742

4843
await Promise.all(
49-
[...prs, ...issues].map(async issue => {
44+
uniqBy([...prs, ...issues], 'number').map(async issue => {
5045
const body = successComment
5146
? template(successComment)({branch, lastRelease, commits, nextRelease, releases, issue})
5247
: getSuccessComment(issue, releaseInfos, nextRelease);

test/success.test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ test.serial('Make multiple search queries if necessary', async t => {
110110
{hash: repeat('d', 40), message: 'Commit 4 message'},
111111
{hash: repeat('e', 40), message: 'Commit 5 message'},
112112
{hash: repeat('f', 40), message: 'Commit 6 message'},
113+
{hash: repeat('g', 40), message: 'Commit 6 message'},
113114
];
114115
const nextRelease = {version: '1.0.0'};
115116
const releases = [{name: 'GitHub release', url: 'https://github.com/release'}];
@@ -120,8 +121,10 @@ test.serial('Make multiple search queries if necessary', async t => {
120121
}+${commits[3].hash}+${commits[4].hash}`
121122
)
122123
.reply(200, {items: [prs[0], prs[1], prs[2], prs[3], prs[4]]})
123-
.get(`/search/issues?q=${escape(`repo:${owner}/${repo}`)}+${escape('type:pr')}+${commits[5].hash}`)
124-
.reply(200, {items: [prs[5]]})
124+
.get(
125+
`/search/issues?q=${escape(`repo:${owner}/${repo}`)}+${escape('type:pr')}+${commits[5].hash}+${commits[6].hash}`
126+
)
127+
.reply(200, {items: [prs[5], prs[1]]})
125128
.post(`/repos/${owner}/${repo}/issues/1/comments`, {body: /This PR is included/})
126129
.reply(200, {html_url: 'https://github.com/successcomment-1'})
127130
.post(`/repos/${owner}/${repo}/issues/2/comments`, {body: /This PR is included/})

0 commit comments

Comments
 (0)