Skip to content

Commit

Permalink
add additional logging to debug push user detection (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-fidd authored Aug 14, 2024
1 parent df93c0e commit 9604f2c
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions src/classes/PullRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,19 @@ export default class PullRequest {
})
).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; time: number };
[key: number]: {
state: string;
time: number;
username: string;
userId: number;
};
} = {};

for (const r of reviews) {
Expand All @@ -142,10 +153,10 @@ export default class PullRequest {
const user = r.user.id;
const time = new Date(r.submitted_at).getTime();

if (!pushUsers.includes(user)) continue;

const review = {
state: r.state,
username: r.user.login,
userId: user,
time,
};

Expand All @@ -159,7 +170,32 @@ export default class PullRequest {
}
}

const latestReviews = Object.values(latestReviewsObj);
const promises = [];
for (const r of Object.values(latestReviewsObj)) {
promises.push(
this.octokit.repos.getCollaboratorPermissionLevel({
owner: this.owner,
repo: this.repo,
username: r.username,
}),
);
}

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

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

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

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

Expand Down

0 comments on commit 9604f2c

Please sign in to comment.