Skip to content

.github/workflows/cron-stale-prs.yml #222

.github/workflows/cron-stale-prs.yml

.github/workflows/cron-stale-prs.yml #222

on:
schedule:
- cron: '0 8 * * *'
workflow_dispatch:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
jobs:
find_stale_prs:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- shell: bash
run: |
stale_prs=$(gh pr list -R "$OWNER/$REPO" --json url,updatedAt,title,state,number,mergeable,labels,id,createdAt,author -L 1000 -s open -q '.|sort_by(.author.login)|.[]|(now - (.updatedAt|fromdate)) as $u|select(.state=="OPEN" and (.labels[].name|contains("merge")) and $u>86400)|{url:.url, author: .author.login, title: .title, updated: .updatedAt, u: $u, number: .number}' | jq -c .)
if [[ "$stale_prs" != "" ]]; then
while IFS= read -r line; do
echo "Stale PR: $line"
prNum=$(echo "$line" | jq -r .number)
prOpener=$(echo "$line" | jq -r .author)
gh pr comment -R "$OWNER/$REPO" $prNum -b "@${prOpener} - This PR appears to be stuck. It's had a merge label for > 24 hours"
done <<< "$stale_prs"
echo "detected stale PRs"
exit 1
else
echo "no stale PRs detected"
exit 0
fi
- name: notify on failure
if: failure()
uses: ./.github/actions/notify-status
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
from: ${{ secrets.NOTIFY_EMAIL_FROM }}
to: ${{ secrets.NOTIFY_EMAIL_TO }}
password: ${{ secrets.NOTIFY_EMAIL_PASSWORD }}