Skip to content
Open
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
44 changes: 39 additions & 5 deletions .github/workflows/copilot-review-on-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ on:

jobs:
assign-copilot:
if: github.event_name == 'pull_request_target' && github.event.action == 'opened'
# Skip bot-authored PRs (dependabot etc.) here -- tg-autopilot itself is
# a User, not a Bot, so this doesn't affect its own PRs. Draft status is
# checked live inside the step below instead of trusting this event's
# own payload.
if: |
github.event_name == 'pull_request_target' &&
github.event.action == 'opened' &&
github.event.pull_request.user.type != 'Bot'
runs-on: ubuntu-latest
steps:
# Poll rather than check-once -- Copilot can take over a minute to
Expand All @@ -37,9 +44,30 @@ jobs:
run: |
set -euo pipefail

# Draft status re-checked live via a plain API call, not the
# "opened" event's own payload, which can be stale. Retried briefly
# in case of a short read delay right after PR creation.
IS_DRAFT="false"
for attempt in 1 2 3; do
IS_DRAFT=$(curl -s -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/$REPO/pulls/$PR" | grep -oE '"draft":\s*(true|false)' | grep -oE '(true|false)')
[ "$IS_DRAFT" = "true" ] && break
sleep 4
done
if [ "$IS_DRAFT" = "true" ]; then
echo "PR is a draft -- skipping Copilot review request."
exit 0
fi

# curl, not `gh api`, which can serve a cached GET right after our
# own mutation and falsely report "not present yet".
copilot_present() {
gh api "repos/$REPO/pulls/$PR/requested_reviewers" --jq '.users[].login' | grep -qx 'copilot-pull-request-reviewer\[bot\]' && return 0
gh api "repos/$REPO/pulls/$PR/reviews" --jq '.[].user.login' | grep -qx 'copilot-pull-request-reviewer\[bot\]' && return 0
curl -s -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/$REPO/pulls/$PR/requested_reviewers" \
| grep -qE '"login":\s*"copilot-pull-request-reviewer\[bot\]"' && return 0
curl -s -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/$REPO/pulls/$PR/reviews" \
| grep -qE '"login":\s*"copilot-pull-request-reviewer\[bot\]"' && return 0
return 1
}

Expand Down Expand Up @@ -111,9 +139,15 @@ jobs:
PR="${{ github.event.issue.number }}"
REPO="${{ github.repository }}"

# curl, not `gh api`, which can serve a cached GET right after our
# own mutation and falsely report "not present yet".
copilot_present() {
gh api "repos/$REPO/pulls/$PR/requested_reviewers" --jq '.users[].login' | grep -qx 'copilot-pull-request-reviewer\[bot\]' && return 0
gh api "repos/$REPO/pulls/$PR/reviews" --jq '.[].user.login' | grep -qx 'copilot-pull-request-reviewer\[bot\]' && return 0
curl -s -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/$REPO/pulls/$PR/requested_reviewers" \
| grep -qE '"login":\s*"copilot-pull-request-reviewer\[bot\]"' && return 0
curl -s -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/$REPO/pulls/$PR/reviews" \
| grep -qE '"login":\s*"copilot-pull-request-reviewer\[bot\]"' && return 0
return 1
}

Expand Down
Loading