Skip to content

Commit 2fc7b65

Browse files
authored
Limit pull request event types for AI Review
1 parent 2b6e989 commit 2fc7b65

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

.github/workflows/ai-review.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: AI Review
2+
3+
on:
4+
pull_request:
5+
types: [opened]
6+
7+
permissions:
8+
pull-requests: write
9+
contents: read
10+
11+
jobs:
12+
ai-review:
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 5
15+
steps:
16+
- name: Send signed webhook
17+
env:
18+
RUNNER_URL: ${{ secrets.RUNNER_URL }}
19+
RUNNER_HMAC_SECRET: ${{ secrets.RUNNER_HMAC_SECRET }}
20+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
shell: bash
22+
run: |
23+
set -euo pipefail
24+
REPO="${GITHUB_REPOSITORY}"
25+
PR_NUMBER="${{ github.event.pull_request.number }}"
26+
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
27+
TS="$(date +%s)"
28+
29+
# Build payload — keep this single-line JSON; the runner verifies HMAC over
30+
# `<ts>.<rawBody>` byte-for-byte.
31+
BODY="$(jq -nc \
32+
--arg repo "${REPO}" \
33+
--argjson pr ${PR_NUMBER} \
34+
--arg sha "${HEAD_SHA}" \
35+
--arg tok "${GH_TOKEN}" \
36+
--argjson ts ${TS} \
37+
'{repo: $repo, pr_number: $pr, head_sha: $sha, gh_token: $tok, ts: $ts}')"
38+
39+
# X-Signature = sha256= + HMAC( "<ts>." + BODY )
40+
SIG="sha256=$(printf '%s.%s' "${TS}" "${BODY}" \
41+
| openssl dgst -sha256 -hmac "${RUNNER_HMAC_SECRET}" -hex \
42+
| awk '{print $2}')"
43+
44+
# POST and capture status; fail the workflow on >= 400 from the runner.
45+
HTTP_CODE=$(curl -sS -o /tmp/resp.json -w '%{http_code}' \
46+
-X POST "${RUNNER_URL}" \
47+
-H "Content-Type: application/json" \
48+
-H "X-Signature: ${SIG}" \
49+
-H "X-Timestamp: ${TS}" \
50+
--data-raw "${BODY}")
51+
echo "runner http: ${HTTP_CODE}"
52+
cat /tmp/resp.json || true
53+
if [ "${HTTP_CODE}" -ge 400 ]; then
54+
echo "::error::Runner returned ${HTTP_CODE}"
55+
exit 1
56+
fi

0 commit comments

Comments
 (0)