Skip to content

[GitHub Actions] Close stale draft pull requests#3799

Open
mho22 wants to merge 3 commits into
trunkfrom
explore-github-draft-requests
Open

[GitHub Actions] Close stale draft pull requests#3799
mho22 wants to merge 3 commits into
trunkfrom
explore-github-draft-requests

Conversation

@mho22

@mho22 mho22 commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Motivation for the change, related issues

Open draft pull requests in this repository accumulate indefinitely. There are 56 open drafts today, and 33 of them have had no commits, comments, or reviews for more than 30 days — several have been silent for over six months. There is no automation that surfaces or retires abandoned drafts, so they bury PRs that are still active.

Implementation details

Adds .github/workflows/stale-draft-pull-requests.yml, a scheduled workflow that runs daily at 07:00 UTC and can also be triggered manually from the Actions tab. For each open draft pull request, the workflow computes the last real activity timestamp from:

  • the PR creation date,
  • every commit's committer date,
  • every non-bot issue comment, every review comment, and every submitted review.

The bot's own warning comments are excluded from this activity calculation so they don't reset the idle clock.

For each draft the workflow does one of:

  1. Warn — if the PR has been idle for at least 30 days and no warning has been posted since the last real activity, post a warning comment carrying a hidden HTML marker.
  2. Close — if a warning has already been posted, that warning is at least 7 days old, and no real activity happened since the warning, post a closing comment and close the PR.
  3. Skip — otherwise.

Pushing a commit, leaving a comment, or submitting a review after a warning invalidates the active warning and restarts the cycle, so a draft is never closed without a 7-day grace window after a warning is posted.

Other workflow hygiene:

  • concurrency.group: stale-draft-prs prevents overlapping runs from posting duplicate warnings.
  • if: github.repository == 'WordPress/wordpress-playground' keeps forks from running the workflow against their own drafts.
  • Workflow-level permissions: {} denies all scopes; the job opts in only to pull-requests: write and issues: write.
  • actions/github-script is pinned to the commit SHA for v7.0.1 since the job has write permissions.

Testing Instructions (or ideally a Blueprint)

GitHub Actions workflows are difficult to unit-test in isolation. After merging:

  1. Manually trigger the workflow from the Actions tab (workflow_dispatch) and confirm it iterates every open draft pull request without errors.
  2. The first run will warn the ~33 existing idle drafts. No PR will be closed on day 0, because no prior warnings exist.
  3. Wait 7 days. Confirm that drafts that received the warning and got no further activity are closed with the closing comment.
  4. Confirm that any commit, issue comment, review comment, or submitted review posted after a warning prevents closure on the next run.

@mho22 mho22 force-pushed the explore-github-draft-requests branch from ec1560b to f8b51bf Compare June 18, 2026 12:28
@mho22 mho22 marked this pull request as ready for review June 22, 2026 08:41
@mho22 mho22 requested review from a team and ashfame June 22, 2026 08:41
Copilot AI review requested due to automatic review settings June 30, 2026 08:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds automation to warn and close stale draft pull requests so abandoned drafts don’t accumulate indefinitely.

Changes:

  • Introduces a scheduled + manually-triggerable GitHub Actions workflow to evaluate activity on open draft PRs.
  • Posts a warning after 30 idle days, then closes after a 7-day grace period if no new activity occurs.
  • Generates an Actions job summary and optionally posts a Slack report.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/stale-draft-pull-requests.yml Outdated
Comment thread .github/workflows/stale-draft-pull-requests.yml Outdated
Comment thread .github/workflows/stale-draft-pull-requests.yml Outdated
Comment thread .github/workflows/stale-draft-pull-requests.yml Outdated
Comment thread .github/workflows/stale-draft-pull-requests.yml
Comment thread .github/workflows/stale-draft-pull-requests.yml Outdated
Comment thread .github/workflows/stale-draft-pull-requests.yml Outdated
@akirk

akirk commented Jun 30, 2026

Copy link
Copy Markdown
Member

@mho22 I took the liberty to add reporting so that we can get notified about the stale PRs being closed via Slack via a STALE_DRAFT_PRS_SLACK_WEBHOOK that can be added as a secret.

It also adds a final Actions output so that the list of affected PRs can be reviewed there.

What do you think? We can also revert this if you think it's not a good idea.

@mho22

mho22 commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

@akirk I really like the idea! I am only worried about the amount of "reminders" we will get on slack over time and being overwhelmed to the point to not read them anymore. But that needs to be tested. And if it doesn't work as planned we can reset that with a new pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants