# ====================================================================================== # Workflow: Close Stale Fix PRs # ====================================================================================== # Usage: # - This workflow runs daily and closes agent-opened CI fix PRs that have been # open for more than 3 days. # # Expected Output: # - Any open PR whose branch matches the oz-agent-fix/run-* convention and that # was opened more than 3 days ago will be closed with an explanatory comment. # # ====================================================================================== name: Close Stale Fix PRs on: schedule: - cron: '0 12 * * *' # 8am EST workflow_dispatch: jobs: close-stale-fix-prs: runs-on: ubuntu-latest steps: - name: Close Stale Fix PRs uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: script: | const { owner, repo } = context.repo; const staleCutoffMs = 3 * 24 * 60 * 60 * 1000; // 3 days in milliseconds const now = Date.now(); // Paginate through all open PRs to find ones matching the branch convention const openPRs = await github.paginate(github.rest.pulls.list, { owner, repo, state: 'open', per_page: 100, }); const staleFixPRs = openPRs.filter(pr => { const branchMatches = /^oz-agent-fix\/run-/.test(pr.head.ref); const openedAt = new Date(pr.created_at).getTime(); const isStale = (now - openedAt) > staleCutoffMs; return branchMatches && isStale; }); if (staleFixPRs.length === 0) { console.log('No stale fix PRs found.'); return; } console.log(`Found ${staleFixPRs.length} stale fix PR(s). Closing them...`); for (const pr of staleFixPRs) { const ageMs = now - new Date(pr.created_at).getTime(); const ageDays = Math.floor(ageMs / (24 * 60 * 60 * 1000)); console.log(`Closing PR #${pr.number} (branch: ${pr.head.ref}, open for ${ageDays} day(s)): ${pr.title}`); await github.rest.issues.createComment({ owner, repo, issue_number: pr.number, body: `Closing this automated CI fix PR because it has been open for more than 3 days (${ageDays} day(s)) without being merged. Please review the underlying CI failures manually if they are still relevant.`, }); await github.rest.pulls.update({ owner, repo, pull_number: pr.number, state: 'closed', }); } console.log('Done.');