Repository navigation
Reuse candidate validation and simplify hosted publication guards #1863
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 |
|---|---|---|
|
|
@@ -27,9 +27,9 @@ def event_number(event: dict) -> int: | |
| value = prs[0].get("number") | ||
| else: | ||
| value = event.get("inputs", {}).get("pr", "") | ||
| if isinstance(value, bool) or not str(value).isdigit() or int(value) < 1: | ||
| raise LoopZeroError("refresh requires a positive PR number") | ||
| return int(value) | ||
| if not isinstance(value, bool) and str(value).isdigit() and (number := int(value)) > 0: | ||
| return number | ||
| raise LoopZeroError("refresh requires a positive PR number") | ||
|
|
||
|
|
||
| def main() -> int: | ||
|
|
@@ -121,11 +121,10 @@ def _landed_before_publication(repo: str, number: int, head: str, snapshot: gith | |
| 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") | ||
| if snapshot is None or current.state == "MERGED": | ||
|
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: Merged-guard rewrite is behaviour-preserving but harder to read I traced all four cases (snapshot None or present × MERGED or not) and the result matches the old code: without a snapshot it returns False, a MERGED PR with a snapshot returns True, and otherwise the fingerprint check runs. The problem is readability. |
||
| 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 | ||
|
|
||
|
|
||
|
|
||
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: Combined lines go past the configured 100-column width
Three joined lines are longer than
line-length = 100in pyproject.toml: theexpected_identity = _identity(_object(github_get(...), ...))call (about 112 columns), thesub_batches_require(about 103), and thepull_requests_require(about 104). The lint rule set doesn't select E501, so CI won't fail, and the file already has longer lines. Still, cutting line count by going over the formatter width will get undone the next time someone runsruff format, and that would bring back the removed lines. Either confirm thatruff formatisn't used in this repo, or keep these calls within 100 columns.