claude-dev-env 8.109.5 → 8.109.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/pr-lifecycle/SKILL.md +1 -1
- package/.agents/skills/pr-lifecycle/reference/review-loop-before-merge.md +2 -0
- package/docs/rule-guides/proof-before-pull-request.md +3 -1
- package/hooks/blocking/merge_review_gate.py +2 -1
- package/hooks/blocking/merge_review_gate_parts/open_request.py +52 -6
- package/hooks/blocking/merge_review_gate_parts/receipts.py +101 -15
- package/hooks/blocking/pull_request_proof.py +258 -50
- package/hooks/blocking/test_merge_review_gate.py +130 -3
- package/hooks/blocking/test_pull_request_proof.py +512 -2
- package/hooks/blocking/tests/test_open_request.py +195 -5
- package/hooks/blocking/tests/test_receipts.py +95 -2
- package/hooks/features/conduct-gates.md +3 -3
- package/hooks/hooks.json +1 -1
- package/hooks/hooks_constants/merge_review_gate_constants.py +24 -5
- package/hooks/hooks_constants/pull_request_proof_constants.py +19 -1
- package/package.json +1 -1
- package/scripts/durable_post_lint.py +28 -4
- package/scripts/merge_review_receipt.py +153 -21
- package/scripts/test_durable_post_lint.py +135 -0
- package/scripts/test_merge_review_receipt.py +168 -0
|
@@ -22,7 +22,7 @@ User-level rule: applies to **every** git repo that uses GitHub with `gh`. Small
|
|
|
22
22
|
|
|
23
23
|
### Pull request submission rules
|
|
24
24
|
|
|
25
|
-
**Prove the change where it runs before opening a PR.** Read `~/.claude/docs/rule-guides/proof-before-pull-request.md` for the body and hook requirements. A `feat` PR also needs an "Eval" section and a session that invoked `/claude-api build-eval`; read `~/.claude/docs/rule-guides/features-start-with-an-eval.md` before you build the feature. A new workflow that runs only on `workflow_dispatch` cannot run until its file is on the default branch: before the PR, run its `run:` steps with a stub `gh` on PATH, name
|
|
25
|
+
**Prove the change where it runs before opening a PR.** Read `~/.claude/docs/rule-guides/proof-before-pull-request.md` for the body and hook requirements. A `feat` PR also needs an "Eval" section and a session that invoked `/claude-api build-eval`; read `~/.claude/docs/rule-guides/features-start-with-an-eval.md` before you build the feature. A new workflow that runs only on `workflow_dispatch` cannot run until its file is on the default branch: before the PR, run its `run:` steps with a stub `gh` on PATH, name the live run that waits on the merge under an "After merge" heading that names the workflow file in backticks and says who records the run, and dispatch it right after the merge.
|
|
26
26
|
|
|
27
27
|
**Open PRs ready for review; use `--draft` when the owner requests it.** Before you commit copied files or open a PR, list the open PRs that change a file whose path starts with yours, then read each hit, with `gh pr list --state open --limit 1000 --json number,files --jq '.[] | select(any(.files[]; .path | startswith("<path>"))) | .number'`, so you do not duplicate a peer's PR. Each pre-existing failure or remaining defect the PR body names links a tracked issue.
|
|
28
28
|
|
|
@@ -9,4 +9,6 @@ A pull request the agent made merges only after a code review of its head comes
|
|
|
9
9
|
5. Repeat until a pass records `CLEAN`. A pass whose every finding is ruled out records `CLEAN` with `--ruled-out <finding count> --rulings <link to the rulings comment on this pull request>`.
|
|
10
10
|
6. Merge pinned to that head: `expectedHeadSha` on the merge tool, or `--match-head-commit` on `gh pr merge`.
|
|
11
11
|
|
|
12
|
+
A pass run before the pull request opens names `open` in place of the number and the full 40 character head: `python3 ~/.claude/scripts/merge_review_receipt.py <owner>/<name> open <head sha> <finding count>`. A pass whose every finding is ruled out adds `--ruled-out <finding count> --rulings <path:line for each finding, comma separated>`. Run it in the checkout that holds the head. It checks that each `path:line` exists at that head, and each finding needs a different one. A merge pinned to that head passes on an open pass only at zero findings. Rulings for the merge go on the pull request, as in step 5.
|
|
13
|
+
|
|
12
14
|
`hooks/blocking/merge_review_gate.py` denies any other merge. In a merge-queue repository, enqueue with `gh pr merge <number> --repo <owner>/<name> --auto --match-head-commit <head sha>`; auto-merge that names no head is denied. A repository whose own CI and merge queue review and merge its pull requests is listed in `CLAUDE_MERGE_REVIEW_EXEMPT_REPOSITORIES`, comma separated as `owner/name`, and skips the gate.
|
|
@@ -34,11 +34,13 @@ For a change to Claude Code behavior, such as a hook, skill, rule, setting, prom
|
|
|
34
34
|
|
|
35
35
|
Report it in the pull request body under "Proof in practice". List each command you ran, quote the output lines that show the effect, and state the difference between the runs with and without the change. The run on the target the change exists to fix belongs in this section before the pull request opens. List a condition the change does not target, such as an older data shape, under a "Not covered" heading at the same level.
|
|
36
36
|
|
|
37
|
+
A workflow file the pull request adds cannot run until it reaches the default branch. For that run only, add an "After merge" heading to the body. Under it, name the added workflow file in backticks and say who records the first run's link. Prove everything else the workflow does before the pull request opens, such as its script and tests.
|
|
38
|
+
|
|
37
39
|
When you cannot prove it, leave the pull request unopened. Tell the owner in three short sentences what you could not run and which tool would make it possible. A blocked proof is an acceptable result, because it shows where tooling is missing.
|
|
38
40
|
|
|
39
41
|
## Enforcement
|
|
40
42
|
|
|
41
|
-
`hooks/blocking/pull_request_proof.py` reads the body of each new pull request before it opens. `pr_lifecycle_skill_gate.py` runs it on `gh pr create`, the `pull_request.py create` script, and each `mcp__*__create_pull_request` tool. The gate denies the call when the body has no "Proof in practice" heading, or when the text under that heading names no command in backticks. The gate also denies a section whose only commands run a test runner, such as `pytest`, `python -m unittest`, `uv run pytest`, `npm test`, `npx vitest`, `jest`, `go test` or `cargo test`. Quotes around a runner word, interpreter flags before `-m`, and `coverage run -m unittest` are still test runs. A command is an inline backticked span or a `$ ` line inside a fenced block. A span that starts with a path and line, such as `gate.py:12`, is not a command. A span that holds one path or file name, such as `src/x.py`, is not a command unless that span runs a test runner, such as `py.test` or `pytest.exe`. A test run piped into `tee`, `tail`, `head`, `grep` or `cat` is still a test run. The deny quotes the line "Unit tests are welcome as extra evidence. The live run is the proof." and asks for a run of the changed thing the way its user runs it, without the change and with it. The gate also denies a section whose prose says part of the change is not proven, not tested or not verified, with "yet", "been" or "fully" allowed after the "not", or says unproven, untested or unverified. The deny quotes that line, and asks for the run before the pull request opens, or for the line under a "Not covered" heading when the change does not target it. The same denial covers a proof line that opens with "not run", "not exercised" or "not executed" (a "yet" or "been" may follow the "not") or says "has not been run". A proof line with a merge word (merge, merged, merges or merging, so post-merge too) is denied with its own reason: run the check on the branch, and put a file or command name that contains merge in backticks. A step that needs the merged code to exist goes under a "Not covered" heading at the same level as the proof heading, as a line that opens with "not run". `UNPROVEN_ADMISSION_PATTERN` and `MERGE_WORD_PATTERN` list the shapes. Words inside backticks or a fenced block are quoted output and do not count. A section with one command that is not a test run, and no such line, passes. A `gh pr create` with no `--body` or `--body-file` is denied with a request for the body. A body edit through `update_pull_request`, `gh pr edit` or the `pull_request.py edit` script gets the same checks on its proof section that a new pull request gets, so an edit cannot swap in a proof that a new pull request would be denied. An edit with no proof section passes. A body the gate cannot read passes, such as an inline multi-line `--body`, a body from standard input, or a body written through `gh api`. Merges and pushes pass.
|
|
43
|
+
`hooks/blocking/pull_request_proof.py` reads the body of each new pull request before it opens. `pr_lifecycle_skill_gate.py` runs it on `gh pr create`, the `pull_request.py create` script, and each `mcp__*__create_pull_request` tool. The gate denies the call when the body has no "Proof in practice" heading, or when the text under that heading names no command in backticks. The gate also denies a section whose only commands run a test runner, such as `pytest`, `python -m unittest`, `uv run pytest`, `npm test`, `npx vitest`, `jest`, `go test` or `cargo test`. Quotes around a runner word, interpreter flags before `-m`, and `coverage run -m unittest` are still test runs. A command is an inline backticked span or a `$ ` line inside a fenced block. A span that starts with a path and line, such as `gate.py:12`, is not a command. A span that holds one path or file name, such as `src/x.py`, is not a command unless that span runs a test runner, such as `py.test` or `pytest.exe`. A test run piped into `tee`, `tail`, `head`, `grep` or `cat` is still a test run. The deny quotes the line "Unit tests are welcome as extra evidence. The live run is the proof." and asks for a run of the changed thing the way its user runs it, without the change and with it. The gate also denies a section whose prose says part of the change is not proven, not tested or not verified, with "yet", "been" or "fully" allowed after the "not", or says unproven, untested or unverified. The line passes only for a workflow file the branch adds, when the body's "After merge" heading plans that file's first run; `pull_request_proof.py` and `hooks_constants/pull_request_proof_constants.py` hold the exact conditions. Otherwise the deny quotes that line, and asks for the run before the pull request opens, or for the line under a "Not covered" heading when the change does not target it. The same denial covers a proof line that opens with "not run", "not exercised" or "not executed" (a "yet" or "been" may follow the "not") or says "has not been run". A proof line with a merge word (merge, merged, merges or merging, so post-merge too) is denied with its own reason: run the check on the branch, and put a file or command name that contains merge in backticks. A step that needs the merged code to exist goes under a "Not covered" heading at the same level as the proof heading, as a line that opens with "not run". `UNPROVEN_ADMISSION_PATTERN` and `MERGE_WORD_PATTERN` list the shapes. Words inside backticks or a fenced block are quoted output and do not count. A section with one command that is not a test run, and no such line, passes. A `gh pr create` with no `--body` or `--body-file` is denied with a request for the body. A body edit through `update_pull_request`, `gh pr edit` or the `pull_request.py edit` script gets the same checks on its proof section that a new pull request gets, so an edit cannot swap in a proof that a new pull request would be denied. An edit with no proof section passes. A body the gate cannot read passes, such as an inline multi-line `--body`, a body from standard input, or a body written through `gh api`. Merges and pushes pass.
|
|
42
44
|
|
|
43
45
|
When the checked-out branch changes a file people see (`.html`, `.htm`, `.css`, `.scss`, `.tsx`, `.jsx`, `.vue`, `.svelte`), the gate also denies a body whose proof section holds no picture: a markdown image, an image URL, or an Artifact page link that shows the screenshots. Render the change, read the screenshot, and put it in the section, so the reader sees what you looked at. A page the branch only moves to another folder or name that ends the same way, with every byte kept (`R100` in `git diff --name-status`), changes nothing people see, so the gate leaves it out; a moved page that also changed, or a file that becomes a page by a change of name ending, still needs the picture. When git in the session directory cannot list the branch's changed files, the gate asks for the picture as well.
|
|
44
46
|
|
|
@@ -38,6 +38,7 @@ if hooks_directory not in sys.path:
|
|
|
38
38
|
from blocking.merge_review_gate_parts.open_request import OpenRequest, open_request_from
|
|
39
39
|
from blocking.merge_review_gate_parts.receipts import (
|
|
40
40
|
has_clean_open_review,
|
|
41
|
+
has_zero_finding_open_review,
|
|
41
42
|
is_clean_receipt,
|
|
42
43
|
receipt_path,
|
|
43
44
|
same_commit,
|
|
@@ -275,7 +276,7 @@ def deny_reason(request: MergeRequest) -> str | None:
|
|
|
275
276
|
if (
|
|
276
277
|
request.pinned_head
|
|
277
278
|
and not pass_on_pinned_head
|
|
278
|
-
and
|
|
279
|
+
and has_zero_finding_open_review(request.repo, request.pinned_head)
|
|
279
280
|
):
|
|
280
281
|
return None
|
|
281
282
|
fields = {"slug": request.slug, "number": request.number}
|
|
@@ -5,6 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
import os
|
|
6
6
|
import subprocess
|
|
7
7
|
import sys
|
|
8
|
+
import tempfile
|
|
8
9
|
from dataclasses import dataclass
|
|
9
10
|
from pathlib import Path
|
|
10
11
|
|
|
@@ -13,6 +14,7 @@ if hooks_directory not in sys.path:
|
|
|
13
14
|
sys.path.insert(0, hooks_directory)
|
|
14
15
|
|
|
15
16
|
from hooks_constants.merge_review_gate_constants import (
|
|
17
|
+
ALL_NON_INTERACTIVE_GIT_SETTINGS,
|
|
16
18
|
ALL_ORIGIN_URL_ARGUMENTS,
|
|
17
19
|
ALL_SHELL_TOOL_NAMES,
|
|
18
20
|
CHANGE_FOLDER_PATTERN,
|
|
@@ -21,13 +23,17 @@ from hooks_constants.merge_review_gate_constants import (
|
|
|
21
23
|
CURRENT_HEAD_REFERENCE,
|
|
22
24
|
CWD_FIELD,
|
|
23
25
|
GH_PR_CREATE_PATTERN,
|
|
26
|
+
GITHUB_REMOTE_URL_TEMPLATE,
|
|
24
27
|
GIT_TIMEOUT_SECONDS,
|
|
25
28
|
HEAD_BRANCH_FIELD,
|
|
26
29
|
HEAD_OPTION_PATTERN,
|
|
30
|
+
LS_REMOTE_FIELD_SEPARATOR,
|
|
27
31
|
ORIGIN_URL_PATTERN,
|
|
28
32
|
OWNER_FIELD,
|
|
29
33
|
PULL_REQUEST_SCRIPT_CREATE_PATTERN,
|
|
30
34
|
REMOTE_BRANCH_PREFIX,
|
|
35
|
+
REMOTE_BRANCH_REFERENCE_TEMPLATE,
|
|
36
|
+
REMOTE_LOOKUP_TIMEOUT_SECONDS,
|
|
31
37
|
REPO_FIELD,
|
|
32
38
|
REPO_OPTION_PATTERN,
|
|
33
39
|
)
|
|
@@ -62,8 +68,11 @@ def open_request_from(all_payload_fields: dict[str, object]) -> OpenRequest | No
|
|
|
62
68
|
gh pr create --repo o/r --head branch
|
|
63
69
|
python pull_request.py create --repo o/r --head branch
|
|
64
70
|
|
|
65
|
-
A
|
|
66
|
-
``
|
|
71
|
+
A tool call reads its head branch from GitHub first. A fork head
|
|
72
|
+
``user:branch`` reads the repository of ``user``. A branch GitHub does not
|
|
73
|
+
list, and every branch of a shell command, resolves in the payload's folder
|
|
74
|
+
as ``origin/<branch>`` first. A ``cd`` target names the folder. No head
|
|
75
|
+
means ``HEAD``; no repository, ``origin``.
|
|
67
76
|
|
|
68
77
|
Args:
|
|
69
78
|
all_payload_fields: The parsed PreToolUse input.
|
|
@@ -86,12 +95,15 @@ def open_request_from(all_payload_fields: dict[str, object]) -> OpenRequest | No
|
|
|
86
95
|
|
|
87
96
|
|
|
88
97
|
def _tool_open_request(all_tool_input: dict[object, object], folder: str | None) -> OpenRequest:
|
|
98
|
+
owner = str(all_tool_input.get(OWNER_FIELD, ""))
|
|
99
|
+
repo = str(all_tool_input.get(REPO_FIELD, ""))
|
|
89
100
|
branch = all_tool_input.get(HEAD_BRANCH_FIELD)
|
|
90
|
-
|
|
91
|
-
owner
|
|
92
|
-
|
|
93
|
-
|
|
101
|
+
head = (
|
|
102
|
+
_pushed_commit(owner, repo, branch) or _branch_commit(branch, folder)
|
|
103
|
+
if isinstance(branch, str) and branch
|
|
104
|
+
else None
|
|
94
105
|
)
|
|
106
|
+
return OpenRequest(owner=owner, repo=repo, head=head)
|
|
95
107
|
|
|
96
108
|
|
|
97
109
|
def _shell_open_request(command: str, folder: str | None) -> OpenRequest | None:
|
|
@@ -155,6 +167,40 @@ def _branch_commit(branch: str, folder: str | None) -> str | None:
|
|
|
155
167
|
return None
|
|
156
168
|
|
|
157
169
|
|
|
170
|
+
def _pushed_commit(owner: str, repo: str, branch: str) -> str | None:
|
|
171
|
+
head_owner, separator, head_branch = branch.partition(":")
|
|
172
|
+
if not separator:
|
|
173
|
+
head_owner, head_branch = owner, branch
|
|
174
|
+
if not head_owner or not repo or not head_branch:
|
|
175
|
+
return None
|
|
176
|
+
reference = REMOTE_BRANCH_REFERENCE_TEMPLATE.format(branch=head_branch)
|
|
177
|
+
remote_url = GITHUB_REMOTE_URL_TEMPLATE.format(owner=head_owner, repo=repo)
|
|
178
|
+
with tempfile.TemporaryDirectory() as empty_folder, tempfile.TemporaryFile() as listing:
|
|
179
|
+
try:
|
|
180
|
+
subprocess.run(
|
|
181
|
+
["git", "ls-remote", remote_url, reference],
|
|
182
|
+
cwd=empty_folder,
|
|
183
|
+
stdin=subprocess.DEVNULL,
|
|
184
|
+
stdout=listing,
|
|
185
|
+
stderr=subprocess.DEVNULL,
|
|
186
|
+
timeout=REMOTE_LOOKUP_TIMEOUT_SECONDS,
|
|
187
|
+
check=False,
|
|
188
|
+
env={**os.environ, **ALL_NON_INTERACTIVE_GIT_SETTINGS},
|
|
189
|
+
)
|
|
190
|
+
except (OSError, subprocess.SubprocessError):
|
|
191
|
+
return None
|
|
192
|
+
listing.seek(0)
|
|
193
|
+
return _listed_commit(listing.read().decode("utf-8", "replace"), reference)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def _listed_commit(listing: str, reference: str) -> str | None:
|
|
197
|
+
for each_line in listing.splitlines():
|
|
198
|
+
commit, separator, listed_reference = each_line.partition(LS_REMOTE_FIELD_SEPARATOR)
|
|
199
|
+
if separator and listed_reference == reference:
|
|
200
|
+
return commit
|
|
201
|
+
return None
|
|
202
|
+
|
|
203
|
+
|
|
158
204
|
def _origin_repository(folder: str | None) -> tuple[str, str]:
|
|
159
205
|
origin_url = _run_git(list(ALL_ORIGIN_URL_ARGUMENTS), folder)
|
|
160
206
|
origin_match = ORIGIN_URL_PATTERN.search(origin_url) if origin_url else None
|
|
@@ -9,6 +9,7 @@ from __future__ import annotations
|
|
|
9
9
|
import json
|
|
10
10
|
import os
|
|
11
11
|
import sys
|
|
12
|
+
from collections.abc import Callable
|
|
12
13
|
from pathlib import Path
|
|
13
14
|
|
|
14
15
|
hooks_directory = str(Path(__file__).resolve().parent.parent.parent)
|
|
@@ -27,7 +28,9 @@ from hooks_constants.merge_review_gate_constants import (
|
|
|
27
28
|
RECEIPT_FINDINGS_KEY,
|
|
28
29
|
RECEIPT_HEAD_KEY,
|
|
29
30
|
RECEIPT_RULED_OUT_KEY,
|
|
31
|
+
RECEIPT_RULING_LINES_KEY,
|
|
30
32
|
RECEIPT_RULINGS_KEY,
|
|
33
|
+
RULING_REFERENCE_PATTERN,
|
|
31
34
|
RULINGS_LINK_PATTERN,
|
|
32
35
|
)
|
|
33
36
|
|
|
@@ -81,32 +84,71 @@ def open_receipt_path(owner: str, repo: str, head: str) -> Path:
|
|
|
81
84
|
|
|
82
85
|
|
|
83
86
|
def has_clean_open_review(repo: str, head: str) -> bool:
|
|
84
|
-
"""Return whether a pass recorded before the pull request opened
|
|
87
|
+
"""Return whether a pass recorded before the pull request opened lets it open at a head.
|
|
85
88
|
|
|
86
|
-
The
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
The pass is clean when it found zero findings, or when each finding has a
|
|
90
|
+
``path:line`` ruling. The head may be a full or an abbreviated commit,
|
|
91
|
+
matched against each recorded head by prefix. The owner is left out of the
|
|
92
|
+
match, since a checkout whose origin still names a transferred
|
|
93
|
+
repository's old owner opens against the new one::
|
|
90
94
|
|
|
91
95
|
open receipt {head: abc1234..., findings: 0}, head abc1234 -> True
|
|
96
|
+
open receipt {head: abc1234..., findings: 2, ruled out 2,
|
|
97
|
+
ruling_lines [a.py:1, b.py:20]}, head abc1234 -> True
|
|
92
98
|
open receipt {head: abc1234..., findings: 2}, head abc1234 -> False
|
|
93
99
|
no open receipt for the repository -> False
|
|
94
100
|
|
|
95
101
|
Args:
|
|
96
102
|
repo: Repository name.
|
|
97
|
-
head: The commit the open
|
|
103
|
+
head: The commit the open names.
|
|
98
104
|
|
|
99
105
|
Returns:
|
|
100
106
|
True when a clean open receipt covers that head.
|
|
101
107
|
"""
|
|
108
|
+
return _has_open_review(repo, head, is_clean_open_pass)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def has_zero_finding_open_review(repo: str, head: str) -> bool:
|
|
112
|
+
"""Return whether a pass recorded before the pull request opened found zero findings at a head.
|
|
113
|
+
|
|
114
|
+
A merge accepts the open pass only at zero findings. Ruled-out findings
|
|
115
|
+
need the rulings comment a numbered pass links on the pull request::
|
|
116
|
+
|
|
117
|
+
open receipt {head: abc1234..., findings: 0}, head abc1234 -> True
|
|
118
|
+
open receipt {head: abc1234..., findings: 2, ruled out 2,
|
|
119
|
+
ruling_lines [a.py:1, b.py:20]}, head abc1234 -> False
|
|
120
|
+
|
|
121
|
+
Args:
|
|
122
|
+
repo: Repository name.
|
|
123
|
+
head: The commit the merge pins.
|
|
124
|
+
|
|
125
|
+
Returns:
|
|
126
|
+
True when an open receipt with zero findings covers that head.
|
|
127
|
+
"""
|
|
128
|
+
return _has_open_review(repo, head, _reports_no_findings)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _has_open_review(
|
|
132
|
+
repo: str, head: str, is_acceptable_pass: Callable[[dict[str, object]], bool]
|
|
133
|
+
) -> bool:
|
|
102
134
|
if not OPEN_HEAD_PATTERN.fullmatch(head):
|
|
103
135
|
return False
|
|
104
136
|
folder = receipt_directory() / OPEN_RECEIPT_DIRECTORY_NAME
|
|
105
137
|
pattern = OPEN_RECEIPT_GLOB_TEMPLATE.format(repo=repo.casefold())
|
|
106
|
-
return any(
|
|
138
|
+
return any(
|
|
139
|
+
_is_open_receipt_for(each_path, head, is_acceptable_pass)
|
|
140
|
+
for each_path in folder.glob(pattern)
|
|
141
|
+
)
|
|
107
142
|
|
|
108
143
|
|
|
109
|
-
def
|
|
144
|
+
def _reports_no_findings(all_receipt_fields: dict[str, object]) -> bool:
|
|
145
|
+
finding_count = all_receipt_fields.get(RECEIPT_FINDINGS_KEY)
|
|
146
|
+
return _is_count(finding_count) and finding_count == 0
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def _is_open_receipt_for(
|
|
150
|
+
path: Path, head: str, is_acceptable_pass: Callable[[dict[str, object]], bool]
|
|
151
|
+
) -> bool:
|
|
110
152
|
try:
|
|
111
153
|
all_receipt_fields = json.loads(path.read_text(encoding="utf-8"))
|
|
112
154
|
except (OSError, ValueError):
|
|
@@ -118,8 +160,50 @@ def _is_clean_open_receipt(path: Path, head: str) -> bool:
|
|
|
118
160
|
isinstance(recorded_head, str)
|
|
119
161
|
and OPEN_RECEIPT_HEAD_PATTERN.fullmatch(recorded_head) is not None
|
|
120
162
|
and same_commit(recorded_head, head)
|
|
121
|
-
and
|
|
122
|
-
|
|
163
|
+
and is_acceptable_pass(all_receipt_fields)
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def is_clean_open_pass(all_receipt_fields: dict[str, object]) -> bool:
|
|
168
|
+
"""Return whether a pass recorded before the pull request opened lets it open.
|
|
169
|
+
|
|
170
|
+
The pull request has no number yet, so no rulings comment exists to link.
|
|
171
|
+
A pass is clean when it reported zero findings, or when each finding it
|
|
172
|
+
reported has its own ``path:line`` ruling beside it::
|
|
173
|
+
|
|
174
|
+
findings 0 -> clean
|
|
175
|
+
findings 2, ruled out 2, ruling_lines [a.py:1, src/b.py:20] -> clean
|
|
176
|
+
findings 2, ruled out 2, ruling_lines [a.py:1] -> not clean
|
|
177
|
+
findings 2, ruled out 2, ruling_lines [a.py:1, a.py:1] -> not clean
|
|
178
|
+
findings 2, ruled out 2, ruling_lines [a.py:1, see the thread] -> not clean
|
|
179
|
+
|
|
180
|
+
Args:
|
|
181
|
+
all_receipt_fields: The parsed receipt of one review pass.
|
|
182
|
+
|
|
183
|
+
Returns:
|
|
184
|
+
True when the pass counts as clean.
|
|
185
|
+
"""
|
|
186
|
+
finding_count = all_receipt_fields.get(RECEIPT_FINDINGS_KEY)
|
|
187
|
+
return _reports_no_findings(all_receipt_fields) or (
|
|
188
|
+
_is_count(finding_count)
|
|
189
|
+
and _rules_out_every_finding_at_file_and_line(all_receipt_fields, finding_count)
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _rules_out_every_finding_at_file_and_line(
|
|
194
|
+
all_receipt_fields: dict[str, object], finding_count: object
|
|
195
|
+
) -> bool:
|
|
196
|
+
all_ruling_lines = all_receipt_fields.get(RECEIPT_RULING_LINES_KEY)
|
|
197
|
+
return (
|
|
198
|
+
_ruled_out_count_matches(all_receipt_fields, finding_count)
|
|
199
|
+
and isinstance(all_ruling_lines, list)
|
|
200
|
+
and len(all_ruling_lines) == finding_count
|
|
201
|
+
and len(set(map(str, all_ruling_lines))) == finding_count
|
|
202
|
+
and all(
|
|
203
|
+
isinstance(each_ruling, str)
|
|
204
|
+
and RULING_REFERENCE_PATTERN.fullmatch(each_ruling) is not None
|
|
205
|
+
for each_ruling in all_ruling_lines
|
|
206
|
+
)
|
|
123
207
|
)
|
|
124
208
|
|
|
125
209
|
|
|
@@ -174,14 +258,16 @@ def _is_count(candidate: object) -> bool:
|
|
|
174
258
|
def _rules_out_every_finding(
|
|
175
259
|
all_receipt_fields: dict[str, object], finding_count: object, owner: str, repo: str, number: int
|
|
176
260
|
) -> bool:
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
_is_count(ruled_out_count)
|
|
180
|
-
and ruled_out_count == finding_count
|
|
181
|
-
and _links_rulings_on(all_receipt_fields.get(RECEIPT_RULINGS_KEY), owner, repo, number)
|
|
261
|
+
return _ruled_out_count_matches(all_receipt_fields, finding_count) and _links_rulings_on(
|
|
262
|
+
all_receipt_fields.get(RECEIPT_RULINGS_KEY), owner, repo, number
|
|
182
263
|
)
|
|
183
264
|
|
|
184
265
|
|
|
266
|
+
def _ruled_out_count_matches(all_receipt_fields: dict[str, object], finding_count: object) -> bool:
|
|
267
|
+
ruled_out_count = all_receipt_fields.get(RECEIPT_RULED_OUT_KEY)
|
|
268
|
+
return _is_count(ruled_out_count) and ruled_out_count == finding_count
|
|
269
|
+
|
|
270
|
+
|
|
185
271
|
def _links_rulings_on(rulings: object, owner: str, repo: str, number: int) -> bool:
|
|
186
272
|
rulings_match = RULINGS_LINK_PATTERN.fullmatch(rulings) if isinstance(rulings, str) else None
|
|
187
273
|
return (
|