actions/bcr-pr-reviewer: Update PR activity filter to 6 hours (#2596)
This PR updates the review_prs action type to only review PRs that have
had activity in the past 6 hours.
diff --git a/actions/bcr-pr-reviewer/index.js b/actions/bcr-pr-reviewer/index.js
index d713f08..359dd23 100644
--- a/actions/bcr-pr-reviewer/index.js
+++ b/actions/bcr-pr-reviewer/index.js
@@ -683,9 +683,42 @@
state: 'open',
});
+ const sixHoursAgo = new Date(Date.now() - 6 * 60 * 60 * 1000);
+
// Review each PR
for (const pr of prs) {
- await reviewPR(octokit, owner, repo, pr.number);
+ let isOughtToBeReviewed = new Date(pr.updated_at) >= sixHoursAgo;
+
+ // If not active by PR timestamp, check CI activity
+ if (!isOughtToBeReviewed) {
+ try {
+ console.log(`PR #${pr.number} is inactive by timestamp. Checking CI status...`);
+ const { data: checkRunsData } = await octokit.rest.checks.listForRef({
+ owner,
+ repo,
+ ref: pr.head.sha,
+ });
+
+ // Check if any check run completed or started in the last 6 hours
+ const hasRecentCiActivity = checkRunsData.check_runs.some(run => {
+ const timeToCompare = run.completed_at ? new Date(run.completed_at) : new Date(run.started_at);
+ return timeToCompare >= sixHoursAgo;
+ });
+
+ if (hasRecentCiActivity) {
+ console.log(`PR #${pr.number} has recent CI activity. Proceeding with review.`);
+ isOughtToBeReviewed = true;
+ }
+ } catch (error) {
+ console.error(`Failed to fetch check runs for PR #${pr.number}: ${error.message}`);
+ }
+ }
+
+ if (isOughtToBeReviewed) {
+ await reviewPR(octokit, owner, repo, pr.number);
+ } else {
+ console.log(`Skipping PR #${pr.number} as it has no activity in the past 6 hours.`);
+ }
}
}