Skip to content

Commit

Permalink
fix: add comment only to merged PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Apr 6, 2018
1 parent 07b05d6 commit ae31009
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/success.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = async (

const prs = [].concat(
...(await Promise.all(
getSearchQueries(`repo:${owner}/${repo}+type:pr`, commits.map(commit => commit.hash)).map(async q => {
getSearchQueries(`repo:${owner}/${repo}+type:pr+is:merged`, commits.map(commit => commit.hash)).map(async q => {
const {data: {items}} = await github.search.issues({q});
return items;
})
Expand Down
4 changes: 2 additions & 2 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ test.serial('Comment on PR included in the releases', async t => {
.get(`/repos/${owner}/${repo}`)
.reply(200, {permissions: {push: true}})
.get(
`/search/issues?q=${escape(`repo:${owner}/${repo}`)}+${escape('type:pr')}+${commits
`/search/issues?q=${escape(`repo:${owner}/${repo}`)}+${escape('type:pr')}+${escape('is:merged')}+${commits
.map(commit => commit.hash)
.join('+')}`
)
Expand Down Expand Up @@ -281,7 +281,7 @@ test.serial('Verify, release and notify success', async t => {
})
.reply(200, {upload_url: uploadUrl, html_url: releaseUrl})
.get(
`/search/issues?q=${escape(`repo:${owner}/${repo}`)}+${escape('type:pr')}+${commits
`/search/issues?q=${escape(`repo:${owner}/${repo}`)}+${escape('type:pr')}+${escape('is:merged')}+${commits
.map(commit => commit.hash)
.join('+')}`
)
Expand Down
24 changes: 13 additions & 11 deletions test/success.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ test.serial('Add comment to PRs associated with release commits and issues close
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
`/search/issues?q=${escape(`repo:${owner}/${repo}`)}+${escape('type:pr')}+${escape('is:merged')}+${commits
.map(commit => commit.hash)
.join('+')}`
)
Expand Down Expand Up @@ -116,13 +116,15 @@ test.serial('Make multiple search queries if necessary', async t => {
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[0].hash}+${commits[1].hash}+${
commits[2].hash
}+${commits[3].hash}+${commits[4].hash}`
`/search/issues?q=${escape(`repo:${owner}/${repo}`)}+${escape('type:pr')}+${escape('is:merged')}+${
commits[0].hash
}+${commits[1].hash}+${commits[2].hash}+${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}+${commits[6].hash}`
`/search/issues?q=${escape(`repo:${owner}/${repo}`)}+${escape('type:pr')}+${escape('is:merged')}+${
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/})
Expand Down Expand Up @@ -167,7 +169,7 @@ test.serial('Do not add comment if no PR is associated with release commits', as
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
`/search/issues?q=${escape(`repo:${owner}/${repo}`)}+${escape('type:pr')}+${escape('is:merged')}+${commits
.map(commit => commit.hash)
.join('+')}`
)
Expand Down Expand Up @@ -200,7 +202,7 @@ test.serial('Do not add comment to PR/issues from other repo', async t => {
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
`/search/issues?q=${escape(`repo:${owner}/${repo}`)}+${escape('type:pr')}+${escape('is:merged')}+${commits
.map(commit => commit.hash)
.join('+')}`
)
Expand Down Expand Up @@ -232,7 +234,7 @@ test.serial('Ignore missing issues/PRs', async t => {
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
`/search/issues?q=${escape(`repo:${owner}/${repo}`)}+${escape('type:pr')}+${escape('is:merged')}+${commits
.map(commit => commit.hash)
.join('+')}`
)
Expand Down Expand Up @@ -276,7 +278,7 @@ test.serial('Add custom comment', async t => {
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
`/search/issues?q=${escape(`repo:${owner}/${repo}`)}+${escape('type:pr')}+${escape('is:merged')}+${commits
.map(commit => commit.hash)
.join('+')}`
)
Expand Down Expand Up @@ -315,7 +317,7 @@ test.serial('Ignore errors when adding comments and closing issues', async t =>
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
`/search/issues?q=${escape(`repo:${owner}/${repo}`)}+${escape('type:pr')}+${escape('is:merged')}+${commits
.map(commit => commit.hash)
.join('+')}`
)
Expand Down Expand Up @@ -366,7 +368,7 @@ test.serial('Close open issues when a release is successful', async t => {
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
`/search/issues?q=${escape(`repo:${owner}/${repo}`)}+${escape('type:pr')}+${escape('is:merged')}+${commits
.map(commit => commit.hash)
.join('+')}`
)
Expand Down

0 comments on commit ae31009

Please sign in to comment.