Skip to content

feat(cli): Add standalone --server and --client modes (#110) #106

feat(cli): Add standalone --server and --client modes (#110)

feat(cli): Add standalone --server and --client modes (#110) #106

name: Stale PR Notifier
on:
push:
branches:
- main
permissions:
pull-requests: write
jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all branches and tags
- name: Get recent commits from main
id: get_commits
run: |
COMMITS=$(git log origin/main --pretty=format:'- %h %s' -n 5)
echo "commits<<EOF" >> $GITHUB_OUTPUT
echo "$COMMITS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Check open PRs and notify if stale
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMITS: ${{ steps.get_commits.outputs.commits }}
run: |
for pr_number in $(gh pr list --state open --json number -q '.[].number'); do
echo "Checking PR number $pr_number"
pr_branch=$(gh pr view $pr_number --json headRefName -q '.headRefName')
git fetch origin $pr_branch
# Check if main is an ancestor of the PR branch. If it is, the PR is up to date.
if git merge-base --is-ancestor origin/main "origin/$pr_branch"; then
echo "PR #$pr_number is up to date."
else
echo "PR #$pr_number is stale. Commenting."
# Check if a "stale" comment already exists to avoid spamming
existing_comment=$(gh pr view $pr_number --json comments -q '.comments[] | select(.body | contains("This PR is out-of-date")) | .id')
if [ -z "$existing_comment" ]; then
# Define the multiline body using a here document to ensure proper expansion and formatting
read -r -d '' BODY <<EOF
⚠️ **This PR is out-of-date with the `main` branch.**
The base branch has been updated with new changes.
**Recent commits to `main`:**
```
$COMMITS
```
To ensure a clean merge, please rebase your branch on top of the latest `main` and push your changes.
EOF
gh pr comment "$pr_number" --body "$BODY"
else
echo "A stale comment already exists on PR #$pr_number. Skipping."
fi
fi
done