31 lines
915 B
Python
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
|