GRM-51: refactor: convert shell scripts and inline workflow scripts to Python

This commit is contained in:
2026-06-22 05:53:31 +00:00
parent bec7b59671
commit b6e87a519b
28 changed files with 1582 additions and 219 deletions
+36 -2
View File
@@ -7,6 +7,7 @@ Usage:
import os
import re
import subprocess # nosec B404
import click
from dotenv import load_dotenv # pyright: ignore[reportMissingImports,reportUnknownVariableType]
@@ -19,6 +20,32 @@ from gitea_runner_manager.i18n import _
load_dotenv(override=True)
def _get_git_commit_message() -> str:
"""Get the full commit message of the latest commit."""
result = subprocess.run( # nosec B603 B607
["git", "log", "-1", "--pretty=%B"],
capture_output=True,
text=True,
check=False,
)
if result.returncode != 0:
raise click.ClickException(f"git log failed: {result.stderr.strip()}")
return result.stdout.strip()
def _get_git_commit_sha() -> str:
"""Get the SHA of the latest commit."""
result = subprocess.run( # nosec B603 B607
["git", "rev-parse", "HEAD"],
capture_output=True,
text=True,
check=False,
)
if result.returncode != 0:
raise click.ClickException(f"git rev-parse failed: {result.stderr.strip()}")
return result.stdout.strip()
def extract_task_id(commit_msg: str) -> str:
"""Extract GRM-N task identifier from the first line of commit message."""
first_line = commit_msg.split("\n")[0]
@@ -69,9 +96,16 @@ def build_comment(task_id: str, conv_msg: str, commit_sha: str) -> str:
@click.command()
@click.argument("commit_msg")
@click.argument("commit_msg", required=False)
@click.option("--commit-sha", default="", help="Commit SHA")
def main(commit_msg: str, commit_sha: str) -> None:
@click.option("--from-git", is_flag=True, default=False, help="Read commit message and SHA from git.")
def main(commit_msg: str | None, commit_sha: str, from_git: bool) -> None:
if from_git:
commit_msg = _get_git_commit_message()
if not commit_sha:
commit_sha = _get_git_commit_sha()
if not commit_msg:
raise click.ClickException("commit_msg argument is required (or use --from-git)")
token = os.environ.get("VIKUNJA_TOKEN", "")
if not token:
raise click.ClickException(_("ERROR: VIKUNJA_TOKEN is not set."))