fix: inline merge+rebase in recovery path (do_merge not yet defined)
do_merge() is defined at line 876, but recovery mode calls it at line ~498. Bash requires functions to be defined before use. Inlined the merge→rebase→re-approve→retry logic directly.
This commit is contained in:
parent
2c527cef4a
commit
0a0d5e8e24
1 changed files with 60 additions and 5 deletions
|
|
@ -493,13 +493,68 @@ ${CHANGE_SUMMARY}
|
||||||
"${API}/commits/$(git -C "$REPO_ROOT" rev-parse "origin/${BRANCH}" 2>/dev/null || echo HEAD)/status" | jq -r '.state // "unknown"')
|
"${API}/commits/$(git -C "$REPO_ROOT" rev-parse "origin/${BRANCH}" 2>/dev/null || echo HEAD)/status" | jq -r '.state // "unknown"')
|
||||||
if [ "${EXISTING_APPROVAL:-0}" -gt 0 ] && [ "$CI_NOW" = "success" ]; then
|
if [ "${EXISTING_APPROVAL:-0}" -gt 0 ] && [ "$CI_NOW" = "success" ]; then
|
||||||
log "PR already approved + CI green — attempting merge"
|
log "PR already approved + CI green — attempting merge"
|
||||||
CURRENT_SHA=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \
|
MERGE_HTTP=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
|
||||||
"${API}/pulls/${PR_NUMBER}" | jq -r '.head.sha')
|
-H "Authorization: token ${CODEBERG_TOKEN}" \
|
||||||
do_merge "$CURRENT_SHA"
|
-H "Content-Type: application/json" \
|
||||||
|
"${API}/pulls/${PR_NUMBER}/merge" \
|
||||||
|
-d '{"Do":"merge","delete_branch_after_merge":true}')
|
||||||
|
if [ "$MERGE_HTTP" = "200" ] || [ "$MERGE_HTTP" = "204" ]; then
|
||||||
|
log "PR #${PR_NUMBER} merged!"
|
||||||
|
notify "✅ PR #${PR_NUMBER} merged! Issue #${ISSUE} done."
|
||||||
|
curl -sf -X PATCH -H "Authorization: token ${CODEBERG_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
"${API}/issues/${ISSUE}" -d '{"state":"closed"}' >/dev/null 2>&1 || true
|
||||||
cleanup_labels
|
cleanup_labels
|
||||||
cleanup_worktree
|
cleanup_worktree
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
# Merge failed — rebase and retry
|
||||||
|
log "merge failed (HTTP ${MERGE_HTTP}) — rebasing"
|
||||||
|
cd "$REPO_ROOT"
|
||||||
|
git fetch origin "${PRIMARY_BRANCH}" "$BRANCH" 2>/dev/null
|
||||||
|
TMP_WT="/tmp/rebase-pr-${PR_NUMBER}"
|
||||||
|
rm -rf "$TMP_WT"
|
||||||
|
if git worktree add "$TMP_WT" "$BRANCH" 2>/dev/null && \
|
||||||
|
(cd "$TMP_WT" && git rebase "origin/${PRIMARY_BRANCH}" 2>&1) && \
|
||||||
|
(cd "$TMP_WT" && git push --force-with-lease origin "$BRANCH" 2>&1); then
|
||||||
|
log "rebased — waiting for CI + re-approval"
|
||||||
|
git worktree remove "$TMP_WT" 2>/dev/null || true
|
||||||
|
NEW_SHA=$(git rev-parse "origin/${BRANCH}" 2>/dev/null || true)
|
||||||
|
# Wait for CI
|
||||||
|
for _r in $(seq 1 20); do
|
||||||
|
_ci=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \
|
||||||
|
"${API}/commits/${NEW_SHA}/status" | jq -r '.state // "unknown"')
|
||||||
|
[ "$_ci" = "success" ] && break
|
||||||
|
sleep 30
|
||||||
|
done
|
||||||
|
# Re-approve (force push dismissed stale approval)
|
||||||
|
curl -sf -X POST -H "Authorization: token ${REVIEW_BOT_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
"${API}/pulls/${PR_NUMBER}/reviews" \
|
||||||
|
-d '{"event":"APPROVED","body":"Auto-approved after rebase."}' >/dev/null 2>&1 || true
|
||||||
|
# Retry merge
|
||||||
|
MERGE_HTTP=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
|
||||||
|
-H "Authorization: token ${CODEBERG_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
"${API}/pulls/${PR_NUMBER}/merge" \
|
||||||
|
-d '{"Do":"merge","delete_branch_after_merge":true}')
|
||||||
|
if [ "$MERGE_HTTP" = "200" ] || [ "$MERGE_HTTP" = "204" ]; then
|
||||||
|
log "PR #${PR_NUMBER} merged after rebase!"
|
||||||
|
notify "✅ PR #${PR_NUMBER} merged! Issue #${ISSUE} done."
|
||||||
|
curl -sf -X PATCH -H "Authorization: token ${CODEBERG_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
"${API}/issues/${ISSUE}" -d '{"state":"closed"}' >/dev/null 2>&1 || true
|
||||||
|
cleanup_labels
|
||||||
|
cleanup_worktree
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
notify "PR #${PR_NUMBER} merge failed after rebase (HTTP ${MERGE_HTTP}). Needs human attention."
|
||||||
|
else
|
||||||
|
git worktree remove --force "$TMP_WT" 2>/dev/null || true
|
||||||
|
notify "PR #${PR_NUMBER} rebase failed. Needs human attention."
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
log "no unaddressed review found — PR exists, entering review loop to wait"
|
log "no unaddressed review found — PR exists, entering review loop to wait"
|
||||||
cd "$REPO_ROOT"
|
cd "$REPO_ROOT"
|
||||||
git fetch origin "$BRANCH" 2>/dev/null
|
git fetch origin "$BRANCH" 2>/dev/null
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue