Repository navigation
Reuse the PR reads that bracket hosted eligibility #1766
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 |
|---|---|---|
|
|
@@ -163,13 +163,18 @@ def readiness_review(reviews: list[dict], head: str, publishers: tuple[str, ...] | |
| return latest | ||
|
|
||
|
|
||
| def source_fingerprint(pr: github.PR) -> tuple[object, ...]: | ||
|
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: Two independent source fingerprints encode the same eligibility-relevant fields
Consider deriving the candidate's eligibility-relevant part from |
||
| return (pr.number, pr.head_sha, pr.base_ref, pr.state, pr.mergeable == "CONFLICTING", | ||
| github.merge_hold(pr.number, pr.labels)) | ||
|
|
||
|
|
||
| def evaluate(repo: str, number: int, head: str, base: str, | ||
| publishers: tuple[str, ...]) -> github.Readiness: | ||
| """Re-fetch reviews and threads; no local receipts, CI identity or source execution.""" | ||
| publishers: tuple[str, ...], *, snapshot: github.PR | None = None) -> github.Readiness: | ||
| """Evaluate live review evidence. Callers supplying a snapshot own the final source check.""" | ||
| if not publishers or not re.fullmatch(r"[0-9a-f]{40}", head): | ||
| raise LoopZeroError("eligibility requires trusted publishers and a full source SHA") | ||
| pr = github.pr_view(repo, number) | ||
| if pr.head_sha != head: | ||
| pr = snapshot if snapshot is not None else github.pr_view(repo, number) | ||
| if pr.number != number or pr.head_sha != head: | ||
| return github.Readiness(False, ("source head changed; refresh eligibility",)) | ||
| if hold := github.merge_hold(pr.number, pr.labels): | ||
| return github.Readiness(False, (hold,)) | ||
|
|
@@ -190,8 +195,8 @@ def evaluate(repo: str, number: int, head: str, base: str, | |
| result = github.readiness(repo, pr, base, (), head if review else None, allow_behind=True, | ||
| ancestor_review=review is not None and review["commit_id"] != head, | ||
| publishers=publishers) | ||
| if github.pr_view(repo, number).head_sha != head: | ||
| return github.Readiness(False, ("source head changed during eligibility refresh",)) | ||
| if snapshot is None and source_fingerprint(github.pr_view(repo, number)) != source_fingerprint(pr): | ||
| return github.Readiness(False, ("source changed during eligibility refresh",)) | ||
| return result | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,11 +78,13 @@ def _run(cfg: Config) -> int: | |
| def publish(state: str, message: str) -> None: | ||
| github.commit_status(cfg.repo, head, eligibility.CONTEXT, state, message[:140]) | ||
| publish("pending", "Refreshing live source review evidence") | ||
| snapshot = None | ||
| try: | ||
| if candidate: | ||
| def policy(source_number: int, source: dict) -> None: | ||
| result = eligibility.evaluate(cfg.repo, source_number, source["head"]["sha"], | ||
| cfg.base_branch, cfg.review_publishers) | ||
| cfg.base_branch, cfg.review_publishers, | ||
| snapshot=github.pr_from_rest(source)) | ||
| if not result.ready: | ||
| raise _SourcePolicyRejection(f"source #{source_number}: " + "; ".join(result.reasons)) | ||
| candidate_mod.attest_candidate( | ||
|
|
@@ -94,10 +96,12 @@ def policy(source_number: int, source: dict) -> None: | |
| ) | ||
| ready, message = True, "All attested candidate sources are reviewed" | ||
| else: | ||
| result = eligibility.evaluate(cfg.repo, number, head, cfg.base_branch, cfg.review_publishers) | ||
| snapshot = 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 github.pr_view(cfg.repo, number).head_sha != head: | ||
| raise LoopZeroError("head changed before publication; refresh eligibility") | ||
| if _landed_before_publication(cfg.repo, number, head, snapshot): | ||
|
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: Landed-source skip leaves a self-written pending status on the merged head When the source merges while eligibility is being evaluated, |
||
| 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" | ||
|
|
@@ -113,6 +117,18 @@ def policy(source_number: int, source: dict) -> None: | |
| return 0 if ready or state == "pending" else 1 | ||
|
|
||
|
|
||
| def _landed_before_publication(repo: str, number: int, head: str, snapshot: github.PR | None) -> bool: | ||
| current = github.pr_view(repo, number) | ||
| if current.head_sha != head: | ||
| raise LoopZeroError("head changed before publication; refresh eligibility") | ||
| if snapshot is not None: | ||
| if current.state == "MERGED": | ||
| return True | ||
| if eligibility.source_fingerprint(current) != eligibility.source_fingerprint(snapshot): | ||
| raise LoopZeroError("source metadata changed before publication; refresh eligibility") | ||
| return False | ||
|
|
||
|
|
||
| def _publish_verdict(repo: str, head: str, state: str, description: str) -> None: | ||
| context = eligibility.CONTEXT | ||
| try: | ||
|
|
||
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: New label validation in candidate fingerprint has no test
_source_fingerprintnow raisesCandidateError("invalid source PR labels")for malformed labels. Before this change it failed with a bare KeyError/TypeError. No test in this diff covers the new path, so a regression could reintroduce an unclassified exception and skip the typed candidate error handling. Add a small case to the candidate tests with labels like[{}]or"x"that expectsCandidateError. The 120+ character line could also be wrapped to match the surrounding style.