Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(prlint): a review label doesn't appear when a PR is approved if there are too many comments #31290

Merged
merged 7 commits into from
Sep 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions tools/@aws-cdk/prlint/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,17 +373,17 @@ export class PullRequestLinter {
private async assessNeedsReview(
pr: Pick<GitHubPr, 'mergeable_state' | 'draft' | 'labels' | 'number'>,
): Promise<void> {
const reviews = await this.client.pulls.listReviews(this.prParams);
console.log(JSON.stringify(reviews.data));
const reviewsData = await this.client.paginate(this.client.pulls.listReviews, this.prParams);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.log(JSON.stringify(reviewsData));

// NOTE: MEMBER = a member of the organization that owns the repository
// COLLABORATOR = has been invited to collaborate on the repository
const maintainerRequestedChanges = reviews.data.some(
const maintainerRequestedChanges = reviewsData.some(
review => review.author_association === 'MEMBER'
&& review.user?.login !== 'aws-cdk-automation'
&& review.state === 'CHANGES_REQUESTED',
);
const maintainerApproved = reviews.data.some(
const maintainerApproved = reviewsData.some(
review => review.author_association === 'MEMBER'
&& review.state === 'APPROVED',
);
Expand All @@ -403,7 +403,7 @@ export class PullRequestLinter {
// be dismissed by a maintainer to respect another reviewer's requested changes.
// 5. Checking if any reviewers' most recent review requested changes
// -> If so, the PR is considered to still need changes to meet community review.
const reviewsByTrustedCommunityMembers = reviews.data
const reviewsByTrustedCommunityMembers = reviewsData
.filter(review => this.getTrustedCommunityMembers().includes(review.user?.login ?? ''))
.filter(review => review.state !== 'PENDING' && review.state !== 'COMMENTED')
.reduce((grouping, review) => {
Expand All @@ -420,12 +420,12 @@ export class PullRequestLinter {
...grouping,
[review.user!.login]: newest,
};
}, {} as Record<string, typeof reviews.data[0]>);
}, {} as Record<string, typeof reviewsData[0]>);
console.log('raw data: ', JSON.stringify(reviewsByTrustedCommunityMembers));
const communityApproved = Object.values(reviewsByTrustedCommunityMembers).some(({state}) => state === 'APPROVED');
const communityRequestedChanges = !communityApproved && Object.values(reviewsByTrustedCommunityMembers).some(({state}) => state === 'CHANGES_REQUESTED')

const prLinterFailed = reviews.data.find((review) => review.user?.login === 'aws-cdk-automation' && review.state !== 'DISMISSED') as Review;
const prLinterFailed = reviewsData.find((review) => review.user?.login === 'aws-cdk-automation' && review.state !== 'DISMISSED') as Review;
const userRequestsExemption = pr.labels.some(label => (label.name === Exemption.REQUEST_EXEMPTION || label.name === Exemption.REQUEST_CLARIFICATION));
console.log('evaluation: ', JSON.stringify({
draft: pr.draft,
Expand Down