Repository navigation
Share the pending mergeability verdict with hosted eligibility #1759
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
f61c323
8a97532
1defab2
12d2ec8
8e95c45
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 |
|---|---|---|
|
|
@@ -62,6 +62,19 @@ def _candidate_event(event: dict, head: str) -> bool: | |
| return True | ||
|
|
||
|
|
||
| def _source_status(result: github.Readiness, current: github.PR) -> tuple[str, str]: | ||
|
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: Mergeability re-check is duplicated between
|
||
| reasons = result.reasons | ||
| if result.ready: | ||
| if not (blocker := github.mergeability_blocker(current)): | ||
| return "success", "Reviewed source head" | ||
| reasons = (blocker,) | ||
| if reasons and set(reasons) <= {github.MISSING_REVIEW_REASON, github.MERGEABILITY_PENDING}: | ||
| if github.MISSING_REVIEW_REASON in reasons: | ||
| return "pending", "Awaiting trusted review of current source head" | ||
| return "pending", github.MERGEABILITY_PENDING | ||
| return "failure", "; ".join(reasons) | ||
|
|
||
|
|
||
| def _run(cfg: Config) -> int: | ||
| if cfg.repo != os.environ.get("GITHUB_REPOSITORY") or not cfg.review_publishers: | ||
| raise LoopZeroError("trusted repository configuration or review publishers missing") | ||
|
|
@@ -93,18 +106,15 @@ def policy(source_number: int, source: dict) -> None: | |
| f"{owner}/{repo}", f"/merge-queue/status?branch={quote(branch, safe='')}"), | ||
| source_policy=policy, | ||
| ) | ||
| ready, message = True, "All attested candidate sources are reviewed" | ||
| else: | ||
| snapshot = github.pr_from_rest(pr) | ||
| snapshot = eligibility.source_snapshot(cfg.repo, number, head, github.pr_from_rest(pr)) | ||
| result = eligibility.evaluate(cfg.repo, number, head, cfg.base_branch, cfg.review_publishers, | ||
| snapshot=snapshot) | ||
| ready, message = result.ready, "; ".join(result.reasons) or "Reviewed source head" | ||
| if _landed_before_publication(cfg.repo, number, head, snapshot): | ||
| current = _publication_snapshot(cfg.repo, number, head, snapshot) | ||
| if current is None: | ||
| return 0 | ||
| state = "success" if ready else "failure" | ||
| if not candidate and not ready and result.reasons == (github.MISSING_REVIEW_REASON,): | ||
| message = "Awaiting trusted review of current source head" | ||
| state = "pending" | ||
| state, message = (("success", "All attested candidate sources are reviewed") if candidate | ||
| else _source_status(result, current)) | ||
| except (github.GhUnavailable, github.ProcTimeout) as exc: | ||
| print(f"Eligibility pending: evidence unavailable ({exc})", file=sys.stderr) | ||
| return 0 | ||
|
|
@@ -115,18 +125,21 @@ def policy(source_number: int, source: dict) -> None: | |
| raise | ||
| _publish_verdict(cfg.repo, head, state, message[:140]) | ||
| print(message) | ||
| return 0 if ready or state == "pending" else 1 | ||
| return int(state == "failure") | ||
|
|
||
|
|
||
| def _landed_before_publication(repo: str, number: int, head: str, snapshot: github.PR | None) -> bool: | ||
| def _publication_snapshot( | ||
| repo: str, number: int, head: str, snapshot: github.PR | None, | ||
| ) -> github.PR | None: | ||
| current = github.pr_view(repo, number) | ||
| if current.head_sha != head: | ||
| raise LoopZeroError("head changed before publication; refresh eligibility") | ||
| if snapshot is None or current.state == "MERGED": | ||
| return snapshot is not None | ||
| if eligibility.source_fingerprint(current) != eligibility.source_fingerprint(snapshot): | ||
| raise LoopZeroError("source metadata changed before publication; refresh eligibility") | ||
| return False | ||
| if snapshot is not None: | ||
| if current.state == "MERGED": | ||
| return None | ||
| if eligibility.source_fingerprint(current) != eligibility.source_fingerprint(snapshot): | ||
| raise LoopZeroError("source metadata changed before publication; refresh eligibility") | ||
| return current | ||
|
|
||
|
|
||
| def _publish_verdict(repo: str, head: str, state: str, description: 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: Snapshot-less recheck uses a conditional assignment that both later guards repeat
current = github.pr_view(...) if snapshot is None else pris followed by two separateif snapshot is None and ...checks. When a snapshot is supplied,currentis never used, so the ternary branch does nothing and the same condition is checked three times. A singleif snapshot is None:block that fetchescurrent, compares fingerprints, and then appliesmergeability_blocker(current)whenresult.readywould behave the same and be easier to read. Behaviour is correct as written: hosted callers that pass a snapshot get the same mergeability recheck in_publication_snapshotand_source_status.