| # Licensed to the Apache Software Foundation (ASF) under one | |
| # or more contributor license agreements. See the NOTICE file | |
| # distributed with this work for additional information | |
| # regarding copyright ownership. The ASF licenses this file | |
| # to you under the Apache License, Version 2.0 (the | |
| # "License"); you may not use this file except in compliance | |
| # with the License. You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, | |
| # software distributed under the License is distributed on an | |
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| # KIND, either express or implied. See the License for the | |
| # specific language governing permissions and limitations | |
| # under the License. | |
| name: Copilot auto review | |
| on: | |
| pull_request_target: | |
| types: [opened, reopened, ready_for_review, synchronize] | |
| permissions: {} | |
| concurrency: | |
| group: copilot-auto-review-${{ github.event.pull_request.number }} | |
| cancel-in-progress: true | |
| jobs: | |
| request-review: | |
| if: >- | |
| github.event.pull_request.draft == false && | |
| !endsWith(github.event.pull_request.user.login, '[bot]') && | |
| !contains(github.event.pull_request.labels.*.name, 'copilot-skip') | |
| runs-on: ubuntu-24.04 | |
| timeout-minutes: 5 | |
| steps: | |
| # pull_request_target exposes the repository secret to fork PR events. | |
| # Never checkout, execute, or otherwise consume untrusted PR code here. | |
| - name: Request GitHub Copilot review | |
| env: | |
| GH_TOKEN: ${{ secrets.COPILOT_REVIEW_TOKEN }} | |
| EXPECTED_REVIEW_REQUESTER: hqhq1025 | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| run: | | |
| if [[ -z "${GH_TOKEN:-}" ]]; then | |
| echo "::error::COPILOT_REVIEW_TOKEN is not configured" | |
| exit 1 | |
| fi | |
| review_requester="$(gh api user --jq '.login')" | |
| if [[ "${review_requester}" != "${EXPECTED_REVIEW_REQUESTER}" ]]; then | |
| echo "::error::COPILOT_REVIEW_TOKEN belongs to ${review_requester}, expected ${EXPECTED_REVIEW_REQUESTER}" | |
| exit 1 | |
| fi | |
| if gh api \ | |
| "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/requested_reviewers" \ | |
| --jq '.users[].login' | \ | |
| grep -Fxq 'copilot-pull-request-reviewer[bot]'; then | |
| exit 0 | |
| fi | |
| gh api \ | |
| --method POST \ | |
| "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/requested_reviewers" \ | |
| -f 'reviewers[]=copilot-pull-request-reviewer[bot]' |