Merge pull request 'nisse-review marks a reply that settles its thread; the PR's author resolves it' (#169) from review-settled into main
This commit was merged in pull request #169.
This commit is contained in:
commit
5277d7827b
11 files changed
+406
-12
No files matched your search
@@ -0,0 +1,56 @@
|
||||
"""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())
|
||||
Reference in new issue
Block a user