Skip to content

Commit a4b4ba3

Browse files
authored
ci: run Argus review from trusted PR target (#865)
* ci: run Argus review from trusted PR target * ci: avoid PR git objects in Argus target workflow
1 parent 3c312a0 commit a4b4ba3

1 file changed

Lines changed: 8 additions & 81 deletions

File tree

.github/workflows/ai-review.yml

Lines changed: 8 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ name: AI PR Review (Argus)
1818
# Ported from adcontextprotocol/adcp's Argus workflow.
1919

2020
on:
21-
pull_request:
21+
pull_request_target:
2222
types:
2323
- opened
2424
- labeled
@@ -38,9 +38,14 @@ jobs:
3838
pull-requests: write
3939
id-token: write
4040
steps:
41+
# pull_request_target runs with base-repo secrets, so keep the
42+
# workspace on trusted base code. Argus reads the untrusted PR via
43+
# GitHub APIs (`gh pr diff/view`) and never checks out or executes it.
4144
- uses: actions/checkout@v6
4245
with:
46+
ref: ${{ github.event.pull_request.base.sha }}
4347
fetch-depth: 0
48+
persist-credentials: false
4449

4550
# ─────────────────────────────────────────────────────────────────────
4651
# Mint an installation token from the AAO release/triage GitHub App.
@@ -54,84 +59,7 @@ jobs:
5459
app-id: ${{ secrets.IPR_APP_ID }}
5560
private-key: ${{ secrets.IPR_APP_PRIVATE_KEY }}
5661

57-
# ─────────────────────────────────────────────────────────────────────
58-
# Skip re-runs on `synchronize` when the last bot review on this PR
59-
# was APPROVED and the new commits only touch trivial paths (docs,
60-
# tests, generated files). Cuts thrash on rebases and docs/test
61-
# follow-up pushes. Force-pushes fall back to full review because
62-
# the prior SHA may be unreachable.
63-
# ─────────────────────────────────────────────────────────────────────
64-
- name: Check for skippable re-run
65-
id: skip-check
66-
if: github.event.action == 'synchronize'
67-
continue-on-error: true
68-
shell: bash
69-
env:
70-
GH_TOKEN: ${{ steps.app-token.outputs.token }}
71-
PR_NUMBER: ${{ github.event.pull_request.number }}
72-
REPO: ${{ github.repository }}
73-
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
74-
run: |
75-
set -euo pipefail
76-
LATEST_APPROVED="$(gh api "/repos/${REPO}/pulls/${PR_NUMBER}/reviews" \
77-
--jq '[.[] | select(.user.type == "Bot" and .state == "APPROVED")] | sort_by(.submitted_at) | last // {}')"
78-
PRIOR_SHA="$(echo "$LATEST_APPROVED" | jq -r '.commit_id // ""')"
79-
if [ -z "$PRIOR_SHA" ]; then
80-
echo "skip=false" >> "$GITHUB_OUTPUT"
81-
echo "No prior bot APPROVED review — running full review."
82-
exit 0
83-
fi
84-
if ! git cat-file -e "$PRIOR_SHA" 2>/dev/null; then
85-
git fetch --quiet origin "$PRIOR_SHA" 2>/dev/null || true
86-
fi
87-
if ! git cat-file -e "$PRIOR_SHA" 2>/dev/null; then
88-
echo "skip=false" >> "$GITHUB_OUTPUT"
89-
echo "Prior review SHA $PRIOR_SHA unreachable (likely force-pushed) — running full review."
90-
exit 0
91-
fi
92-
CHANGED="$(git diff --name-only "$PRIOR_SHA" "$HEAD_SHA")"
93-
if [ -z "$CHANGED" ]; then
94-
echo "skip=true" >> "$GITHUB_OUTPUT"
95-
echo "No file changes since prior approval at $PRIOR_SHA — skipping."
96-
exit 0
97-
fi
98-
# Trivial paths in adcp-client-python — re-pushes touching only these
99-
# skip re-review. Source under src/adcp/ (excluding generated_poc) is
100-
# NEVER trivial.
101-
is_trivial() {
102-
case "$1" in
103-
*.md|*.mdx) return 0 ;;
104-
docs/*) return 0 ;;
105-
examples/*) return 0 ;;
106-
src/adcp/types/generated_poc/*) return 0 ;;
107-
src/adcp/types/_generated.py) return 0 ;;
108-
tests/*) return 0 ;;
109-
test_*.py|*_test.py) return 0 ;;
110-
CHANGELOG.md) return 0 ;;
111-
schemas/*) return 0 ;;
112-
llms.txt) return 0 ;;
113-
esac
114-
return 1
115-
}
116-
NON_TRIVIAL=""
117-
while IFS= read -r f; do
118-
[ -z "$f" ] && continue
119-
if ! is_trivial "$f"; then
120-
NON_TRIVIAL="${NON_TRIVIAL}${f}"$'\n'
121-
fi
122-
done <<< "$CHANGED"
123-
if [ -z "$NON_TRIVIAL" ]; then
124-
echo "skip=true" >> "$GITHUB_OUTPUT"
125-
echo "All changes since $PRIOR_SHA are trivial — skipping re-review. Changed files:"
126-
echo "$CHANGED"
127-
else
128-
echo "skip=false" >> "$GITHUB_OUTPUT"
129-
echo "Non-trivial changes since $PRIOR_SHA — running full review:"
130-
echo "$NON_TRIVIAL"
131-
fi
132-
13362
- name: Build Argus review prompt
134-
if: steps.skip-check.outputs.skip != 'true'
13563
id: build-prompt
13664
shell: bash
13765
env:
@@ -157,7 +85,6 @@ jobs:
15785
15886
- name: Run Argus PR Review
15987
id: ai-review
160-
if: steps.skip-check.outputs.skip != 'true'
16188
continue-on-error: true
16289
uses: anthropics/claude-code-action@v1
16390
with:
@@ -173,7 +100,7 @@ jobs:
173100
174101
- name: Verify Argus posted a review
175102
id: verify
176-
if: always() && steps.app-token.outcome == 'success' && steps.skip-check.outputs.skip != 'true'
103+
if: always() && steps.app-token.outcome == 'success'
177104
shell: bash
178105
env:
179106
GH_TOKEN: ${{ steps.app-token.outputs.token }}
@@ -203,7 +130,7 @@ jobs:
203130
echo "review_state=$STATE" >> "$GITHUB_OUTPUT"
204131
205132
- name: Comment on PR if Argus review failed
206-
if: steps.skip-check.outputs.skip != 'true' && (steps.ai-review.outcome == 'failure' || steps.verify.outputs.review_posted != 'true')
133+
if: steps.ai-review.outcome == 'failure' || steps.verify.outputs.review_posted != 'true'
207134
uses: actions/github-script@v8
208135
env:
209136
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}

0 commit comments

Comments
 (0)