-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathantigravity-code-review.yml
More file actions
121 lines (113 loc) · 5.2 KB
/
Copy pathantigravity-code-review.yml
File metadata and controls
121 lines (113 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# Copy to .github/workflows/antigravity-code-review.yml in your repo.
# NOTE: Do NOT declare a top-level `concurrency:` block in this caller workflow.
# The reusable workflow manages per-PR concurrency internally on its job
# (`group: antigravity-review-<mode>-<PR>`). A top-level `concurrency:` block with a PR-scoped
# group name deadlocks GitHub Actions against the nested `antigravity-review` job
# and cancels the run ([gha#437](https://github.com/Morrison-Lab/gha/issues/437)).
#
# NOTE: Requires GEMINI_API_KEY stored as a GitHub secret. Pass secrets explicitly.
#
# Default: Automatic review on every PR push.
# Optional: Uncomment `issue_comment` below to allow `/antigravity review` or `/review` comments.
name: Antigravity Code Review
on:
pull_request:
types: [opened, synchronize, ready_for_review, reopened]
# Option B (On-Request): Direct on-demand `/review` or `/antigravity review` path.
# issue_comment:
# types: [created]
# Manual dispatch or bot re-dispatch.
workflow_dispatch:
inputs:
pr_number:
description: 'Pull request number to review'
required: true
type: string
mode:
description: 'Operational mode: code-review, security-audit, or test-generation'
required: false
default: 'code-review'
type: choice
options:
- code-review
- security-audit
- test-generation
jobs:
# `/review` or `/antigravity review` comment handler for on-demand requests.
dispatch-on-comment:
if: >-
github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
(startsWith(github.event.comment.body, '/review') || startsWith(github.event.comment.body, '/antigravity review')) &&
contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association)
runs-on: ubuntu-latest
permissions:
actions: write
issues: write
steps:
- name: Parse workflow ref
id: this-wf
uses: Morrison-Lab/gha/.github/actions/parse-workflow-ref@v2
with:
workflow-ref: ${{ github.workflow_ref }}
- name: Dispatch Antigravity Review
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.issue.number }}
WF_PATH: ${{ steps.this-wf.outputs.path }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
COMMENT_BODY: ${{ github.event.comment.body }}
run: |
set -euo pipefail
if [[ ! "$COMMENT_BODY" =~ ^/(review|antigravity[[:space:]]+review)([[:space:]]|$) ]]; then
echo "Comment does not start with a standalone '/review' or '/antigravity review' command; skipping dispatch."
exit 0
fi
WF_FILE=$(basename "$WF_PATH")
PR_JSON=$(gh api "repos/$REPO/pulls/$PR_NUMBER")
PR_BRANCH=$(jq -r '.head.ref' <<< "$PR_JSON")
PR_HEAD_REPO=$(jq -r '.head.repo.full_name' <<< "$PR_JSON")
REF_ARGS=(--ref "$PR_BRANCH")
if [ "$PR_HEAD_REPO" != "$REPO" ]; then
REF_ARGS=()
fi
# Keep this grep in sync with detect-pr-workflow-edits.sh (gha#598).
# GET .../files is capped at 3000 files (GitHub REST "List pull
# requests files", read 2026-08-26). Keep in sync with
# list-pr-changed-files.sh.
changed=$(jq -r '.changed_files' <<< "$PR_JSON")
listed=0
if ! files=$(gh api "repos/$REPO/pulls/$PR_NUMBER/files?per_page=100" --paginate --jq '.[].filename'); then
echo "::notice::Could not list a complete file set for PR #$PR_NUMBER; dispatching $WF_FILE without --ref (gha#598)."
REF_ARGS=()
else
if [ -n "$files" ]; then
listed=$(printf '%s\n' "$files" | grep -c . || true)
fi
if [ -z "$changed" ] || [ "$changed" = "null" ] || ! [[ "$changed" =~ ^[0-9]+$ ]] || [ "$listed" -lt "$changed" ]; then
echo "::notice::Could not list a complete file set for PR #$PR_NUMBER; dispatching $WF_FILE without --ref (gha#598)."
REF_ARGS=()
elif printf '%s\n' "$files" | grep -qE '^\.github/workflows/[^/]+\.ya?ml$'; then
echo "::notice::PR #$PR_NUMBER edits workflow files; dispatching $WF_FILE from the default branch (gha#598)."
REF_ARGS=()
fi
fi
gh workflow run "$WF_FILE" --repo "$REPO" "${REF_ARGS[@]}" -f pr_number="$PR_NUMBER"
gh issue comment "$PR_NUMBER" --repo "$REPO" \
--body ":robot: Dispatched an Antigravity Agent review for PR #$PR_NUMBER (see [run]($RUN_URL))." \
|| echo "::warning::Could not acknowledge comment."
review:
if: github.event_name != 'issue_comment'
permissions:
contents: read
pull-requests: write
issues: write
id-token: write
uses: Morrison-Lab/gha/.github/workflows/antigravity-code-review.yml@v2
with:
mode: ${{ inputs.mode || 'code-review' }}
pr-number: ${{ inputs.pr_number }}
trigger-policy: ${{ github.event_name == 'pull_request' && 'on-push' || 'on-request' }}
secrets:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}