fix: reconcile ambiguous merge outcomes (#277)
This commit is contained in:
1 parent
e0543b2007
commit
e58808f2d4
5 files changed
+168
-3
No files matched your search
@@ -1470,6 +1470,21 @@ async def pull_completion_review(repository: str, number: int) -> dict:
|
||||
}
|
||||
|
||||
|
||||
async def is_pull_merged_at_head(
|
||||
repository: str, number: int, expected_head_sha: str
|
||||
) -> bool:
|
||||
pull = await fetch(f"repos/{repository}/pulls/{number}")
|
||||
if not isinstance(pull, dict):
|
||||
return False
|
||||
head_value = pull.get("head")
|
||||
head = head_value if isinstance(head_value, dict) else {}
|
||||
return (
|
||||
pull.get("merged") is True
|
||||
and pull.get("state") == "closed"
|
||||
and head.get("sha") == expected_head_sha
|
||||
)
|
||||
|
||||
|
||||
async def merge_assigned_pull(
|
||||
repository: str, number: int, expected_head_sha: str
|
||||
) -> dict:
|
||||
|
||||
+19
-2
@@ -2068,9 +2068,26 @@ async def merge_assigned_pull(
|
||||
status_code=409,
|
||||
)
|
||||
except Exception:
|
||||
try:
|
||||
merged = await asyncio.wait_for(
|
||||
gitea_proxy.is_pull_merged_at_head(
|
||||
repository, number, submission.expected_head_sha
|
||||
),
|
||||
timeout=ISSUE_ACTION_TIMEOUT_SECONDS,
|
||||
)
|
||||
except Exception:
|
||||
merged = False
|
||||
if merged:
|
||||
return {"number": number, "merged": True, "state": "closed"}
|
||||
return JSONResponse(
|
||||
{"error": "The pull request could not be merged. It remains in My Work; please retry."},
|
||||
status_code=503,
|
||||
{
|
||||
"number": number,
|
||||
"merged": False,
|
||||
"state": "unknown",
|
||||
"confirmation_pending": True,
|
||||
"error": "Merge confirmation is pending. Check its status before retrying.",
|
||||
},
|
||||
status_code=202,
|
||||
headers={"Retry-After": "1"},
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user