Skip to main content

codex/commands/
review.rs

1use std::ffi::OsString;
2
3use crate::{
4    ApplyDiffArtifacts, CodexClient, CodexError, ExecReviewCommandRequest, ReviewCommandRequest,
5};
6
7impl CodexClient {
8    /// Runs `codex review [OPTIONS] [PROMPT]` and returns captured output.
9    pub async fn review(
10        &self,
11        request: ReviewCommandRequest,
12    ) -> Result<ApplyDiffArtifacts, CodexError> {
13        if matches!(request.prompt.as_deref(), Some(prompt) if prompt.trim().is_empty()) {
14            return Err(CodexError::EmptyPrompt);
15        }
16
17        let mut args = vec![OsString::from("review")];
18        if let Some(base) = request.base {
19            if !base.trim().is_empty() {
20                args.push(OsString::from("--base"));
21                args.push(OsString::from(base));
22            }
23        }
24        if let Some(commit) = request.commit {
25            if !commit.trim().is_empty() {
26                args.push(OsString::from("--commit"));
27                args.push(OsString::from(commit));
28            }
29        }
30        if let Some(title) = request.title {
31            if !title.trim().is_empty() {
32                args.push(OsString::from("--title"));
33                args.push(OsString::from(title));
34            }
35        }
36        if request.uncommitted {
37            args.push(OsString::from("--uncommitted"));
38        }
39        if let Some(prompt) = request.prompt {
40            if !prompt.trim().is_empty() {
41                args.push(OsString::from(prompt));
42            }
43        }
44
45        self.run_simple_command_with_overrides(args, request.overrides)
46            .await
47    }
48
49    /// Runs `codex exec review [OPTIONS] [PROMPT]` and returns captured output.
50    pub async fn exec_review(
51        &self,
52        request: ExecReviewCommandRequest,
53    ) -> Result<ApplyDiffArtifacts, CodexError> {
54        if matches!(request.prompt.as_deref(), Some(prompt) if prompt.trim().is_empty()) {
55            return Err(CodexError::EmptyPrompt);
56        }
57
58        let mut args = vec![OsString::from("exec"), OsString::from("review")];
59        if let Some(base) = request.base {
60            if !base.trim().is_empty() {
61                args.push(OsString::from("--base"));
62                args.push(OsString::from(base));
63            }
64        }
65        if let Some(commit) = request.commit {
66            if !commit.trim().is_empty() {
67                args.push(OsString::from("--commit"));
68                args.push(OsString::from(commit));
69            }
70        }
71        if request.json {
72            args.push(OsString::from("--json"));
73        }
74        if request.skip_git_repo_check {
75            args.push(OsString::from("--skip-git-repo-check"));
76        }
77        if let Some(title) = request.title {
78            if !title.trim().is_empty() {
79                args.push(OsString::from("--title"));
80                args.push(OsString::from(title));
81            }
82        }
83        if request.uncommitted {
84            args.push(OsString::from("--uncommitted"));
85        }
86        if let Some(prompt) = request.prompt {
87            if !prompt.trim().is_empty() {
88                args.push(OsString::from(prompt));
89            }
90        }
91
92        self.run_simple_command_with_overrides(args, request.overrides)
93            .await
94    }
95}