Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion docs/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ GitHub's update-branch API with the observed head as its concurrency guard. It v
result contains both the old head and current base, preserves auto-merge settings, and observes a
fresh PR workflow event. An updated head requires a new current-head review before merge;
existing commits are retained. Current non-Dependabot branches use the reopen route to ensure
App-created drafts receive their required PR CI event.
App-created drafts receive their required PR CI event. A branch that conflicts with the base is
reported and skipped, not counted as a failure: GitHub will not merge it, and the push that
resolves the conflict starts a fresh PR run against the current gates. Only GitHub's settled
verdict (`mergeable: false`, `dirty`) for the head the update tried counts; an unknown verdict or a
moved head is still a failure.

**Forks** use close and immediate reopen, which preserves their head and current-head review.
Every reopen requires a newer PR event and a matching OPEN readback of head, base, author and
Expand Down
37 changes: 36 additions & 1 deletion scripts/recheck-open-prs-base-refresh.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,21 @@ if [[ "$*" == *'/compare/'* ]]; then
fi
if [[ "$*" == *'/update-branch'* ]]; then
[[ "$*" == *'--method PUT'* && "$*" == *"expected_head_sha=$HEAD"* ]] || exit 3
[[ "$MODE" != update-fails ]] || exit 1
[[ "$MODE" != update-fails && "$MODE" != conflict* ]] || { [[ "$MODE" != conflict* ]] || echo "gh: merge conflict between base and head (HTTP 422)" >&2; exit 1; }
[[ "$MODE" != unchanged ]] || exit
printf '%s' "$UPDATED" > "$FIXTURE/current"
exit
fi
if [[ "$*" == *'repos/owner/name/pulls/11 '* ]]; then
case "$MODE" in
conflict) printf '%s\tfalse\tdirty\n' "$HEAD" ;;
conflict-computing) printf '%s\tnull\tunknown\n' "$HEAD" ;;
conflict-moved) printf '%s\tfalse\tdirty\n' "$LATER" ;;
conflict-read-fails) exit 1 ;;
*) printf '%s\ttrue\tbehind\n' "$HEAD" ;;
esac
exit
fi
if [[ "$*" == *'api --paginate'* ]]; then
jq -nc '[[{number:11,title:"wanted update",state:"open",base:{ref:"main",repo:{full_name:"owner/name"}}}]]'
exit
Expand Down Expand Up @@ -157,6 +167,31 @@ run_case wrong-pr 1
run_case retargeted 1
run_case late-movement 1
run_case late-base 1
# A conflicting branch cannot merge, and the push that resolves it re-runs every check, so only
# GitHub's settled conflict verdict for the head this run tried is reported rather than failed.
for mode in conflict conflict-computing conflict-moved conflict-read-fails; do
export MODE="$mode"
rm -f "$work/current" "$work/later-base"
: > "$work/calls"
rc=0
PATH="$work/bin:$PATH" RECHECK_CHECK_WAIT_SECONDS=1 RECHECK_CHECK_POLL_SECONDS=1 \
bash "$here/recheck-open-prs.sh" --repo owner/name > "$work/output" 2>&1 || rc=$?
expected=1
[ "$mode" != conflict ] || expected=0
if [ "$rc" -ne "$expected" ] || grep -Eq '^pr (close|reopen|merge)' "$work/calls" \
|| grep -q '/actions/workflows/ci.yaml/runs' "$work/calls"; then
cat "$work/output"; echo "FAIL $mode: exit $rc"; exit 1
fi
if [ "$mode" = conflict ]; then
grep -q '^ skipped #11 — it conflicts with main' "$work/output"
grep -q '::notice::1 pull request(s) conflict with main' "$work/output"
! grep -q '::error::' "$work/output" || { cat "$work/output"; echo 'FAIL conflict: reported an error'; exit 1; }
else
grep -q '::error::#11 head-checked base update failed' "$work/output"
! grep -q 'skipped #11' "$work/output" || { echo "FAIL $mode: skipped without a settled conflict"; exit 1; }
fi
echo "PASS same-repository $mode"
done
# A current Dependabot branch stays open, but its observed run certifies only that exact head/base.
export HEAD="$updated"
for mode in normal no-check late-movement late-base; do
Expand Down
20 changes: 19 additions & 1 deletion scripts/recheck-open-prs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ rearm() {
# success evidence: read back the new head, verify both ancestors, then observe its PR event.
# Return 3 only for a current non-Dependabot branch that needs the existing reopen route.
refresh_same_repository() {
local n=$1 before=$2 old_head old_base relation current new_head new_base base_path final_base waited=0
local n=$1 before=$2 old_head old_base relation current new_head new_base base_path final_base conflict waited=0
old_head=$(printf '%s' "$before" | jq -r '.headRefOid')
# A PR's associated base OID is not proof of the current named branch tip.
base_path=$(printf '%s' "$base" | jq -sRr @uri)
Expand Down Expand Up @@ -390,6 +390,17 @@ refresh_same_repository() {
*) echo "::error::#$n base ancestry is unknown; left untouched"; return 1 ;;
esac
if ! gh api --method PUT "repos/$repo/pulls/$n/update-branch" -f expected_head_sha="$old_head" > /dev/null; then
# A branch that conflicts with the base cannot be updated, and it cannot merge either:
# GitHub refuses to merge a conflicting pull request, and the push that resolves the
# conflict is a new head whose own `pull_request` event runs every current gate. Its stale
# green therefore cannot reach the base, so it is reported, not counted as a failure. Only
# GitHub's settled verdict about the head this run tried counts: an unknown, still
# computing or moved head stays a failure.
if conflict=$(gh api "repos/$repo/pulls/$n" --jq '[.head.sha, (.mergeable|tostring), .mergeable_state] | @tsv') \
&& [ "$conflict" = "$old_head"$'\tfalse\tdirty' ]; then
echo " skipped #$n — it conflicts with $base, so it cannot merge until a push resolves that, and that push re-runs every required check"
return 4
fi
echo "::error::#$n head-checked base update failed; no close or recreation attempted"
return 1
fi
Expand Down Expand Up @@ -486,6 +497,7 @@ echo "recheck-open-prs: re-triggering required checks on $count open PR(s) targe

failed=0
done_count=0
conflicted=0

while IFS=$'\t' read -r number title; do
[ -n "$number" ] || continue
Expand Down Expand Up @@ -549,6 +561,9 @@ while IFS=$'\t' read -r number title; do
if [ "$refresh_status" -eq 0 ]; then
done_count=$((done_count + 1))
continue
elif [ "$refresh_status" -eq 4 ]; then
conflicted=$((conflicted + 1))
continue
elif [ "$refresh_status" -ne 3 ]; then
failed=$((failed + 1))
continue
Expand Down Expand Up @@ -633,6 +648,9 @@ while IFS=$'\t' read -r number title; do
done < <(printf '%s\n' "$prs")

echo "recheck-open-prs: $done_count of $count current-base refreshes completed"
if [ "$conflicted" -gt 0 ]; then
echo "::notice::$conflicted pull request(s) conflict with $base and were not refreshed; they cannot merge until a push resolves the conflict, which re-runs their checks"
fi
if [ "$failed" -gt 0 ]; then
echo "::error::$failed pull request(s) could not be re-triggered; their required checks are still the pre-gate result"
exit 1
Expand Down
Loading