Skip to content

Commit

Permalink
fix push user detection
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-fidd committed Aug 14, 2024
1 parent 9604f2c commit e6c97e0
Showing 1 changed file with 8 additions and 31 deletions.
39 changes: 8 additions & 31 deletions src/classes/PullRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,6 @@ export default class PullRequest {

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

const pushUsers = (
await this.octokit.repos.listCollaborators({
owner: this.owner,
repo: this.repo,
permission: 'push',
})
).data.map(u => u.id);

console.log('\n**** reviews ****');
console.log(reviews);

console.log('\n**** push users ****');
console.log(pushUsers);

const latestReviewsObj: {
[key: number]: {
state: string;
Expand Down Expand Up @@ -170,33 +156,24 @@ export default class PullRequest {
}
}

const promises = [];
for (const r of Object.values(latestReviewsObj)) {
promises.push(
const reviewerPermissions = await Promise.all(
Object.values(latestReviewsObj).map(({ username }) =>
this.octokit.repos.getCollaboratorPermissionLevel({
owner: this.owner,
repo: this.repo,
username: r.username,
username,
}),
);
}
),
);

console.log('\n**** alternative approach ****');
const newPushUsers = (await Promise.all(promises))
.filter(
({ data }) =>
data.permission === 'write' || data.permission === 'admin',
)
const pushReviewers = reviewerPermissions
.filter(({ data }) => ['write', 'admin'].includes(data.permission))
.map(d => d.data?.user?.id);
console.log(newPushUsers);

const latestReviews = Object.values(latestReviewsObj).filter(({ userId }) =>
pushUsers.includes(userId),
pushReviewers.includes(userId),
);

console.log('\n**** latestReviews ****');
console.log(latestReviews);

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

if (latestReviews.filter(r => r.state === 'CHANGES_REQUESTED').length > 0) {
Expand Down

0 comments on commit e6c97e0

Please sign in to comment.