Files
nisse/scripts/resolve_settled.py
dongarandClaude Opus 5.5 33d030590d
CI / checks (push) Skipped
CI / checks (pull_request) Successful in 1m58s
CI / e2e (pull_request) Successful in 7m41s
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
2026-10-19 22:06:56 +00:00

57 lines
1.9 KiB
Python

"""Resolve the review threads nisse-review settled on a PR.
uv run python scripts/resolve_settled.py PR [--repo dev/nisse]
nisse-review marks a reply that closes its thread, but it is read-only (R3)
and can't resolve the thread itself; the PR's author does. nisse-dev
resolves its own PRs' threads; this is for PRs made by hand or by Claude
Code. The Gitea URL and token come from tea's login (~/.config/tea).
"""
import argparse
import sys
from pathlib import Path
import yaml
from nisse_core.gitea import GiteaClient, to_resolve
TEA_CONFIG = Path.home() / ".config" / "tea" / "config.yml"
def tea_login(path: Path = TEA_CONFIG) -> tuple[str, str]:
"""tea's default login (or its only one): the Gitea URL and its token."""
logins = (yaml.safe_load(path.read_text()) or {}).get("logins") or []
if not logins:
raise SystemExit(f"no tea login in {path}")
login = next((one for one in logins if one.get("default")), logins[0])
return str(login["url"]), str(login["token"])
def resolve_settled(gitea: GiteaClient, repo: str, pr: int) -> list[int]:
"""Resolve every comment in the threads a settled reply closed."""
done = []
for comment_id in to_resolve(gitea.review_notes(repo, pr)):
gitea.resolve_comment(repo, comment_id)
done.append(comment_id)
return done
def main(argv: list[str] | None = None, gitea: GiteaClient | None = None) -> int:
parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])
parser.add_argument("pr", type=int, help="the PR's number")
parser.add_argument("--repo", default="dev/nisse", help="owner/name")
args = parser.parse_args(argv)
if gitea is None:
gitea = GiteaClient(*tea_login())
done = resolve_settled(gitea, args.repo, args.pr)
print(
f"resolved {len(done)} comment(s) on {args.repo}#{args.pr}"
+ (f": {', '.join(map(str, done))}" if done else "")
)
return 0
if __name__ == "__main__":
sys.exit(main())