Approve Please #23
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 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 | |
label: | |
type: choice | |
description: PR must have label | |
required: true | |
default: chore | |
options: | |
- build | |
- chore | |
- ci | |
- docs | |
- style | |
- test | |
title: | |
type: choice | |
description: PR title must match | |
required: true | |
options: | |
- "chore(deps): update dependencies" | |
action: | |
type: choice | |
description: Action to perform | |
required: true | |
default: Search PRs | |
options: | |
- Approve PRs | |
- Search PRs | |
jobs: | |
approve-please: | |
runs-on: ubuntu-latest | |
timeout-minutes: 5 | |
steps: | |
- name: ${{ inputs.action }} | |
run: | | |
urls=$(gh search prs --limit 1000 --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 | |
${{ inputs.action == 'Approve PRs' && 'echo "Approving $(echo "$urls" | wc -l) PRs:"' || 'echo "Found $(echo "$urls" | wc -l) PRs:"' }} | |
body=":technologist: @${{ github.actor }} approved this PR using [approve-please](https://github.com/hedia-team/.github/actions/workflows/approve-please.yml) :robot:" | |
for url in ${urls//,/ } | |
do | |
echo "> $url" | |
pending_checks=$(gh pr view $url --json statusCheckRollup --jq '.statusCheckRollup[].conclusion' | grep -v 'SUCCESS') | |
if [ -z "$pending_checks" ]; then | |
if [ "${{ inputs.action }}" == "Approve PRs" ]; then | |
gh pr review --approve --body "$body" $url | |
fi | |
else | |
echo "Not all checks have completed successfully for PR $url" | |
fi | |
done | |
env: | |
GH_TOKEN: ${{ inputs.assignee == 'hedia-bot' && secrets.HEDIA_BOT_LIMITED_GITHUB_PAT || secrets.HEDIA_BOT_GITHUB_PAT }} |