Label pull_ready on maintainer approval #122
Workflow file for this run
This file contains hidden or 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: Label pull_ready on maintainer approval | |
| on: | |
| pull_request_review: | |
| types: [submitted] | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| add-label-on-maintainer-approval: | |
| runs-on: ubuntu-latest | |
| if: github.event.review.state == 'approved' | |
| steps: | |
| - name: Check reviewer permissions | |
| id: check_reviewer | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| REVIEWER: ${{ github.event.review.user.login }} | |
| REPO: ${{ github.repository }} | |
| run: | | |
| permission=$(gh api "repos/${REPO}/collaborators/${REVIEWER}/permission" --jq '.permission') | |
| if [[ "$permission" == "admin" || "$permission" == "maintain" || "$permission" == "push" ]]; then | |
| echo "::debug::Reviewer has merge permissions: $permission}" | |
| echo "is_maintainer=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "::debug::Reviewer does not have merge permissions, skipping pull_ready" | |
| echo "is_maintainer=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Add pull_ready label | |
| if: steps.check_reviewer.outputs.is_maintainer == true | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GH_REPO: ${{ github.repository }} | |
| NUMBER: ${{ github.event.pull_request.number }} | |
| LABELS: pull_ready | |
| run: | | |
| if [ -z "$NUMBER" ]; then | |
| echo "Error: PR number not found. Skipping commit fetch." | |
| exit 0 | |
| fi | |
| echo "Fetching commits for PR #$PR_NUMBER..." | |
| # The `gh pr view` command provides a 'commits' field which is the *count* | |
| COMMITS=$(gh pr view "$PR_NUMBER" --json commits --jq '.commits') | |
| if (( COMMITS != 1 )); then | |
| echo "::error::Expected approved PR to have a single commit, but found $commits. google/heir requires a single commit per PR because Google's internal/external synchronization tooling does not support squashing, and instead would rebase all commits into the main branch." | |
| exit 1 | |
| fi | |
| gh issue edit "$NUMBER" --add-label "$LABELS" |