fix: revert review_pr.py to GiteaClient (tea v0.14.1 is interactive-only) (#70)
This commit is contained in:
+25
-9
@@ -3,9 +3,14 @@
|
||||
|
||||
Used by the GRM workflow to post structured PR reviews. The review body
|
||||
is provided via --body and inline comments via a JSON file
|
||||
(--comments-json) or stdin (--comments-stdin). This script uses the
|
||||
``tea`` Gitea CLI for posting the review — the actual review analysis is
|
||||
performed by the agent before invoking this tool.
|
||||
(--comments-json) or stdin (--comments-stdin).
|
||||
|
||||
.. note::
|
||||
The ``tea`` CLI v0.14.1 only supports interactive reviews (no
|
||||
``--approve``/``--comment`` flags), so this script uses
|
||||
``GiteaClient`` (direct HTTP API) for posting reviews. When a newer
|
||||
version of tea adds non-interactive review support, this can be
|
||||
switched to use ``TeaCLI.review_pr()``.
|
||||
|
||||
Usage:
|
||||
REPO_TOKEN=<token> python3 scripts/review_pr.py <pr_number> <repo> \
|
||||
@@ -36,8 +41,10 @@ from typing import Any
|
||||
import click
|
||||
from dotenv import load_dotenv # pyright: ignore[reportMissingImports,reportUnknownVariableType]
|
||||
|
||||
from gitea_runner_manager.api_clients import GiteaClient
|
||||
from gitea_runner_manager.config import GITEA_API_URL
|
||||
from gitea_runner_manager.exceptions import APIError
|
||||
from gitea_runner_manager.i18n import _
|
||||
from scripts.gitea_cli import TeaCLI, TeaCLIError
|
||||
|
||||
load_dotenv(override=True)
|
||||
|
||||
@@ -105,7 +112,8 @@ def main(
|
||||
if not token:
|
||||
raise click.ClickException(_("ERROR: REPO_TOKEN is not set."))
|
||||
|
||||
tea = TeaCLI(repo=repo)
|
||||
owner, repo_name = repo.split("/")
|
||||
client = GiteaClient(GITEA_API_URL, token, owner, repo_name)
|
||||
|
||||
comments = parse_comments(comments_json, comments_stdin)
|
||||
|
||||
@@ -129,13 +137,21 @@ def main(
|
||||
)
|
||||
|
||||
try:
|
||||
tea.review_pr(repo, int(pr_number), event=event, body=body)
|
||||
except TeaCLIError as e:
|
||||
raise click.ClickException(_("Failed to post review: {error}", error=str(e))) from None
|
||||
review = client.create_review(pr_number, event=event, body=body, comments=comments)
|
||||
except APIError as e:
|
||||
raise click.ClickException(
|
||||
_(
|
||||
"Failed to post review: HTTP {status} — {message}",
|
||||
status=e.status,
|
||||
message=e.message,
|
||||
)
|
||||
) from None
|
||||
|
||||
review_id = review.get("id", "?")
|
||||
click.echo(
|
||||
_(
|
||||
"Review posted on PR #{pr_number} with event '{event}' ({num_comments} inline comments).",
|
||||
"Review #{review_id} posted on PR #{pr_number} with event '{event}' ({num_comments} inline comments).",
|
||||
review_id=review_id,
|
||||
pr_number=pr_number,
|
||||
event=event,
|
||||
num_comments=len(comments),
|
||||
|
||||
Reference in New Issue
Block a user