[ENG-895] Migrate batch API callers to the useBatchRequest hook #22974
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: Assign Labels | |
| on: | |
| pull_request_target: | |
| types: | |
| - opened | |
| - converted_to_draft | |
| - ready_for_review | |
| - assigned | |
| - unassigned | |
| - review_requested | |
| workflow_run: | |
| workflows: ["PR Review Trigger"] | |
| types: | |
| - completed | |
| permissions: | |
| contents: read | |
| issues: write | |
| pull-requests: write | |
| actions: read | |
| jobs: | |
| assign-pr: | |
| runs-on: ubuntu-24.04-arm | |
| # Only run for pull_request_target events and skip PRs created by bots | |
| if: >- | |
| github.event_name == 'pull_request_target' && | |
| github.event.pull_request.user.type != 'Bot' | |
| steps: | |
| - name: Generate token | |
| id: generate-token | |
| uses: actions/create-github-app-token@v2 | |
| with: | |
| app-id: ${{ secrets.APP_ID }} | |
| private-key: ${{ secrets.APP_PEM }} | |
| - name: Assign PR Author | |
| env: | |
| GH_TOKEN: ${{ steps.generate-token.outputs.token }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| AUTHOR: ${{ github.event.pull_request.user.login }} | |
| REPO: ${{ github.repository }} | |
| run: | | |
| gh api --method POST repos/$REPO/issues/$PR_NUMBER/assignees -f assignees[]="$AUTHOR" || echo "Warning: Could not assign $AUTHOR" | |
| - name: Update PR Status and Labels | |
| env: | |
| GH_TOKEN: ${{ steps.generate-token.outputs.token }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| IS_DRAFT: ${{ github.event.pull_request.draft }} | |
| REPO: ${{ github.repository }} | |
| run: | | |
| if [[ "${{ github.event.action }}" == "opened" || "${{ github.event.action }}" == "ready_for_review" || "${{ github.event.action }}" == "converted_to_draft" ]]; then | |
| if [[ "$IS_DRAFT" == "true" ]]; then | |
| gh pr edit $PR_NUMBER --remove-label "needs testing" --repo $REPO 2>/dev/null || true | |
| gh pr edit $PR_NUMBER --remove-label "needs review" --repo $REPO 2>/dev/null || true | |
| gh pr edit $PR_NUMBER --add-label "work in progress" --repo $REPO | |
| else | |
| gh pr edit $PR_NUMBER --remove-label "work in progress" --repo $REPO 2>/dev/null || true | |
| gh pr edit $PR_NUMBER --add-label "needs testing" --repo $REPO | |
| gh pr edit $PR_NUMBER --add-label "needs review" --repo $REPO | |
| fi | |
| fi | |
| - name: Handle Review Re-Request | |
| if: github.event.action == 'review_requested' && github.event.requested_reviewer.type != 'Bot' | |
| env: | |
| GH_TOKEN: ${{ steps.generate-token.outputs.token }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| REPO: ${{ github.repository }} | |
| run: | | |
| CURRENT_LABELS=$(gh pr view $PR_NUMBER --repo $REPO --json labels --jq '.labels[].name') | |
| HAS_TESTED=$(echo "$CURRENT_LABELS" | grep -x "Tested" || echo "") | |
| HAS_NEEDS_TESTING=$(echo "$CURRENT_LABELS" | grep -x "needs testing" || echo "") | |
| HAS_NEEDS_REVIEW=$(echo "$CURRENT_LABELS" | grep -x "needs review" || echo "") | |
| gh pr edit $PR_NUMBER --remove-label "changes required" --repo $REPO 2>/dev/null || true | |
| if [[ -z "$HAS_TESTED" && -z "$HAS_NEEDS_TESTING" ]]; then | |
| gh pr edit $PR_NUMBER --add-label "needs testing" --repo $REPO | |
| fi | |
| if [[ -z "$HAS_NEEDS_REVIEW" ]]; then | |
| gh pr edit $PR_NUMBER --add-label "needs review" --repo $REPO | |
| fi | |
| handle-review: | |
| runs-on: ubuntu-24.04-arm | |
| # Only run for workflow_run events from the PR Review Trigger workflow | |
| if: >- | |
| github.event_name == 'workflow_run' && | |
| github.event.workflow_run.conclusion == 'success' | |
| steps: | |
| - name: Check for review artifact | |
| id: check-artifact | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| ARTIFACT_NAME=$(gh api "repos/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}/artifacts" \ | |
| --jq '.artifacts[] | select(.name == "review-info") | .name') | |
| if [[ -n "$ARTIFACT_NAME" ]]; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| echo "No review-info artifact found — expected for non-changes_requested reviews" | |
| fi | |
| - name: Download review info | |
| if: steps.check-artifact.outputs.exists == 'true' | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: review-info | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| run-id: ${{ github.event.workflow_run.id }} | |
| - name: Read and validate review info | |
| if: steps.check-artifact.outputs.exists == 'true' | |
| id: review | |
| run: | | |
| PR_NUMBER=$(cat pr_number.txt) | |
| REVIEW_STATE=$(cat review_state.txt) | |
| if ! [[ "$PR_NUMBER" =~ ^[0-9]+$ ]]; then | |
| echo "::error::Invalid PR number: $PR_NUMBER" | |
| exit 1 | |
| fi | |
| if [[ "$REVIEW_STATE" != "changes_requested" && "$REVIEW_STATE" != "approved" && "$REVIEW_STATE" != "commented" && "$REVIEW_STATE" != "dismissed" ]]; then | |
| echo "::error::Invalid review state: $REVIEW_STATE" | |
| exit 1 | |
| fi | |
| echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT | |
| echo "review_state=$REVIEW_STATE" >> $GITHUB_OUTPUT | |
| - name: Generate token | |
| if: steps.check-artifact.outputs.exists == 'true' && steps.review.outputs.review_state == 'changes_requested' | |
| id: generate-token | |
| uses: actions/create-github-app-token@v2 | |
| with: | |
| app-id: ${{ secrets.APP_ID }} | |
| private-key: ${{ secrets.APP_PEM }} | |
| - name: Handle Review Changes Requested | |
| if: steps.check-artifact.outputs.exists == 'true' && steps.review.outputs.review_state == 'changes_requested' | |
| env: | |
| GH_TOKEN: ${{ steps.generate-token.outputs.token }} | |
| PR_NUMBER: ${{ steps.review.outputs.pr_number }} | |
| REPO: ${{ github.repository }} | |
| run: | | |
| gh pr edit $PR_NUMBER --remove-label "needs review" --repo $REPO 2>/dev/null || true | |
| gh pr edit $PR_NUMBER --remove-label "needs testing" --repo $REPO 2>/dev/null || true | |
| gh pr edit $PR_NUMBER --add-label "changes required" --repo $REPO |