Skip to content

Commit 8ef0ba2

Browse files
authored
chore(prlinter): fixing some errors in the needs review workflow (#25464)
Fixing some of the remaining issues with the new needs review workflow - `aws-cdk-automation` does show up as MEMBER so need to filter it out - If the PR linter failed then we never made it to the assessReview. Make sure we assess review even if the linter fails ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent df3ae95 commit 8ef0ba2

File tree

2 files changed

+53
-14
lines changed

2 files changed

+53
-14
lines changed

Diff for: tools/@aws-cdk/prlint/lint.ts

+17-10
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ export class PullRequestLinter {
310310
* @param sha the commit sha to evaluate
311311
*/
312312
private async codeBuildJobSucceeded(sha: string): Promise<boolean> {
313-
const statuses = await this.client.rest.repos.listCommitStatusesForRef({
313+
const statuses = await this.client.repos.listCommitStatusesForRef({
314314
owner: this.prParams.owner,
315315
repo: this.prParams.repo,
316316
ref: sha,
@@ -340,7 +340,11 @@ export class PullRequestLinter {
340340
const reviews = await this.client.pulls.listReviews(this.prParams);
341341
// NOTE: MEMBER = a member of the organization that owns the repository
342342
// COLLABORATOR = has been invited to collaborate on the repository
343-
const maintainerRequestedChanges = reviews.data.some(review => review.author_association === 'MEMBER' && review.state === 'CHANGES_REQUESTED');
343+
const maintainerRequestedChanges = reviews.data.some(
344+
review => review.author_association === 'MEMBER'
345+
&& review.user?.login !== 'aws-cdk-automation'
346+
&& review.state === 'CHANGES_REQUESTED'
347+
);
344348
const prLinterFailed = reviews.data.find((review) => review.user?.login === 'aws-cdk-automation' && review.state !== 'DISMISSED') as Review;
345349
const userRequestsExemption = pr.labels.some(label => (label.name === Exemption.REQUEST_EXEMPTION || label.name === Exemption.REQUEST_CLARIFICATION));
346350
console.log('evaluation: ', JSON.stringify({
@@ -444,16 +448,19 @@ export class PullRequestLinter {
444448
});
445449

446450
await this.deletePRLinterComment();
447-
await this.communicateResult(validationCollector);
448-
449-
// also assess whether the PR needs review or not
450451
try {
451-
const state = await this.codeBuildJobSucceeded(sha);
452-
if (state) {
453-
await this.assessNeedsReview(pr);
452+
await this.communicateResult(validationCollector);
453+
// always assess the review, even if the linter fails
454+
} finally {
455+
// also assess whether the PR needs review or not
456+
try {
457+
const state = await this.codeBuildJobSucceeded(sha);
458+
if (state) {
459+
await this.assessNeedsReview(pr);
460+
}
461+
} catch (e) {
462+
console.log(`assessing review failed for sha ${sha}: `, e);
454463
}
455-
} catch (e) {
456-
console.log(`assessing review failed for sha ${sha}: `, e);
457464
}
458465
}
459466

Diff for: tools/@aws-cdk/prlint/test/lint.test.ts

+36-4
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,40 @@ describe('integration tests required on features', () => {
646646
});
647647
expect(mockAddLabel.mock.calls).toEqual([]);
648648
});
649+
650+
test('review happens even if linter fails', async () => {
651+
// GIVEN
652+
mockListReviews.mockImplementation(() => {
653+
return {
654+
data: [
655+
{ id: 1111122222, user: { login: 'aws-cdk-automation' }, state: 'CHANGES_REQUESTED' },
656+
{ id: 1111122223, user: { login: 'someuser' }, author_association: 'MEMBER', state: 'CHANGES_REQUESTED' },
657+
]
658+
}
659+
});
660+
(pr as any).title = 'blah';
661+
(pr as any).labels = [
662+
{
663+
name: 'pr-linter/exemption-requested',
664+
},
665+
{
666+
name: 'pr/needs-review',
667+
}
668+
];
669+
670+
// WHEN
671+
const prLinter = configureMock(pr);
672+
await expect(prLinter.validatePullRequestTarget(SHA)).rejects.toThrow();
673+
674+
// THEN
675+
expect(mockRemoveLabel.mock.calls[0][0]).toEqual({
676+
"issue_number": 1234,
677+
"name": "pr/needs-review",
678+
"owner": "aws",
679+
"repo": "aws-cdk",
680+
});
681+
expect(mockAddLabel.mock.calls).toEqual([]);
682+
});
649683
});
650684
});
651685

@@ -689,7 +723,7 @@ function configureMock(pr: Subset<linter.GitHubPr>, prFiles?: linter.GitHubFile[
689723
return {
690724
data: [{
691725
context: linter.CODE_BUILD_CONTEXT,
692-
state: 'succeeded',
726+
state: 'success',
693727
}],
694728
}
695729
},
@@ -708,9 +742,7 @@ function configureMock(pr: Subset<linter.GitHubPr>, prFiles?: linter.GitHubFile[
708742
pulls: pullsClient as any,
709743
issues: issuesClient as any,
710744
search: searchClient as any,
711-
rest: {
712-
repos: reposClient,
713-
},
745+
repos: reposClient as any,
714746
paginate: (method: any, args: any) => { return method(args).data },
715747
} as any,
716748
})

0 commit comments

Comments
 (0)