From 7bd8140c6f5161404579083518a6a86b5b52e8a7 Mon Sep 17 00:00:00 2001 From: Tobias <96661824+CrazyWolf13@users.noreply.github.com> Date: Sun, 8 Feb 2026 20:58:24 +0100 Subject: [PATCH] Refactor stale PR management script for clarity --- .github/workflows/stale_pr_close.yml | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/.github/workflows/stale_pr_close.yml b/.github/workflows/stale_pr_close.yml index df62a6f8e..5ffc9475a 100644 --- a/.github/workflows/stale_pr_close.yml +++ b/.github/workflows/stale_pr_close.yml @@ -1,5 +1,4 @@ name: Stale PR Management - on: schedule: # Runs daily at midnight UTC @@ -7,7 +6,6 @@ on: pull_request: types: - labeled - jobs: stale-prs: runs-on: ubuntu-latest @@ -20,8 +18,7 @@ jobs: const now = new Date(); const owner = context.repo.owner; const repo = context.repo.repo; - - // Handle when PR is labeled + // --- PR labeled event --- if (context.eventName === "pull_request" && context.payload.action === "labeled") { const label = context.payload.label?.name; if (label === "stale") { @@ -32,33 +29,26 @@ jobs: body: "This PR has been marked as stale. It will be closed if no new commits are added in 7 days." }); } - return; + return; // exit, nothing else to do } - - // Scheduled run: fetch all open PRs + // --- Scheduled run --- const { data: prs } = await github.pulls.list({ owner, repo, state: "open", per_page: 100 }); - for (const pr of prs) { const hasStale = pr.labels.some(l => l.name === "stale"); if (!hasStale) continue; - - // Fetch commits for this PR const { data: commits } = await github.pulls.listCommits({ owner, repo, pull_number: pr.number }); - const lastCommitDate = new Date(commits[commits.length - 1].commit.author.date); const diffDays = (now - lastCommitDate) / (1000 * 60 * 60 * 24); - if (diffDays > 7) { - // Close stale PR await github.pulls.update({ owner, repo, @@ -71,8 +61,7 @@ jobs: issue_number: pr.number, body: "Closing stale PR due to inactivity." }); - } else if (lastCommitDate > new Date(now - 7*24*60*60*1000)) { - // Remove stale label if recent activity + } else if (diffDays <= 7) { await github.issues.removeLabel({ owner, repo,