GRM-58: refactor: require tea CLI everywhere, fail on missing Vikunja task

This commit is contained in:
2026-06-22 11:04:51 +00:00
parent 5e270f21d1
commit dcb2ed0fd9
11 changed files with 104 additions and 162 deletions
+21 -50
View File
@@ -3,8 +3,7 @@
Used by the release and publish workflows to alert on failures that would
otherwise go unnoticed in the Actions tab. Uses the ``tea`` Gitea CLI
for issue creation when available, falling back to ``GiteaClient`` (direct
HTTP API) when tea is not installed.
for issue creation — tea must be installed and configured.
Usage:
REPO_TOKEN=<token> python3 scripts/notify_failure.py \
@@ -18,59 +17,36 @@ from __future__ import annotations
import contextlib
import os
import shutil
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)
def _create_issue_via_tea(repo: str, title: str, body: str) -> int | None:
"""Try creating issue via tea CLI. Returns issue index or None on failure."""
if shutil.which("tea") is None:
return None
from scripts.gitea_cli import TeaCLI, TeaCLIError
def _create_issue_via_tea(repo: str, title: str, body: str) -> int:
"""Create issue via tea CLI. Returns issue index.
Raises TeaCLIError if tea is not installed or the command fails.
"""
tea = TeaCLI(repo=repo)
try:
# Check if "bug" label exists
labels: list[str] = []
try:
existing_labels = tea.list_labels(repo)
if any(label.get("name") == "bug" for label in existing_labels):
labels = ["bug"]
except TeaCLIError:
pass
issue = tea.create_issue(repo, title=title, body=body, labels=labels if labels else None)
if labels:
with contextlib.suppress(TeaCLIError):
tea.add_label(repo, issue["index"], labels)
return int(issue.get("index", 0))
except TeaCLIError:
return None
# Check if "bug" label exists
labels: list[str] = []
with contextlib.suppress(TeaCLIError):
existing_labels = tea.list_labels(repo)
if any(label.get("name") == "bug" for label in existing_labels):
labels = ["bug"]
def _create_issue_via_client(repo: str, title: str, body: str) -> int:
"""Create issue via GiteaClient (direct HTTP API). Returns issue ID."""
token = os.environ.get("REPO_TOKEN", "")
owner, repo_name = repo.split("/")
client = GiteaClient(GITEA_API_URL, token, owner, repo_name)
# Look up label IDs by name (Gitea API expects integer IDs, not strings)
label_ids: list[int] = []
for label in client.list_labels():
if label.get("name") == "bug":
label_ids.append(int(label["id"]))
break
issue = client.create_issue(title=title, body=body, labels=label_ids if label_ids else None)
return int(issue.get("id", 0))
issue = tea.create_issue(repo, title=title, body=body, labels=labels if labels else None)
if labels:
with contextlib.suppress(TeaCLIError):
tea.add_label(repo, issue["index"], labels)
return int(issue.get("index", 0))
@click.command()
@@ -93,15 +69,10 @@ def main(repo: str, run_id: str, workflow: str, commit: str) -> None:
f"Please investigate and fix the issue."
)
# Try tea CLI first, fall back to GiteaClient
issue_id = _create_issue_via_tea(repo, title, body)
if issue_id is None:
try:
issue_id = _create_issue_via_client(repo, title, body)
except APIError as e:
raise click.ClickException(
_("Failed to create issue: HTTP {status}{message}", status=e.status, message=e.message)
) from None
try:
issue_id = _create_issue_via_tea(repo, title, body)
except TeaCLIError as e:
raise click.ClickException(_("Failed to create issue via tea: {error}", error=str(e))) from None
click.echo(
_(