Skip to content

Commit

Permalink
Merge eeb37c7 into 48fc389
Browse files Browse the repository at this point in the history
  • Loading branch information
CatChen authored Aug 28, 2022
2 parents 48fc389 + eeb37c7 commit c57c27a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
14 changes: 7 additions & 7 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async function run(): Promise<void> {
if (reviewRequests.users.length > 0) {
info(
`Review requested from users: ${reviewRequests.users
.map((user) => user.name)
.map((user) => `${user.login} (${user.html_url})`)
.join()}`
);
}
Expand Down Expand Up @@ -124,30 +124,34 @@ async function run(): Promise<void> {
Date.parse(y.submitted_at ?? "") - Date.parse(x.submitted_at ?? "")
);
if (reviewRequests.users.length === 0 && reviewRequests.teams.length === 0) {
const lastReview = reviewsSortedByDescendingTime[0]?.state ?? "";
info(`Last review state: ${lastReview}`);
approved = lastReview === APPROVED;
const lastReview = reviewsSortedByDescendingTime[0];
info(`Last review state: ${lastReview?.state ?? "none"}`);
approved = lastReview?.state === APPROVED;
} else {
const reviewUserIds = reviewRequests.users.map((user) => user.id);
const lastReviewPerUserId = reviewsSortedByDescendingTime.reduce(
(result, review) => {
const user = review.user;
if (user) {
result[user.id] = result[user.id] ?? review.state;
result[user.id] = result[user.id] ?? review;
}
return result;
},
{} as {
[id: string]: components["schemas"]["pull-request-review"]["state"];
[id: string]: components["schemas"]["pull-request-review"];
}
);
info(`Last review by user:`);
for (const user of reviewRequests.users) {
info(` ${user.name}: ${lastReviewPerUserId[user.id]}`);
info(
` ${user.login}: ${lastReviewPerUserId[user.id].state ?? "none"} (${
lastReviewPerUserId[user.id].html_url
})`
);
}
approved = reviewUserIds
.map((userId) => lastReviewPerUserId[userId])
.every((state) => state === APPROVED);
.every((review) => review.state === APPROVED);
}

if (!approved) {
Expand Down

0 comments on commit c57c27a

Please sign in to comment.