Skip to content

Commit

Permalink
fix: process label was causing PRs to be closed (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Feb 12, 2020
1 parent b096454 commit de3d557
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 10 deletions.
3 changes: 1 addition & 2 deletions __snapshots__/java-yoshi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}

Expand Down
16 changes: 10 additions & 6 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,14 +473,18 @@ export class GitHub {
repo: this.repo,
}
)) as Octokit.Response<Octokit.PullsListResponseItem[]>;
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;
}
Expand Down
11 changes: 9 additions & 2 deletions src/release-pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
}
Expand Down
46 changes: 46 additions & 0 deletions test/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

import * as nock from 'nock';
import { expect } from 'chai';
nock.disableNetConnect();

import { readFileSync } from 'fs';
Expand Down Expand Up @@ -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();
});
});
});

0 comments on commit de3d557

Please sign in to comment.