Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions .github/workflows/copilot-auto-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ on:
pull_request_target:
types: [opened, reopened, ready_for_review, synchronize]

permissions:
contents: read
pull-requests: write
permissions: {}

concurrency:
group: copilot-auto-review-${{ github.event.pull_request.number }}
Expand All @@ -22,13 +20,25 @@ jobs:
timeout-minutes: 5

steps:
# pull_request_target supplies a writable token for fork PRs. Do not
# checkout or execute code from the untrusted pull request in this job.
# 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: ${{ github.token }}
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' | \
Expand Down