Skip to content

Stale PRs

Stale PRs #52

Workflow file for this run

name: Stale PRs
on:
schedule:
- cron: "0 9 * * 1-5"
workflow_dispatch:
permissions:
contents: read
pull-requests: write
issues: write
jobs:
stale:
name: Check for stale PRs
runs-on: ubuntu-latest
steps:
- uses: actions/stale@b5d41d4e1d5dceea10e7104786b73624c18a190f # v10
with:
stale-pr-message: "This PR has been inactive for 14 days. It may also be out of date with the base branch. Please rebase or close if no longer needed."
days-before-pr-stale: 14
days-before-pr-close: 7
stale-pr-label: "stale"
exempt-pr-labels: "pinned,work-in-progress"
days-before-issue-stale: -1
days-before-issue-close: -1
outdated:
name: Flag outdated PRs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
- name: Check PRs behind base branch
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr list --state open --json number,baseRefName,headRefName --jq '.[]' | while read -r pr; do
NUMBER=$(echo "$pr" | jq -r '.number')
BASE=$(echo "$pr" | jq -r '.baseRefName')
HEAD=$(echo "$pr" | jq -r '.headRefName')
git fetch origin "$BASE" "$HEAD" 2>/dev/null || continue
BEHIND=$(git rev-list --count "origin/$HEAD..origin/$BASE" 2>/dev/null || echo "0")
if [ "$BEHIND" -gt 20 ]; then
EXISTING=$(gh pr view "$NUMBER" --json labels --jq '.labels[].name' | grep -c "outdated" || true)
if [ "$EXISTING" -eq 0 ]; then
gh pr comment "$NUMBER" --body "This PR is **${BEHIND} commits** behind \`${BASE}\`. Please rebase to avoid merge conflicts."
gh pr edit "$NUMBER" --add-label "outdated" 2>/dev/null || true
fi
else
gh pr edit "$NUMBER" --remove-label "outdated" 2>/dev/null || true
fi
done