Skip to content

Add workflow to prune stale branches #5

Add workflow to prune stale branches

Add workflow to prune stale branches #5

Workflow file for this run

name: Close stale branches
on:
pull_request:
workflow_dispatch:
schedule:
- cron: '30 1 * * *' # run every day at 01:30 UTC
permissions:
contents: read
jobs:
stale-branches:
runs-on: ubuntu-latest
env:
ORG: nginx
REPO: documentation
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Get all stale branches
run: |
HAS_MORE="true"
echo "Checking for stale branches..."
while [ "$HAS_NAME" == "true" ]; do
# Fetch stale branches
RESPONSE=$(curl -L \
-X GET \
-H "Accept: application/json" \
-s "https://github.com/${{env.ORG}}/${{env.REPO}}/branches/stale")
echo $RESPONSE
HAS_MORE=$(echo "$RESPONSE" | jq -r '.payload.has_more')
BRANCHES=$(echo "$RESPONSE" | jq -r '.payload.branches[].name')
for BRANCH in $BRANCHES; do
REF="heads/$BRANCH"
echo $REF
echo $HAS_MORE
echo $BRANCH
# DELETE_REPONSE=$(curl -L \
# -X DELETE \
# -H "Accept: application/vnd.github+json" \
# -H "Authorization: Bearer ${{env.GITHUB_TOKEN}}" \
# -H "X-GitHub-Api-Version: 2022-11-28" \
# https://api.github.com/repos/${{env.ORG}}/${{env.REPO}}/git/refs/$REF)
done
done