Skip to content

Check old PRs

Check old PRs #452

name: "Check old PRs"
on:
schedule:
- cron: '0 0 * * *' # run once a day
workflow_dispatch: # enables manual trigger
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: |
set -x
# 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: $PRS"
OLD_PRS=""
while read -r PR; do
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')
# Continue loop if the PR is draft
if [[ "$PR_ISDRAFT" == "true" ]]; then
continue
fi
# Continue loop if the PR has the label "WIP"
if echo "$PR_LABELS" | grep -q "WIP"; then
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 Discord message
if: env.old_prs != ''
uses: Ilshidur/[email protected]
with:
args: "Hey team, please check out the following PRs that are not yet reviewed/merged: ${{ env.old_prs }}"
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}