diff --git a/__snapshots__/java-yoshi.js b/__snapshots__/java-yoshi.js index 13ac61850..576dc7120 100644 --- a/__snapshots__/java-yoshi.js +++ b/__snapshots__/java-yoshi.js @@ -493,8 +493,7 @@ This PR was generated with [Release Please](https://github.com/googleapis/releas exports['labels'] = { "labels": [ - "autorelease: pending", - "type: process" + "autorelease: pending" ] } diff --git a/src/github.ts b/src/github.ts index 043bbd42a..da8c6c104 100644 --- a/src/github.ts +++ b/src/github.ts @@ -473,14 +473,18 @@ export class GitHub { repo: this.repo, } )) as Octokit.Response; - for (let i = 0, pull; i < pullsResponse.data.length; i++) { - pull = pullsResponse.data[i]; - for (let ii = 0, label; ii < pull.labels.length; ii++) { - label = pull.labels[ii]; - if (labels.indexOf(label.name) !== -1) { - openReleasePRs.push(pull); + for (const pull of pullsResponse.data) { + let hasAllLabels = false; + const observedLabels = pull.labels.map(l => l.name); + for (const expectedLabel of labels) { + if (observedLabels.includes(expectedLabel)) { + hasAllLabels = true; + } else { + hasAllLabels = false; + break; } } + if (hasAllLabels) openReleasePRs.push(pull); } return openReleasePRs; } diff --git a/src/release-pr.ts b/src/release-pr.ts index ea0249163..3d4e80556 100644 --- a/src/release-pr.ts +++ b/src/release-pr.ts @@ -57,7 +57,7 @@ export interface ReleaseCandidate { previousTag?: string; } -const DEFAULT_LABELS = 'autorelease: pending,type: process'; +const DEFAULT_LABELS = 'autorelease: pending'; export class ReleasePR { apiUrl: string; @@ -127,7 +127,10 @@ export class ReleasePR { if (includePackageName && !pr.title.includes(` ${this.packageName} `)) { continue; } - checkpoint(`closing pull #${pr.number}`, CheckpointType.Failure); + checkpoint( + `closing pull #${pr.number} on ${this.repoUrl}`, + CheckpointType.Failure + ); await this.gh.closePR(pr.number); } } @@ -225,6 +228,10 @@ export class ReleasePR { // a return of -1 indicates that PR was not updated. if (pr > 0) { await this.gh.addLabels(this.labels, pr); + checkpoint( + `${this.repoUrl} find stale PRs with label "${this.labels.join(',')}"`, + CheckpointType.Success + ); await this.closeStaleReleasePRs(pr, includePackageName); } } diff --git a/test/github.ts b/test/github.ts index 5286a3acd..48927342b 100644 --- a/test/github.ts +++ b/test/github.ts @@ -13,6 +13,7 @@ // limitations under the License. import * as nock from 'nock'; +import { expect } from 'chai'; nock.disableNetConnect(); import { readFileSync } from 'fs'; @@ -59,4 +60,49 @@ describe('GitHub', () => { req.done(); }); }); + + describe('findOpenReleasePRs', () => { + it('returns PRs that have all release labels', async () => { + const req = nock('https://api.github.com') + .get('/repos/fake/fake/pulls?state=open&per_page=100') + .reply(200, [ + { + number: 99, + labels: [{ name: 'autorelease: pending' }, { name: 'process' }], + }, + { + number: 100, + labels: [{ name: 'autorelease: pending' }], + }, + ]); + const prs = await github.findOpenReleasePRs([ + 'autorelease: pending', + 'process', + ]); + const numbers = prs.map(pr => pr.number); + expect(numbers).to.include(99); + expect(numbers).to.not.include(100); + req.done(); + }); + + it('returns PRs when only one release label is configured', async () => { + const req = nock('https://api.github.com') + .get('/repos/fake/fake/pulls?state=open&per_page=100') + .reply(200, [ + { + number: 99, + labels: [{ name: 'autorelease: pending' }, { name: 'process' }], + }, + { + number: 100, + labels: [{ name: 'autorelease: pending' }], + }, + ]); + const prs = await github.findOpenReleasePRs(['autorelease: pending']); + const numbers = prs.map(pr => pr.number); + expect(numbers).to.include(99); + expect(numbers).to.include(100); + req.done(); + }); + }); });