Skip to content

Check old PRs

Check old PRs #959

name: 'Check old PRs'
on:
schedule:
- cron: '0 0 * * *' # run once a day
workflow_dispatch: # enables manual trigger
permissions:
contents: read # required to fetch repository contents
pull-requests: read # required to list PRs and access metadata (via GitHub API or gh CLI)
jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Check PR age
id: check_age
env: # set the GH_TOKEN environment variable here
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Use GitHub API and jq to parse the data
PRS=$(gh api repos/lifinance/contracts/pulls -q '.[] | {number: .number, created_at: .created_at, labels: (.labels | map(.name)), draft: .draft}')
echo "PRs found: $PRS"
OLD_PRS=""
while read -r PR; do
echo "------------------------------------------------------------------"
PR_CREATED_AT=$(echo "$PR" | jq -r '.created_at')
PR_NUMBER=$(echo "$PR" | jq -r '.number')
PR_LABELS=$(echo "$PR" | jq -c '.labels')
PR_ISDRAFT=$(echo "$PR" | jq -r '.draft')
echo "Now checking PR: $PR_NUMBER"
echo "PR is in DRAFT status: $PR_ISDRAFT"
echo "The following labels are assigned to this PR: $PR_LABELS"
# Continue loop if the PR is draft
if [[ "$PR_ISDRAFT" == "true" ]]; then
echo "skipping this PR cause it is in draft mode"
continue
fi
# Continue loop if the PR has the label "WIP"
if echo "$PR_LABELS" | grep -q "WIP"; then
echo "skipping this PR cause it is labeled with 'WIP'"
continue
fi
# Continue loop if the PR has the label "waitForAudit"
if echo "$PR_LABELS" | grep -q "waitForAudit"; then
echo "skipping this PR cause it is labeled with 'waitForAudit'"
continue
fi
# Continue loop if the PR has the label "waitForBackend"
if echo "$PR_LABELS" | grep -q "waitForBackend"; then
echo "skipping this PR cause it is labeled with 'waitForBackend'"
continue
fi
# Convert date to Unix timestamp
PR_CREATED_AT=$(date -d"$PR_CREATED_AT" +%s)
NOW=$(date +%s)
# Calculate age of PR in days
PR_AGE=$(( (NOW - PR_CREATED_AT) / 86400 ))
if (( PR_AGE > 7 )); then
OLD_PRS="${OLD_PRS}PR #$PR_NUMBER is $PR_AGE days old ||"
fi
done <<< "$PRS"
echo -e "$OLD_PRS"
echo "old_prs=$OLD_PRS" >> $GITHUB_ENV
- name: Send Reminder to Slack PR Review Channel
uses: slackapi/[email protected]
with:
webhook: ${{ secrets.SLACK_WEBHOOK_SC_REVIEW }}
webhook-type: incoming-webhook
payload: |
text: "Hey team, please check out the following PRs that are not yet reviewed/merged: ${{ env.old_prs }}"