Repository navigation
Recover native merge after a lost GitHub reply #1345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1322,7 +1322,7 @@ def mark_ready(repo: str, number: int) -> None: | |
|
|
||
| _QUEUE_QUERY = ( | ||
| "query($owner:String!,$name:String!,$number:Int!){repository(owner:$owner,name:$name)" | ||
| "{pullRequest(number:$number){isInMergeQueue autoMergeRequest{enabledAt}}}}" | ||
| "{pullRequest(number:$number){headRefOid isInMergeQueue autoMergeRequest{enabledAt}}}}" | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -1354,7 +1354,7 @@ def merged_sha( | |
| raise GhError(argv, "PR closed without a verified merge or invalid merge evidence") | ||
|
|
||
|
|
||
| def merge_pending(repo: str, number: int) -> bool: | ||
| def merge_pending(repo: str, number: int, head_sha: str) -> bool: | ||
| """True when GitHub holds the PR for merging: queued, or accepted as an auto-merge | ||
| request that it moves into the queue shortly after (observed ~1 minute, #180).""" | ||
| owner, name = repo.split("/", 1) | ||
|
|
@@ -1373,6 +1373,8 @@ def merge_pending(repo: str, number: int) -> bool: | |
| raise MergeFailed(("gh", "api", "graphql"), | ||
| f"GitHub queue lookup for PR #{number}: queue status could not be verified. " | ||
| f"Check the PR's queue or merge state before retrying.\n{str(exc)[-300:]}") from exc | ||
| if pr.get("headRefOid") != head_sha: | ||
| raise MergeFailed(("gh", *argv), "PR head changed or unavailable during queue verification") | ||
| return queued or bool(auto) | ||
|
|
||
|
|
||
|
|
@@ -1389,16 +1391,19 @@ def merge(repo: str, number: int, strategy: str, head_sha: str) -> str | None: | |
| argv = ( | ||
| "pr", "merge", str(number), "--repo", repo, *method, "--match-head-commit", head_sha, | ||
| ) | ||
| if strategy == "queue" and merge_pending(repo, number, head_sha): | ||
| return None | ||
| write_error = None | ||
| try: | ||
| _gh(*argv, timeout=300) | ||
| except GhError as exc: | ||
| raise MergeFailed(exc.command, exc.tail) from exc | ||
| except (GhError, ProcTimeout, OSError) as exc: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: The write error is dropped when a later verification step raises
Before this change, the user always saw gh's rejection text. Smallest fix: attach |
||
| write_error = exc | ||
| sha = merged_sha(repo, number, expected_head=head_sha) | ||
| if sha: | ||
| return sha | ||
| queue_error = None | ||
| try: | ||
| if merge_pending(repo, number): | ||
| if merge_pending(repo, number, head_sha): | ||
| return None | ||
| except MergeFailed as exc: | ||
| queue_error = exc | ||
|
|
@@ -1408,7 +1413,8 @@ def merge(repo: str, number: int, strategy: str, head_sha: str) -> str | None: | |
| return sha | ||
| if queue_error: | ||
| raise queue_error | ||
| raise MergeFailed(("gh", *argv), f"PR #{number} neither merged nor queued") | ||
| detail = f": {write_error}" if write_error else "" | ||
| raise MergeFailed(("gh", *argv), f"PR #{number} neither merged nor queued{detail}") | ||
|
|
||
|
|
||
| def _remote_branch_head(endpoint: str) -> str | None: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Only the queue strategy checks for admission before writing; squash/merge/rebase retries still send a second write
The check before the write (
if strategy == "queue" and merge_pending(...)) only runs forstrategy == "queue".merge()also treats a squash/merge/rebase request as accepted when GitHub queues it or turns it into an auto-merge request (test_merge_queued_returns_nonewithstrategy=squash, auto=True). Example: a squash request is accepted as auto-merge, the reply is lost, and the run fails or is interrupted before the second read. The retry then sends anothergh pr merge --squash. This retry case is the one the acceptance criterion "a retry observes admission before writing" describes. The second write is usually harmless because the read after it still finds the PR pending, but it is the same defect. Smallest fix: run the admission check for every strategy, which costs one GraphQL read, or explain in a comment why non-queue strategies are excluded. Then add the squash+auto case to the retry assertion intest_merge_queued_returns_none.