-
Notifications
You must be signed in to change notification settings - Fork 2
164 lines (147 loc) · 5.91 KB
/
Copy pathai-plan.yml
File metadata and controls
164 lines (147 loc) · 5.91 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
name: AI Issue Planning
on:
issues:
types: [labeled]
permissions:
contents: read
issues: write
pull-requests: write
jobs:
ai-plan:
if: github.event.label.name == 'ai-task'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install OpenCode and oh-my-opencode
run: |
bun add -g opencode-ai
- name: Copy configs and setup
env:
MINIMAX_API_KEY: ${{ secrets.MINIMAX_API_KEY }}
run: |
mkdir -p ~/.config/opencode
# 复制并替换 opencode.json (本体配置)
sed "s/MINIMAX_API_KEY/${MINIMAX_API_KEY}/g" .github/workflows/opencode.json > ~/.config/opencode/opencode.json
# 复制并替换 oh-my-opencode.json (插件配置)
sed "s/MINIMAX_API_KEY/${MINIMAX_API_KEY}/g" .github/workflows/oh-my-opencode.json > ~/.config/opencode/oh-my-opencode.json
- name: Get issue details
id: issue
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const issue = context.payload.issue;
const { data: issueData } = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number
});
return JSON.stringify({
number: issue.number,
title: issue.title,
body: issueData.body,
url: issueData.html_url
});
- name: Check existing plan
id: find-comment
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const data = JSON.parse('${{ steps.issue.outputs.result }}');
const { data: comments } = await github.rest.issues.listComments({
issue_number: data.number,
owner: context.repo.owner,
repo: context.repo.repo
});
const aiComment = comments.find(c => c.body.includes('## AI Implementation Plan'));
return aiComment ? aiComment.id : 'none';
- name: Remove label if plan exists
if: steps.find-comment.outputs.result != 'none'
uses: actions/github-script@v7
with:
script: |
const data = JSON.parse('${{ steps.issue.outputs.result }}');
await github.rest.issues.removeLabel({
issue_number: data.number,
name: 'ai-task',
owner: context.repo.owner,
repo: context.repo.repo
});
- name: Generate plan
if: steps.find-comment.outputs.result == 'none'
id: opencode
env:
ISSUE_DATA: ${{ steps.issue.outputs.result }}
MINIMAX_API_KEY: ${{ secrets.MINIMAX_API_KEY }}
run: |
bun add -g opencode-ai
# 确保配置文件中的占位符被正确替换
sed "s/MINIMAX_API_KEY/${MINIMAX_API_KEY}/g" .github/workflows/opencode.json > ~/.config/opencode/opencode.json
sed "s/MINIMAX_API_KEY/${MINIMAX_API_KEY}/g" .github/workflows/oh-my-opencode.json > ~/.config/opencode/oh-my-opencode.json
node -e "
const fs=require('fs');
const d=JSON.parse(process.env.ISSUE_DATA);
let p=fs.readFileSync('.github/workflows/prompts/ai-plan-prompt.txt','utf8');
p=p.replace(/{{issue_number}}/g,d.number)
.replace(/{{issue_title}}/g,d.title)
.replace(/{{issue_body}}/g,d.body)
.replace(/{{issue_url}}/g,d.url);
fs.writeFileSync('prompt.txt',p);
"
opencode . < prompt.txt --opencode-go=yes
- name: Post plan comment
if: steps.opencode.outputs.result != '' && steps.find-comment.outputs.result == 'none'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const plan = fs.readFileSync('plan.md', 'utf8');
const data = JSON.parse('${{ steps.issue.outputs.result }}');
await github.rest.issues.createComment({
issue_number: data.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: plan
});
- name: Create branch
if: steps.opencode.outputs.result != '' && steps.find-comment.outputs.result == 'none'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
node -e "console.log('ai/issue-'+JSON.parse(process.env.ISSUE_DATA).number)" > branch_name.txt
git config user.name "AI Agent"
git config user.email "ai@github.local"
git checkout -b $(cat branch_name.txt) main || git checkout -b $(cat branch_name.txt) master
git push -u origin $(cat branch_name.txt) || echo Branch created locally
- name: Remove ai-task label after planning
if: steps.opencode.outputs.result != '' && steps.find-comment.outputs.result == 'none'
uses: actions/github-script@v7
with:
script: |
const data = JSON.parse('${{ steps.issue.outputs.result }}');
await github.rest.issues.removeLabel({
issue_number: data.number,
name: 'ai-task',
owner: context.repo.owner,
repo: context.repo.repo
});
- name: Cleanup label on failure
if: failure() && steps.find-comment.outputs.result == 'none'
uses: actions/github-script@v7
with:
script: |
const data = JSON.parse('${{ steps.issue.outputs.result }}');
await github.rest.issues.removeLabel({
issue_number: data.number,
name: 'ai-task',
owner: context.repo.owner,
repo: context.repo.repo
});