[fix]. Restore PR-scoped review + remove fix cmd
This commit is contained in:
@@ -64,8 +64,12 @@ def run_review_ephemeral(
|
||||
gitea = GiteaClient(settings)
|
||||
pr = gitea.get_pull_request(repo, pr_number)
|
||||
repo_cfg = _load_repo_review_config_from_gitea(gitea, repo, pr.head_sha)
|
||||
review_prompt = _build_exec_review_prompt(command)
|
||||
_apply_repo_default_review_mode(command, repo_cfg)
|
||||
review_prompt = _build_exec_review_prompt(command, repo_cfg, pr)
|
||||
container_name = f"codex-review-{uuid.uuid4().hex[:12]}"
|
||||
marker_nonce = uuid.uuid4().hex
|
||||
result_start_marker = f"{RESULT_START_MARKER}_{marker_nonce}"
|
||||
result_end_marker = f"{RESULT_END_MARKER}_{marker_nonce}"
|
||||
extra_env: dict[str, str] = {
|
||||
"GITEA_TOKEN": settings.gitea_token.get_secret_value(),
|
||||
"GITEA_GIT_USERNAME": settings.gitea_bot_username,
|
||||
@@ -84,11 +88,17 @@ def run_review_ephemeral(
|
||||
pr=pr,
|
||||
container_name=container_name,
|
||||
review_prompt=review_prompt,
|
||||
result_start_marker=result_start_marker,
|
||||
result_end_marker=result_end_marker,
|
||||
extra_env=extra_env,
|
||||
)
|
||||
if completed.returncode != 0:
|
||||
raise RuntimeError(_format_runner_failure(completed))
|
||||
parsed = _parse_review_result_from_stdout_artifact(completed.stdout)
|
||||
parsed = _parse_review_result_from_stdout_artifact(
|
||||
completed.stdout,
|
||||
result_start_marker=result_start_marker,
|
||||
result_end_marker=result_end_marker,
|
||||
)
|
||||
parsed["_meta"] = _extract_result_meta_from_codex_stdout(completed.stdout, settings)
|
||||
return normalize_review_result(parsed), repo_cfg
|
||||
except Exception as exc:
|
||||
@@ -102,9 +112,17 @@ def _run_ephemeral_container(
|
||||
pr: PullRequestContext,
|
||||
container_name: str,
|
||||
review_prompt: str,
|
||||
result_start_marker: str,
|
||||
result_end_marker: str,
|
||||
extra_env: dict[str, str],
|
||||
) -> subprocess.CompletedProcess[str]:
|
||||
install_and_run = _build_install_and_run_command(settings, pr=pr, review_prompt=review_prompt)
|
||||
install_and_run = _build_install_and_run_command(
|
||||
settings,
|
||||
pr=pr,
|
||||
review_prompt=review_prompt,
|
||||
result_start_marker=result_start_marker,
|
||||
result_end_marker=result_end_marker,
|
||||
)
|
||||
cmd = _build_docker_command(settings, container_name=container_name, install_and_run=install_and_run)
|
||||
return subprocess.run(
|
||||
cmd,
|
||||
@@ -121,6 +139,8 @@ def _build_install_and_run_command(
|
||||
*,
|
||||
pr: PullRequestContext,
|
||||
review_prompt: str,
|
||||
result_start_marker: str,
|
||||
result_end_marker: str,
|
||||
) -> str:
|
||||
steps = ["set -euo pipefail"]
|
||||
if settings.codex_auth_mode != "chatgpt":
|
||||
@@ -190,23 +210,45 @@ def _build_install_and_run_command(
|
||||
steps.extend(
|
||||
[
|
||||
" ".join(codex_exec_parts),
|
||||
f'echo "{RESULT_START_MARKER}"',
|
||||
f'echo "{result_start_marker}"',
|
||||
f"cat {shlex.quote(REVIEW_OUTPUT_FILE)}",
|
||||
f'echo "{RESULT_END_MARKER}"',
|
||||
f'echo "{result_end_marker}"',
|
||||
]
|
||||
)
|
||||
return "\n".join(steps)
|
||||
|
||||
|
||||
def _build_exec_review_prompt(command: ParsedCommand) -> str:
|
||||
def _apply_repo_default_review_mode(command: ParsedCommand, repo_cfg: RepoReviewConfig) -> None:
|
||||
if command.name != "review" or command.mode_explicit:
|
||||
return
|
||||
configured_mode = repo_cfg.default_mode
|
||||
command.mode = configured_mode if configured_mode in {"summary", "security", "performance", "tests", "full"} else "summary"
|
||||
|
||||
|
||||
def _build_exec_review_prompt(command: ParsedCommand, repo_cfg: RepoReviewConfig, pr: PullRequestContext) -> str:
|
||||
raw = (command.raw or "").strip()
|
||||
remainder = raw
|
||||
match = re.match(r"^@[^\s]+\s+\S+\s*(.*)$", raw, flags=re.IGNORECASE | re.DOTALL)
|
||||
if match:
|
||||
remainder = match.group(1).strip()
|
||||
if not remainder:
|
||||
return "review: review this pull request and report introduced issues."
|
||||
return f"review: {remainder}"
|
||||
intent = remainder or "review this pull request and report introduced issues."
|
||||
focus = ", ".join(repo_cfg.focus) if repo_cfg.focus else "correctness, security, maintainability"
|
||||
ignore = ", ".join(repo_cfg.ignore) if repo_cfg.ignore else "(none)"
|
||||
mode = command.mode if command.name in {"review", "rerun"} else "summary"
|
||||
return "\n".join(
|
||||
[
|
||||
f"review: {intent}",
|
||||
"Review only issues introduced by this PR.",
|
||||
f"Compare exactly these commits: base `{pr.base_sha}` ... head `{pr.head_sha}`.",
|
||||
"Use local git data from this checkout; do not review unrelated history.",
|
||||
f"Requested mode: {mode}.",
|
||||
f"Focus areas: {focus}.",
|
||||
f"Ignore patterns: {ignore}.",
|
||||
f"Include tests setting: {repo_cfg.include_tests}.",
|
||||
f"Full review requested: {command.full}.",
|
||||
"Return strict JSON matching the provided output schema.",
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def _build_docker_command(settings: Settings, *, container_name: str, install_and_run: str) -> list[str]:
|
||||
@@ -323,12 +365,27 @@ def _load_repo_review_config_from_gitea(gitea: GiteaClient, repo: str, head_sha:
|
||||
return parse_repo_review_config_text(content, configured=True)
|
||||
|
||||
|
||||
def _parse_review_result_from_stdout_artifact(stdout: str) -> dict[str, Any]:
|
||||
start = stdout.find(RESULT_START_MARKER)
|
||||
end = stdout.find(RESULT_END_MARKER)
|
||||
if start == -1 or end == -1 or end <= start:
|
||||
def _parse_review_result_from_stdout_artifact(
|
||||
stdout: str,
|
||||
*,
|
||||
result_start_marker: str,
|
||||
result_end_marker: str,
|
||||
) -> dict[str, Any]:
|
||||
lines = stdout.splitlines()
|
||||
start_idx = -1
|
||||
end_idx = -1
|
||||
for idx, line in enumerate(lines):
|
||||
if line.strip() == result_start_marker:
|
||||
start_idx = idx
|
||||
break
|
||||
if start_idx != -1:
|
||||
for idx in range(start_idx + 1, len(lines)):
|
||||
if lines[idx].strip() == result_end_marker:
|
||||
end_idx = idx
|
||||
break
|
||||
if start_idx == -1 or end_idx == -1 or end_idx <= start_idx:
|
||||
raise RuntimeError("Runner output did not include final review artifact markers.")
|
||||
artifact = stdout[start + len(RESULT_START_MARKER) : end].strip()
|
||||
artifact = "\n".join(lines[start_idx + 1 : end_idx]).strip()
|
||||
if not artifact:
|
||||
raise RuntimeError("Runner output contained empty final review artifact.")
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user