nisse-review marks a reply that settles its thread; the PR's author resolves it
The reviewer is read-only (R3), so Gitea refuses it resolving a thread. Now each reply says whether it settles its thread, and a settled reply carries <!-- nisse-review: settled -->. nisse-dev, as the author, resolves every comment on that thread's line when it watches the PR, and doesn't take the settled reply as a point to answer. scripts/resolve_settled.py does the same for PRs made by hand. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J5Utyfzw7gF7UhjRDEtjTk
This commit is contained in:
1 parent
6b85e5a039
commit
33d030590d
11 files changed
+384
-12
No files matched your search
@@ -86,6 +86,26 @@ class ReviewNote:
|
||||
author: str
|
||||
body: str
|
||||
where: str # "path:line" for a line comment, "" for a review body
|
||||
resolved: bool = False # a line comment's thread, marked resolved
|
||||
|
||||
|
||||
# A reviewer's reply that settles its thread: nothing more is needed from
|
||||
# it there. It can't resolve the thread itself (read-only, R3), so the PR's
|
||||
# author does.
|
||||
SETTLED_MARKER = "<!-- nisse-review: settled -->"
|
||||
|
||||
|
||||
def to_resolve(notes: list[ReviewNote]) -> list[int]:
|
||||
"""The ids of the unresolved line comments in threads a settled reply
|
||||
closed: every comment on that path:line, as Gitea groups a thread."""
|
||||
settled = {
|
||||
n.where for n in notes if n.key.startswith("line-") and SETTLED_MARKER in n.body
|
||||
}
|
||||
return [
|
||||
int(n.key.removeprefix("line-"))
|
||||
for n in notes
|
||||
if n.key.startswith("line-") and n.where in settled and not n.resolved
|
||||
]
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -198,10 +218,16 @@ class GiteaClient:
|
||||
author=(comment.get("user") or {}).get("login", author),
|
||||
body=str(comment.get("body") or ""),
|
||||
where=f"{comment.get('path', '')}:{line}",
|
||||
resolved=bool(comment.get("resolver")),
|
||||
)
|
||||
)
|
||||
return notes
|
||||
|
||||
def resolve_comment(self, repo: str, comment_id: int) -> None:
|
||||
"""Mark a line comment's thread resolved: the PR's author or someone
|
||||
with write access may."""
|
||||
self._request("POST", f"/repos/{repo}/pulls/comments/{comment_id}/resolve")
|
||||
|
||||
def find_pull_request(self, repo: str, head: str) -> PullRequest | None:
|
||||
"""External truth for L8: did the PR for this branch already get
|
||||
opened? Includes closed PRs — a crash after opening must not be
|
||||
|
||||
@@ -5,11 +5,14 @@ import pytest
|
||||
|
||||
from nisse_core.gitea import (
|
||||
PR_PAGE_SIZE,
|
||||
SETTLED_MARKER,
|
||||
Comment,
|
||||
GiteaClient,
|
||||
GiteaError,
|
||||
GiteaNotFound,
|
||||
ReviewNote,
|
||||
pull_request_reconciler,
|
||||
to_resolve,
|
||||
)
|
||||
from nisse_core.state.store import Intent
|
||||
|
||||
@@ -445,3 +448,65 @@ def test_commits_between_are_oldest_first_and_diffs_come_through_the_api() -> No
|
||||
method, path, body = seen[2]
|
||||
assert (method, path) == ("POST", "/api/v1/repos/o/r/issues/comments/42/reactions")
|
||||
assert json.loads(body) == {"content": "+1"}
|
||||
|
||||
|
||||
# --- settled threads ------------------------------------------------------------
|
||||
|
||||
|
||||
def line(n: int, where: str, body: str = "", resolved: bool = False) -> ReviewNote:
|
||||
return ReviewNote(f"line-{n}", "someone", body, where, resolved)
|
||||
|
||||
|
||||
def test_a_settled_reply_resolves_every_comment_in_its_thread() -> None:
|
||||
notes = [
|
||||
line(1, "a.py:3", "a point"),
|
||||
line(2, "a.py:3", "an answer"),
|
||||
line(3, "a.py:3", f"conceded\n{SETTLED_MARKER}"),
|
||||
line(4, "a.py:9", "another point, still open"),
|
||||
ReviewNote("review-5", "someone", f"summary {SETTLED_MARKER}", ""),
|
||||
]
|
||||
assert to_resolve(notes) == [1, 2, 3]
|
||||
|
||||
|
||||
def test_a_thread_already_resolved_is_left_alone() -> None:
|
||||
notes = [
|
||||
line(1, "a.py:3", "a point", resolved=True),
|
||||
line(2, "a.py:3", f"conceded\n{SETTLED_MARKER}", resolved=True),
|
||||
]
|
||||
assert to_resolve(notes) == []
|
||||
|
||||
|
||||
def test_review_notes_say_which_line_comments_are_resolved() -> None:
|
||||
def handler(request: httpx.Request) -> httpx.Response:
|
||||
if request.url.path.endswith("/reviews"):
|
||||
return httpx.Response(200, json=[{"id": 7, "comments_count": 2}])
|
||||
return httpx.Response(
|
||||
200,
|
||||
json=[
|
||||
{"id": 1, "body": "x", "path": "a.py", "position": 3},
|
||||
{
|
||||
"id": 2,
|
||||
"body": "y",
|
||||
"path": "a.py",
|
||||
"position": 3,
|
||||
"resolver": {"login": "dev-agent"},
|
||||
},
|
||||
],
|
||||
)
|
||||
|
||||
notes = client(handler).review_notes("o/r", 4)
|
||||
assert [(n.key, n.where, n.resolved) for n in notes] == [
|
||||
("line-1", "a.py:3", False),
|
||||
("line-2", "a.py:3", True),
|
||||
]
|
||||
|
||||
|
||||
def test_resolving_a_comment_posts_to_its_resolve_endpoint() -> None:
|
||||
seen: list[tuple[str, str]] = []
|
||||
|
||||
def handler(request: httpx.Request) -> httpx.Response:
|
||||
seen.append((request.method, request.url.path))
|
||||
return httpx.Response(200)
|
||||
|
||||
client(handler).resolve_comment("o/r", 42)
|
||||
assert seen == [("POST", "/api/v1/repos/o/r/pulls/comments/42/resolve")]
|
||||
Reference in new issue
Block a user