fix: surface skipped tracker cleanup on merge read-back failure (#98)
gitea_merge_pr ran cleanup_in_progress_for_pr inside the same try as the post-merge read-back GET; a read-back failure silently skipped tracker cleanup, leaving only merge_commit=null and no cleanup_status at all, so status:in-progress could stay stuck while the merge read as full success. Split the block: read-back failure now returns an explicit cleanup_status='skipped (merge read-back failed)', and an unexpected cleanup exception returns 'skipped (cleanup error: <redacted>)' instead of masking merge_commit. Cleanup still never blocks a performed merge, the happy-path API call sequence is unchanged, and _redact keeps credentials out of surfaced errors. Add regression tests: read-back failure => merge still performed, explicit skip status, no tracker DELETE traffic; cleanup exception => surfaced and redacted. Fixes #98. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+17
-3
@@ -1098,16 +1098,30 @@ def gitea_merge_pr(
|
||||
payload["MergeMessageField"] = message
|
||||
api_request("POST", merge_url, auth, payload)
|
||||
# Best-effort read-back of the merge commit SHA (redacted on error).
|
||||
merged = None
|
||||
try:
|
||||
merged = api_request(
|
||||
"GET", f"{repo_api_url(h, o, r)}/pulls/{pr_number}", auth
|
||||
)
|
||||
result["merge_commit"] = (merged or {}).get("merged_commit_sha")
|
||||
|
||||
cleanup = cleanup_in_progress_for_pr(merged or {}, remote, host, org, repo)
|
||||
result["cleanup_status"] = cleanup.get("cleanup_status")
|
||||
except Exception:
|
||||
result["merge_commit"] = None
|
||||
|
||||
# Tracker cleanup (#98): never blocks the merge, and always surfaces an
|
||||
# explicit cleanup_status once the merge mutation has happened. Cleanup
|
||||
# needs the PR title/body/branch, which only the read-back payload
|
||||
# carries here — so a failed read-back is an explicit skip, not a
|
||||
# silent one.
|
||||
if merged is None:
|
||||
result["cleanup_status"] = "skipped (merge read-back failed)"
|
||||
else:
|
||||
try:
|
||||
cleanup = cleanup_in_progress_for_pr(merged, remote, host, org, repo)
|
||||
result["cleanup_status"] = cleanup.get("cleanup_status")
|
||||
except Exception as cleanup_exc: # noqa: BLE001 — redact before surfacing
|
||||
result["cleanup_status"] = (
|
||||
f"skipped (cleanup error: {_redact(str(cleanup_exc))})"
|
||||
)
|
||||
except Exception as exc: # noqa: BLE001 — redact before surfacing
|
||||
reasons.append(f"merge failed: {_redact(str(exc))}")
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user