From d767570291fff049e0230d5ee56d40a9e2877e2a Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Mon, 17 Nov 2025 20:48:02 +0100 Subject: [PATCH] ci/github-script/bot: skip PR checks when stale It makes not much sense to run all the checks for PRs when we can already tell they are stale beforehand. In particular this should avoid creating ~3.3k temporary merge commits every day, for PRs that surely won't have had any change. The number of merge commits *could* play a role in the growing size of the fork network. We'll have GitHub look into the metrics before and after this change to see whether that is any improvement. --- ci/github-script/bot.js | 42 +++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/ci/github-script/bot.js b/ci/github-script/bot.js index 65db03ffaee5..20b717238996 100644 --- a/ci/github-script/bot.js +++ b/ci/github-script/bot.js @@ -481,22 +481,6 @@ module.exports = async ({ github, context, core, dry }) => { }, ) - if (item.pull_request || context.payload.pull_request) { - stats.prs++ - Object.assign( - itemLabels, - await handlePullRequest({ item, stats, events }), - ) - } else { - stats.issues++ - if (item.labels.some(({ name }) => name === '4.workflow: auto-close')) { - // If this returns true, the issue was closed. In this case we return, to not - // label the issue anymore. Most importantly this avoids unlabeling stale issues - // which are closed via auto-close. - if (await handleAutoClose(item)) return - } - } - const latest_event_at = new Date( events .filter(({ event }) => @@ -537,6 +521,29 @@ module.exports = async ({ github, context, core, dry }) => { log('latest_event_at', latest_event_at.toISOString()) const stale_at = new Date(new Date().setDate(new Date().getDate() - 180)) + const is_stale = latest_event_at < stale_at + + if (item.pull_request || context.payload.pull_request) { + // No need to compute merge commits for stale PRs over and over again. + // This increases the repo size on GitHub's side unnecessarily and wastes + // a lot of API requests, too. Any relevant change will result in the + // stale status to change and thus pick up the PR again for labeling. + if (!is_stale) { + stats.prs++ + Object.assign( + itemLabels, + await handlePullRequest({ item, stats, events }), + ) + } + } else { + stats.issues++ + if (item.labels.some(({ name }) => name === '4.workflow: auto-close')) { + // If this returns true, the issue was closed. In this case we return, to not + // label the issue anymore. Most importantly this avoids unlabeling stale issues + // which are closed via auto-close. + if (await handleAutoClose(item)) return + } + } // Create a map (Label -> Boolean) of all currently set labels. // Each label is set to True and can be disabled later. @@ -550,8 +557,7 @@ module.exports = async ({ github, context, core, dry }) => { ) Object.assign(itemLabels, { - '2.status: stale': - !before['1.severity: security'] && latest_event_at < stale_at, + '2.status: stale': !before['1.severity: security'] && is_stale, }) const after = Object.assign({}, before, itemLabels)