Skip to content

Commit 4d23801

Browse files
authored
chore(prlint): handle case where label does not exist (#25444)
Forgot to handle a case where the label does not exist on the pull request when trying to remove the label. Update to first check to make sure the label exists before removing it.
1 parent ae95540 commit 4d23801

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

tools/@aws-cdk/prlint/lint.ts

+16-10
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,15 @@ export class PullRequestLinter {
361361
// or the PR linter failed and the user didn't request an exemption
362362
|| (prLinterFailed && !userRequestsExemption)
363363
) {
364-
console.log(`removing labels from pr ${pr.number}`);
365-
this.client.issues.removeLabel({
366-
owner: this.prParams.owner,
367-
repo: this.prParams.repo,
368-
issue_number: pr.number,
369-
name: 'pr/needs-review',
370-
});
364+
if (pr.labels.some(label => label.name === 'pr/needs-review')) {
365+
console.log(`removing labels from pr ${pr.number}`);
366+
this.client.issues.removeLabel({
367+
owner: this.prParams.owner,
368+
repo: this.prParams.repo,
369+
issue_number: pr.number,
370+
name: 'pr/needs-review',
371+
});
372+
}
371373
return;
372374
} else {
373375
console.log(`adding labels to pr ${pr.number}`);
@@ -445,9 +447,13 @@ export class PullRequestLinter {
445447
await this.communicateResult(validationCollector);
446448

447449
// also assess whether the PR needs review or not
448-
const state = await this.codeBuildJobSucceeded(sha);
449-
if (state) {
450-
await this.assessNeedsReview(pr);
450+
try {
451+
const state = await this.codeBuildJobSucceeded(sha);
452+
if (state) {
453+
await this.assessNeedsReview(pr);
454+
}
455+
} catch (e) {
456+
console.log('assessing review failed: ', e);
451457
}
452458
}
453459

tools/@aws-cdk/prlint/test/lint.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,11 @@ describe('integration tests required on features', () => {
555555
data: [{ id: 1111122222, user: { login: 'aws-cdk-automation' }, state: 'CHANGES_REQUESTED' }]
556556
}
557557
});
558+
(pr as any).labels = [
559+
{
560+
name: 'pr/needs-review',
561+
}
562+
];
558563

559564
// WHEN
560565
const prLinter = configureMock(pr);
@@ -618,6 +623,9 @@ describe('integration tests required on features', () => {
618623
(pr as any).labels = [
619624
{
620625
name: 'pr-linter/exemption-requested',
626+
},
627+
{
628+
name: 'pr/needs-review',
621629
}
622630
];
623631

0 commit comments

Comments
 (0)