Files
gitea-codex/src/gitea_codex_bot/services/commands.py
Space-Banane d8956b309d
Some checks failed
ci / test (push) Failing after 12s
ci / publish (push) Has been skipped
First MVP
2026-05-22 19:25:57 +02:00

31 lines
915 B
Python

from __future__ import annotations
import re
from gitea_codex_bot.types import ParsedCommand
COMMAND_RE = re.compile(r"^@codex\s+(review|explain|fix|ignore|rerun)\b(.*)$", re.IGNORECASE | re.DOTALL)
def parse_command(body: str) -> ParsedCommand | None:
stripped = body.strip()
match = COMMAND_RE.match(stripped)
if not match:
return None
name = match.group(1).lower()
rest = match.group(2).strip()
tokens = [token for token in rest.split() if token]
parsed = ParsedCommand(name=name, raw=stripped, arguments=tokens)
if name == "review":
if "--full" in tokens:
parsed.full = True
parsed.mode = "full"
for mode in ("security", "performance", "tests"):
if mode in tokens:
parsed.mode = mode
break
elif name == "fix":
parsed.branch_fix = "--branch" in tokens
return parsed