Skip to content

Commit 8059d80

Browse files
Add a GHA to close inactive PRs in Draft status (60 days) (#47559)
* adds workflow to close stale prs * add a dry run mode and default to true * Update .github/workflows/close_stale_draft_prs.yml Co-authored-by: Justin Retzolk <44710313+justinretzolk@users.noreply.github.com> --------- Co-authored-by: Justin Retzolk <44710313+justinretzolk@users.noreply.github.com>
1 parent 9065920 commit 8059d80

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright IBM Corp. 2014, 2026
2+
# "SPDX-License-Identifier: MPL-2.0"
3+
4+
name: "Close Stale Draft PRs"
5+
on:
6+
schedule:
7+
- cron: "0 0 * * *"
8+
workflow_dispatch:
9+
inputs:
10+
dry_run:
11+
description: "Describe actions without commenting or closing PRs"
12+
required: false
13+
type: boolean
14+
default: false
15+
16+
permissions:
17+
pull-requests: write
18+
19+
jobs:
20+
close-stale-drafts:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Close stale draft PRs
24+
env:
25+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
GH_REPO: ${{ github.repository }}
27+
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' &&
28+
github.event.inputs.dry_run || 'true' }}
29+
run: |
30+
# Calculate the date 60 days ago in ISO format (YYYY-MM-DD) GNU/BSD compatible
31+
DATE=$(date -u -d "60 days ago" +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -v-60d +%Y-%m-%dT%H:%M:%SZ)
32+
33+
echo "Finding draft PRs updated before $DATE (dry_run=$DRY_RUN)..."
34+
35+
# Use gh search prs to find open draft PRs matching the criteria
36+
PRS=$(gh search prs \
37+
--state open \
38+
--repo ${{ github.repository }} \
39+
--draft \
40+
--updated "<$DATE" \
41+
--json number \
42+
-q '.[].number')
43+
44+
if [ -z "$PRS" ]; then
45+
echo "No stale draft PRs found."
46+
exit 0
47+
fi
48+
49+
for PR in $PRS; do
50+
echo "Processing PR #$PR"
51+
if [ "$DRY_RUN" = "true" ]; then
52+
echo "[DRY RUN] Would comment on and close PR #$PR"
53+
else
54+
echo -e "This draft pull request is being closed because it has been inactive for _60 days_ ⏳. This helps our maintainers find and focus on active contributions.\n\nIf you would like to continue working on this, please reopen the pull request and mark it as ready for review when complete. Thank you!" \
55+
| gh pr comment $PR --body-file -
56+
gh pr close $PR
57+
fi
58+
done

0 commit comments

Comments
 (0)