Skip to content

Instantly share code, notes, and snippets.

@Julian88Tex
Created May 3, 2023 16:41
Show Gist options
  • Save Julian88Tex/28dc65b85db73a0850a4d1deac5d035b to your computer and use it in GitHub Desktop.
Save Julian88Tex/28dc65b85db73a0850a4d1deac5d035b to your computer and use it in GitHub Desktop.
GitHub Action: Close PRs Opened by github-actions bot
name: Close PRs Opened by github-actions bot
on:
workflow_run:
workflows: [Tests]
types:
- completed
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
close-github-actions-prs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3.3.0
- name: List open pull requests
run: |
gh pr list --json number,author > pr_list.json
cat pr_list.json
- name: Get list of PRs created by github-actions
id: extract_pr_numbers
run: |
PR_NUMBERS=$(jq -r '[ .[] | select(.author.login == "app/github-actions") | .number ] | join(",")' pr_list.json)
echo "PR_NUMBERS=${PR_NUMBERS}" >> $GITHUB_ENV
- name: Close PRs created by github-actions
run: |
IFS=',' read -ra PR_ARRAY <<< "$PR_NUMBERS"
for pr_number in "${PR_ARRAY[@]}"; do
echo "Processing PR #${pr_number}"
gh pr view ${pr_number}
gh pr close ${pr_number}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment