-
Notifications
You must be signed in to change notification settings - Fork 2
176 lines (162 loc) · 6.34 KB
/
Copy pathocr-review.yml
File metadata and controls
176 lines (162 loc) · 6.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# OpenCodeReview PR on-demand review — self-contained workflow for PUBLIC repos.
# GitHub only lets public caller repos invoke PUBLIC reusable workflows, so
# simulator-broker / agent-skills cannot call the private
# fiveonecode/workflows reusable. This file inlines the proven job body from
# that reusable (mirroring fiveonecode/ChattyFit) so these public repos still
# get OCR. LLM endpoint/key/model come from this repo's own OCR_LLM_*
# secrets/variables (repo-level, set on 2026-08-14).
name: OpenCodeReview PR Review
concurrency:
group: >-
${{
github.event.issue.pull_request
&& github.event.comment.user.type != 'Bot'
&& (
github.event.comment.author_association == 'MEMBER'
|| github.event.comment.author_association == 'OWNER'
|| github.event.comment.author_association == 'COLLABORATOR'
)
&& (
startsWith(github.event.comment.body, '/open-code-review')
|| startsWith(github.event.comment.body, '@open-code-review')
)
&& format('ocr-{0}', github.event.issue.number)
|| format('noop-{0}', github.run_id)
}}
cancel-in-progress: true
on:
issue_comment:
types: [created]
permissions:
contents: read
pull-requests: write
jobs:
code-review:
if: |
github.event.issue.pull_request
&& github.event.comment.user.type != 'Bot'
&& (
github.event.comment.author_association == 'MEMBER'
|| github.event.comment.author_association == 'OWNER'
|| github.event.comment.author_association == 'COLLABORATOR'
)
&& (
startsWith(github.event.comment.body, '/open-code-review')
|| startsWith(github.event.comment.body, '@open-code-review')
)
# Public-repository reviews run only after an authorized member requests one,
# on GitHub's free, ephemeral standard runner.
runs-on: ubuntu-latest
timeout-minutes: 240
steps:
- name: Get PR context
id: pr-context
uses: actions/github-script@v7
with:
script: |
const prNumber = context.issue.number;
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
core.setOutput('pr_number', String(prNumber));
core.setOutput('base_ref', pr.base.ref);
core.setOutput('head_sha', pr.head.sha);
core.setOutput('title', pr.title);
- name: Checkout base (trusted)
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Fetch PR head
env:
PR_NUM: ${{ steps.pr-context.outputs.pr_number }}
HEAD_SHA: ${{ steps.pr-context.outputs.head_sha }}
run: |
git fetch origin "pull/${PR_NUM}/head"
echo "HEAD_SHA=$HEAD_SHA" >> "$GITHUB_ENV"
- name: Compute merge-base
env:
HEAD_SHA: ${{ steps.pr-context.outputs.head_sha }}
run: |
git fetch origin "${{ steps.pr-context.outputs.base_ref }}" 2>/dev/null || true
MERGE_BASE=$(git merge-base "origin/${{ steps.pr-context.outputs.base_ref }}" "$HEAD_SHA" 2>/dev/null || echo "$HEAD_SHA")
echo "MERGE_BASE=$MERGE_BASE" >> "$GITHUB_ENV"
echo "Reviewing $HEAD_SHA from merge-base $MERGE_BASE"
- name: Checkout OpenCodeReview helpers
uses: actions/checkout@v7
with:
repository: alibaba/open-code-review
ref: v1.9.2
path: .ocr-upstream
sparse-checkout: |
scripts/github-actions
sparse-checkout-cone-mode: false
- name: Setup Node.js
uses: actions/setup-node@v7
with:
node-version: '22'
package-manager-cache: false
- name: Install OpenCodeReview
run: |
npm install --prefix "$RUNNER_TEMP/ocr" "@alibaba-group/open-code-review@1.9.2"
echo "$RUNNER_TEMP/ocr/node_modules/.bin" >> "$GITHUB_PATH"
"$RUNNER_TEMP/ocr/node_modules/.bin/ocr" version
- name: Configure OCR
run: |
ocr config set llm.extra_body '{"enable_thinking": false}'
ocr config set language English
- name: Run OpenCodeReview
env:
OCR_LLM_URL: ${{ secrets.OCR_LLM_URL }}
OCR_LLM_TOKEN: ${{ secrets.OCR_LLM_AUTH_TOKEN }}
OCR_LLM_MODEL: ${{ vars.OCR_LLM_MODEL }}
OCR_USE_ANTHROPIC: ${{ vars.OCR_LLM_USE_ANTHROPIC }}
OCR_LLM_TIMEOUT: '1200'
OCR_BACKGROUND: ${{ steps.pr-context.outputs.title }}
run: |
set +e
ocr review \
--from "${MERGE_BASE}" \
--to "${HEAD_SHA}" \
--format json \
--concurrency 4 \
--timeout 45 \
--background "${OCR_BACKGROUND}" \
> "$RUNNER_TEMP/ocr-result.json" 2>"$RUNNER_TEMP/ocr-stderr.log"
OCR_EXIT_CODE=$?
set -e
echo "OCR_EXIT_CODE=$OCR_EXIT_CODE" >> "$GITHUB_ENV"
echo "=== OCR result (first 200 lines) ==="
head -n 200 "$RUNNER_TEMP/ocr-result.json" || true
echo "=== OCR stderr (last 200 lines) ==="
tail -n 200 "$RUNNER_TEMP/ocr-stderr.log" || true
if [ "$OCR_EXIT_CODE" != "0" ]; then
echo "ocr review exited with code ${OCR_EXIT_CODE}"
exit "$OCR_EXIT_CODE"
fi
- name: Post review comments
uses: actions/github-script@v7
env:
OCR_INCREMENTAL_OVERLAP_THRESHOLD: '0.6'
with:
script: |
const path = require('path');
const fs = require('fs');
const helper = path.resolve('.ocr-upstream/scripts/github-actions/post-review-comments.js');
if (!fs.existsSync(helper)) {
throw new Error(`Missing helper at ${helper}`);
}
const { runPostReviewComments } = require(helper);
const runnerTemp = process.env.RUNNER_TEMP || '/tmp';
await runPostReviewComments({
github,
context,
core,
fs,
resultPath: path.join(runnerTemp, 'ocr-result.json'),
stderrPath: path.join(runnerTemp, 'ocr-stderr.log'),
stickySummary: true,
incremental: true,
incrementalOverlapThreshold: parseFloat(process.env.OCR_INCREMENTAL_OVERLAP_THRESHOLD),
});