Skip to content

Commit

Permalink
Change labels to only consider reviews from users with push access (#23)
Browse files Browse the repository at this point in the history
* change approved label to only consider reviews from users with push access

* all non-push reviews are ignored by labels
  • Loading branch information
matt-fidd authored Aug 13, 2024
1 parent 37d1234 commit df93c0e
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions src/classes/PullRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,34 +124,45 @@ export default class PullRequest {

if (reviews.length < 1) return 'readyForReview';

const latestReviewsObj: { [key: number]: { state: string; time: number } } =
{};
const pushUsers = (
await this.octokit.repos.listCollaborators({
owner: this.owner,
repo: this.repo,
permission: 'push',
})
).data.map(u => u.id);

const latestReviewsObj: {
[key: number]: { state: string; time: number };
} = {};

for (const r of reviews) {
if (!r?.user?.id || !r.submitted_at) continue;

const user = r.user.id;
const time = new Date(r.submitted_at).getTime();

if (!latestReviewsObj[user]) {
latestReviewsObj[user] = {
state: r.state,
time,
};
if (!pushUsers.includes(user)) continue;

const review = {
state: r.state,
time,
};

if (!latestReviewsObj[user]) {
latestReviewsObj[user] = review;
continue;
}

if (latestReviewsObj[user].time < time) {
latestReviewsObj[user] = {
state: r.state,
time,
};
latestReviewsObj[user] = review;
}
}

const latestReviews = Object.values(latestReviewsObj);

if (!latestReviews.length) return 'readyForReview';

if (latestReviews.filter(r => r.state === 'CHANGES_REQUESTED').length > 0) {
return 'changesRequested';
}
Expand All @@ -165,6 +176,10 @@ export default class PullRequest {
return 'needsMoreApprovals';
}

return 'approved';
if (approvingReviews > 0) {
return 'approved';
}

return 'readyForReview';
}
}

0 comments on commit df93c0e

Please sign in to comment.