-
Notifications
You must be signed in to change notification settings - Fork 3
89 lines (79 loc) · 3.34 KB
/
Copy pathcodex-review.yml
File metadata and controls
89 lines (79 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: Codex Review
on:
pull_request:
types: [opened, synchronize, reopened]
concurrency:
group: codex-review-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
codex:
runs-on: ubuntu-latest
# Only run for same-repo (non-fork) PRs by users with write access
if: >-
github.event.pull_request.head.repo.full_name == github.repository &&
contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.pull_request.author_association)
permissions:
contents: read
outputs:
final_message: ${{ steps.run_codex.outputs.final-message }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
- name: Pre-fetch base and head refs for the PR
env:
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
# Pass GitHub expressions through env and quote shell expansions.
git fetch --no-tags origin \
"$PR_BASE_REF" \
"+refs/pull/$PR_NUMBER/head"
- name: Run Codex
id: run_codex
uses: openai/codex-action@52fe01ec70a42f454c9d2ebd47598f9fd6893d56 # v1.11.0
with:
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
permission-profile: ":read-only"
prompt: |
This is PR #${{ github.event.pull_request.number }} for ${{ github.repository }}.
Review ONLY the changes introduced by the PR, so consider:
git log --oneline ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }}
Suggest any improvements, potential bugs, or issues.
Be concise and specific in your feedback.
For each finding, begin the line with a bolded severity in the form
**Severity: <level>** — where <level> is Critical, High, Medium, or
Low — judged by potential impact and relevance to the changes made.
post_feedback:
runs-on: ubuntu-latest
needs: codex
if: needs.codex.outputs.final_message != ''
permissions:
issues: write
pull-requests: write
steps:
- name: Report Codex feedback
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
CODEX_FINAL_MESSAGE: ${{ needs.codex.outputs.final_message }}
with:
github-token: ${{ github.token }}
script: |
const marker = '<!-- codex-review -->';
const body = `${marker}\n${process.env.CODEX_FINAL_MESSAGE}`;
const { owner, repo } = context.repo;
const issue_number = context.payload.pull_request.number;
const existing = await github.paginate(github.rest.issues.listComments, {
owner,
repo,
issue_number,
});
const previous = existing.find(
(c) => c.user?.login === 'github-actions[bot]' && c.body?.startsWith(marker),
);
if (previous) {
await github.rest.issues.updateComment({ owner, repo, comment_id: previous.id, body });
} else {
await github.rest.issues.createComment({ owner, repo, issue_number, body });
}