Skip to content

Commit

Permalink
chore: changed logic for opened PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Nov 26, 2024
1 parent 21d9f55 commit c3540aa
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/utils/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,25 +270,30 @@ async function getReviewByUser(context: Context, pullRequest: Awaited<ReturnType

async function shouldSkipPullRequest(
context: Context,
pullRequests: Awaited<ReturnType<typeof getReviewByUser>>,
pullRequest: Awaited<ReturnType<typeof getOpenedPullRequestsForUser>>[0],
reviews: Awaited<ReturnType<typeof getReviewByUser>>,
{ owner, repo, issueNumber }: { owner: string; repo: string; issueNumber: number },
reviewDelayTolerance: string
) {
if (!pullRequests.size) {
return false;
const timeline = await context.octokit.paginate(context.octokit.rest.issues.listEventsForTimeline, {
owner,
repo,
issue_number: issueNumber,
});
const reviewEvent = timeline.filter((o) => o.event === "review_requested").pop();
if (!reviews.size) {
const toCompare = reviewEvent && "created_at" in reviewEvent ? reviewEvent : pullRequest;
return new Date().getTime() - new Date(toCompare.created_at).getTime() >= getTimeValue(reviewDelayTolerance);
}
if (pullRequests.values().some((o) => o.state === "CHANGES_REQUESTED")) {
if (reviews.values().some((o) => o.state === "CHANGES_REQUESTED")) {
return false;
} else if (
!reviews.values().some((o) => o.state === "APPROVED") &&
reviewEvent &&
"created_at" in reviewEvent &&
new Date().getTime() - new Date(reviewEvent.created_at).getTime() >= getTimeValue(reviewDelayTolerance)
) {
return false;
} else if (!pullRequests.values().some((o) => o.state === "APPROVED")) {
const timeline = await context.octokit.paginate(context.octokit.rest.issues.listEventsForTimeline, {
owner,
repo,
issue_number: issueNumber,
});
const reviewEvent = timeline.filter((o) => o.event === "review_requested").pop();
if (reviewEvent && "created_at" in reviewEvent && new Date().getTime() - new Date(reviewEvent.created_at).getTime() < getTimeValue(reviewDelayTolerance)) {
return false;
}
}
return true;
}
Expand All @@ -303,13 +308,15 @@ export async function getPendingOpenedPullRequests(context: Context, username: s
const openedPullRequests = await getOpenedPullRequestsForUser(context, username);
const result: (typeof openedPullRequests)[number][] = [];

console.log("opened prs", openedPullRequests.length);
for (let i = 0; openedPullRequests && i < openedPullRequests.length; i++) {
const openedPullRequest = openedPullRequests[i];
if (!openedPullRequest) continue;
const { owner, repo } = getOwnerRepoFromHtmlUrl(openedPullRequest.html_url);
const latestReviewsByUser = await getReviewByUser(context, openedPullRequest);
const shouldSkipPr = await shouldSkipPullRequest(
context,
openedPullRequest,
latestReviewsByUser,
{ owner, repo, issueNumber: openedPullRequest.number },
reviewDelayTolerance
Expand Down

0 comments on commit c3540aa

Please sign in to comment.