You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/codex/build_code_review_with_codex_sdk.md
+14-5Lines changed: 14 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,16 +4,18 @@ With [Code Review](https://chatgpt.com/codex/settings/code-review) in Codex Clou
4
4
5
5
Luckily, we can replicate Codex's cloud hosted review process in our own CI/CD runners. In this guide, we'll build our own Code Review action using the Codex CLI headless mode with both GitHub Actions and Jenkins.
6
6
7
-
To build our own Code review, we'll take the following steps:
7
+
To build our own Code review, we'll take the following stps:
8
+
8
9
1. Install the Codex CLI in our CI/CD runner
9
-
1. Prompt Codex in headless (exec) mode with the Code Review prompt that ships with the CLI
10
-
1. Specify a structured output JSON schema for Codex
11
-
1. Parse the JSON result and use it to make API calls to our SCM to create review comments
10
+
2. Prompt Codex in headless (exec) mode with the Code Review prompt that ships with the CLI
11
+
3. Specify a structured output JSON schema for Codex
12
+
4. Parse the JSON result and use it to make API calls to our SCM to create review comments
12
13
13
14
Once implemented, Codex will be able to leave inline code review comments:
14
-
<imgsrc="../../images/codex_code_review.png"alt="Codex Code Review in GitHub"width="500"/>
15
+
`<img src="../../images/codex_code_review.png" alt="Codex Code Review in GitHub" width="500"/>`
15
16
16
17
## The Code Review Prompt
18
+
17
19
GPT-5-Codex has received specific training to improve its code review abilities. You can steer GPT-5-Codex to conduct a code review with the following prompt:
18
20
19
21
```
@@ -25,7 +27,9 @@ Prioritize severe issues and avoid nit-level comments unless they block understa
25
27
After listing findings, produce an overall correctness verdict (\"patch is correct\" or \"patch is incorrect\") with a concise justification and a confidence score between 0 and 1.
26
28
Ensure that file citations and line numbers are exactly correct using the tools available; if they are incorrect your comments will be rejected.
27
29
```
30
+
28
31
## Codex Structured Outputs
32
+
29
33
In order to make comments on code ranges in our pull request, we need to receive Codex's response in a specific format. To do that we can create a file called `codex-output-schema.json` that conforms to OpenAI's [structured outputs](https://platform.openai.com/docs/guides/structured-outputs) format.
30
34
31
35
To use this file in our workflow YAML, we can call Codex with the `output-schema-file` argument like this:
Let's put it all together. If you're using GitHub Actions in an on-prem environment, you can tailor this example to your specific workflow. Inline comments highlight the key steps.
59
+
54
60
```yaml
55
61
name: Codex Code Review
56
62
@@ -331,6 +337,7 @@ jobs:
331
337
```
332
338
333
339
## Jenkins Example
340
+
334
341
We can use the same approach to scripting a job with Jenkins. Once again, comments highlight key stages of the workflow:
335
342
336
343
```groovy
@@ -650,5 +657,7 @@ pipeline {
650
657
}
651
658
}
652
659
```
660
+
653
661
# Wrap Up
662
+
654
663
With the Codex SDK, you can build your own GitHub Code Review in on-prem environments. However, the pattern of triggering Codex with a prompt, receiving a structured output, and then acting on that output with an API call extends far beyond Code Review. For example, we could use this pattern to trigger a root-cause analysis when an incident is created and post a structured report into a Slack channel. Or we could create a code quality report on each PR and post results into a dashboard.
0 commit comments