Skip to content

Bulk Approve Please #65

Bulk Approve Please

Bulk Approve Please #65

name: Bulk Approve Please
on:
workflow_dispatch:
inputs:
assignee:
type: choice
description: PR must be created by and assigned to
required: true
options:
- hedia-bot
- hedia-bot-limited
team-reviewer:
type: choice
description: PR must be reviewed by
required: true
options:
- backend
- bots
- development
- mobile
label:
type: choice
description: PR must have label
required: true
default: deps
options:
- build
- chore
- ci
- deps
- docs
- style
- test
title:
type: choice
description: PR title must match
required: true
options:
- "deps: update dependencies"
action:
type: choice
description: Action to perform
required: true
default: Search PRs
options:
- Approve PRs
- Search PRs
jobs:
bulk-approve-please:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: ${{ inputs.action }}
run: |
urls=$(gh search prs --limit 100 --owner hedia-team --review none --state open --author ${{ inputs.assignee }} --assignee ${{ inputs.assignee }} --review-requested hedia-team/${{ inputs.team-reviewer }} --label ${{ inputs.label }} --match title "${{ inputs.title }}" --json url --jq '.[] | .url')
if [ -z "$urls" ]; then
echo "No PRs found." && exit 0
fi
echo "Found $(echo "$urls" | wc -l) potential PRs"
echo " "
echo "Validating PRs for check status ..."
actionable_urls=()
inactionable_urls=()
for url in $urls
do
echo "Checking $url for check status ..."
pending_checks=$(gh pr checks $url --json state --jq '.[].state' | grep -v 'SUCCESS' | grep -v 'SKIPPED' || true)
if [ -z "$pending_checks" ]; then
actionable_urls+=($url)
else
inactionable_urls+=($url)
fi
done
if [ ${#actionable_urls[@]} -eq 0 ]; then
echo " "
echo "No PRs can be approved."
else
echo " "
echo "Number of PRs that can be approved: ${#actionable_urls[@]}"
for url in "${actionable_urls[@]}"
do
echo "* $url"
done
if [ "${{ inputs.action }}" == "Approve PRs" ]; then
echo " "
echo "Approving PRs ..."
body=":technologist: @${{ github.actor }} approved this PR using [bulk-approve-please](https://github.com/hedia-team/.github/actions/workflows/bulk-approve-please.yml) :robot:"
for url in "${actionable_urls[@]}"
do
gh pr review --approve --body "$body" $url
echo "Approved $url"
done
fi
fi
if [ ${#inactionable_urls[@]} -ne 0 ]; then
echo " "
echo "Number of PRs that cannot be approved: ${#inactionable_urls[@]}"
for url in "${inactionable_urls[@]}"
do
echo "* $url"
done
fi
env:
GH_TOKEN: ${{ inputs.assignee == 'hedia-bot' && secrets.HEDIA_BOT_LIMITED_GITHUB_PAT || secrets.HEDIA_BOT_GITHUB_PAT }}