diff --git a/src/classes/PullRequest.ts b/src/classes/PullRequest.ts index 8c359b2..398fea2 100644 --- a/src/classes/PullRequest.ts +++ b/src/classes/PullRequest.ts @@ -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; @@ -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) {