Skip to content

Commit 194d6c2

Browse files
committed
ci: add opencode review workflow for PR comments
1 parent db4dab3 commit 194d6c2

1 file changed

Lines changed: 112 additions & 0 deletions

File tree

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: opencode-review
2+
3+
on:
4+
# issue_comment covers both issues and PR comments
5+
issue_comment:
6+
types: [created]
7+
pull_request_review_comment:
8+
types: [created]
9+
10+
jobs:
11+
review:
12+
# Only trigger in PRs (not issues), and require /review or /opencode trigger
13+
if: |
14+
(
15+
github.event_name == 'issue_comment' &&
16+
github.event.issue.pull_request &&
17+
(
18+
contains(github.event.comment.body, '/review') ||
19+
contains(github.event.comment.body, '/opencode')
20+
)
21+
) ||
22+
(
23+
github.event_name == 'pull_request_review_comment' &&
24+
(
25+
contains(github.event.comment.body, '/review') ||
26+
contains(github.event.comment.body, '/opencode')
27+
)
28+
)
29+
runs-on: ubuntu-latest
30+
permissions:
31+
contents: read # Change to 'write' to allow OpenCode to push commits
32+
pull-requests: write # Required to post comments (kept as write for responses)
33+
issues: read # Change to 'write' if you enable issue workflows later
34+
actions: read # Required to read CI results on PRs
35+
id-token: write # Required for OIDC token generation (OpenCode GitHub App)
36+
steps:
37+
- uses: actions/checkout@v6
38+
with:
39+
persist-credentials: false
40+
- uses: anomalyco/opencode/github@latest
41+
env:
42+
# ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
43+
ZHIPU_API_KEY: ${{ secrets.ZHIPU_API_KEY }}
44+
ZHIPU_BASE_URL: ${{ secrets.ZHIPU_BASE_URL }}
45+
# with:
46+
# # model: anthropic/claude-sonnet-4-20250514
47+
# model: zai-coding-plan/glm-4.7
48+
# use_github_token: true
49+
# prompt: |
50+
# Review this pull request:
51+
# - Check for code quality issues
52+
# - Look for potential bugs
53+
# - Suggest improvements
54+
with:
55+
model: ${{ secrets.OPENCODE_PR_REVIEW_MODEL }}
56+
share: false
57+
agent: plan
58+
prompt: |
59+
你是一位严格的代码安全审计员。请对代码变更进行审查。
60+
61+
【审查原则 - 去噪模式】:
62+
- **只报告高风险问题**:例如导致崩溃、安全漏洞、数据丢失、构建失败、严重的逻辑错误。
63+
- **忽略以下问题**:代码风格、变量命名、微小的性能优化、非确定性的潜在问题。
64+
- 如果不确定,不要报告。
65+
- 如果没有高风险问题,请回复:"No critical risks found."
66+
67+
【输出格式要求】:
68+
69+
第一部分:具体风险建议(供人阅读)
70+
针对每一个高风险问题,请按以下格式输出:
71+
suggestion (bug_risk): [一句话概括核心问题]
72+
[简短解释原因]
73+
Suggested implementation:
74+
```[语言]
75+
[修复代码片段]
76+
```
77+
78+
第二部分:AI 修复指令汇总(供 AI Agent 使用)
79+
请严格遵循以下格式生成 "Prompt for AI Agents" 部分。
80+
**特别注意**:为了防止 Markdown 嵌套导致截断,在 XML 标签内部展示代码时,**严禁使用三重反引号 (\`\`\`)**,请使用 **4个空格缩进** 来代替代码块标记。
81+
82+
Prompt for AI Agents:
83+
```markdown
84+
Please address the comments from this code review:
85+
86+
## Overall Comments
87+
[在此处填写通用性总结。重点说明:本次审查旨在解决什么核心风险?修复这些问题的最终目标是什么?(例如:确保系统升级的稳定性、消除潜在的崩溃隐患等)。若无明显整体风险,请写 "No overall comments."]
88+
89+
## Individual Comments
90+
91+
### Comment [序号]
92+
<location> `[文件路径]:[起始行]-[结束行]` </location>
93+
<code_context>
94+
[粘贴该位置有问题的原始代码上下文]
95+
</code_context>
96+
97+
<issue_to_address>
98+
**suggestion (bug_risk):** [问题标题]
99+
100+
[详细原因说明]
101+
102+
Suggested implementation:
103+
104+
[注意:此处代码应使用 4 个空格缩进,不要使用 ``` 符号,否则会被截断]
105+
[例如:]
106+
Package: dde-cooperation
107+
Architecture: any
108+
Breaks: old-package
109+
</issue_to_address>
110+
```
111+
112+
开始审查:

0 commit comments

Comments
 (0)