You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* fix: harden sdk auto-review gate
deny paths now clear stale auto-merge before commenting and fail the
step if the disable errors, instead of best-effort || true. an empty
changed-files listing no longer counts as an allowlist pass. renames
are checked on both sides everywhere. approvals are pinned to the
head commit.
* fix: close validate-then-approve race in auto-review
pin the approval to the head captured before the allowlist run, then
re-read the head after submitting; if it moved, dismiss the approval
and deny. dismiss_stale_reviews (now enabled) covers pushes after the
review; this covers the window before it.
* fix: make review dismissal best-effort ahead of deny
a dismiss failure under set -e must not skip deny, which is the hard
gate that clears stale auto-merge. dismiss_stale_reviews already
covers the dismissal in the normal case.
echo "No open PR for $BRANCH; nothing to approve."
160
176
exit 0
161
177
fi
178
+
pr=$(echo "$pr_json" | jq -r .number)
179
+
base=$(echo "$pr_json" | jq -r .baseRefName)
180
+
head_sha=$(echo "$pr_json" | jq -r .headRefOid)
181
+
182
+
if [ "$base" != "main" ]; then
183
+
echo "Not approving PR #$pr: base is $base, not main."
184
+
deny "SDK reviewer app: not auto-approving; the PR base is \`$base\`, not \`main\`. Left for human review (policy: fail open to human review, never to merge)."
185
+
fi
162
186
163
187
# Only regen PRs authored by the bot app qualify for auto-review.
164
188
# REST is used because it returns the stable "convoy-sdk-bot[bot]"
165
189
# login for app-authored PRs.
166
190
author=$(GH_TOKEN="$APP_TOKEN" gh api "repos/$GH_REPO/pulls/$pr" --jq '.user.login')
167
191
if [ "$author" != "convoy-sdk-bot[bot]" ]; then
168
192
echo "Not approving PR #$pr: author is $author, not convoy-sdk-bot[bot]."
169
-
GH_TOKEN="$APP_TOKEN" gh pr comment "$pr" --body "SDK reviewer app: not auto-approving; PR author is not convoy-sdk-bot[bot]. Left for human review (policy: fail open to human review, never to merge)."
170
-
exit 0
193
+
deny "SDK reviewer app: not auto-approving; PR author is not convoy-sdk-bot[bot]. Left for human review (policy: fail open to human review, never to merge)."
194
+
fi
195
+
196
+
# Bind the approval to the commit this run pushed; a concurrent
197
+
# push to the regen branch means the diff is no longer this run's
198
+
# generated output.
199
+
pushed_sha=$(git rev-parse HEAD)
200
+
if [ "$head_sha" != "$pushed_sha" ]; then
201
+
echo "Not approving PR #$pr: head $head_sha is not the commit this run pushed."
202
+
deny "SDK reviewer app: not auto-approving; the PR head is not the commit this generation run pushed. Left for human review (policy: fail open to human review, never to merge)."
203
+
fi
204
+
205
+
# This run committed a real diff, so an empty changed-files listing
206
+
# is an API anomaly, not a clean PR; it must not count as an
207
+
# allowlist pass.
208
+
files=$(GH_TOKEN="$APP_TOKEN" gh api "repos/$GH_REPO/pulls/$pr/files" --paginate \
echo "Not approving PR #$pr: changed-files listing came back empty."
212
+
deny "SDK reviewer app: not auto-approving; the changed-files listing came back empty for a non-empty regen commit. Left for human review (policy: fail open to human review, never to merge)."
171
213
fi
172
214
173
-
# The head branch is the regen branch this run pushed, so the
174
-
# branch condition holds by construction of the lookup above.
175
215
# Allowlist mirrors scripts/generate.sh: only the api, client, and
176
-
# models packages are generated; webhook/ is hand-written.
177
-
bad=$(GH_TOKEN="$APP_TOKEN" gh api "repos/$GH_REPO/pulls/$pr/files" --paginate --jq '.[].filename' \
216
+
# models packages are generated; webhook/ is hand-written. Renames
217
+
# are checked on both sides so a file cannot be moved into the
echo "Head moved from $head_sha to $now_sha during approval; dismissing review."
251
+
# Best-effort: dismiss_stale_reviews normally dismissed this
252
+
# approval already when the head moved. The hard gate is deny
253
+
# below, which clears auto-merge or fails the step; a dismiss
254
+
# error must not skip it.
255
+
GH_TOKEN="$APP_TOKEN" gh api -X PUT "repos/$GH_REPO/pulls/$pr/reviews/$review_id/dismissals" \
256
+
-f message="Head moved during approval; the approved commit is no longer the PR head." \
257
+
-f event=DISMISS || true
258
+
deny "SDK reviewer app: approval dismissed; the PR head changed while the review was being submitted. Left for human review (policy: fail open to human review, never to merge)."
259
+
fi
204
260
261
+
# Post-validation head drift is closed by branch protection, not
262
+
# here: the approval is pinned to the validated commit_id and
263
+
# dismiss_stale_reviews dismisses it on any later push, so
0 commit comments