-
Notifications
You must be signed in to change notification settings - Fork 1
275 lines (230 loc) · 10.1 KB
/
ai-analysis.yml
File metadata and controls
275 lines (230 loc) · 10.1 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
name: AI Task Analysis
on:
workflow_dispatch:
inputs:
issue_number:
description: 'Issue number to analyze'
required: true
type: number
analysis_type:
description: 'Type of analysis'
required: true
default: 'comprehensive'
type: choice
options:
- comprehensive
- technical
- complexity
- dependencies
- implementation
permissions:
contents: read
issues: write
pull-requests: read
jobs:
analyze-task:
name: AI Task Analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup analysis environment
run: |
npm install openai @octokit/rest marked mermaid-cli yaml
- name: Fetch issue context
id: context
uses: actions/github-script@v7
with:
script: |
const issueNumber = ${{ github.event.inputs.issue_number }};
// Get issue details
const { data: issue } = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber
});
// Get related PRs
const { data: timeline } = await github.rest.issues.listEventsForTimeline({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber
});
const relatedPRs = timeline
.filter(event => event.event === 'cross-referenced' && event.source?.issue?.pull_request)
.map(event => event.source.issue.number);
// Get repository structure
const { data: tree } = await github.rest.git.getTree({
owner: context.repo.owner,
repo: context.repo.repo,
tree_sha: 'HEAD',
recursive: true
}).catch(() => ({ data: { tree: [] } }));
const fileStructure = tree.tree
.filter(item => item.type === 'blob')
.map(item => item.path);
core.setOutput('issue', JSON.stringify(issue));
core.setOutput('related_prs', JSON.stringify(relatedPRs));
core.setOutput('file_structure', JSON.stringify(fileStructure));
- name: Perform AI analysis
id: analysis
uses: actions/github-script@v7
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
with:
script: |
const OpenAI = require('openai');
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const issue = JSON.parse('${{ steps.context.outputs.issue }}');
const fileStructure = JSON.parse('${{ steps.context.outputs.file_structure }}');
const analysisType = '${{ github.event.inputs.analysis_type }}';
const systemPrompts = {
comprehensive: `You are an expert software architect performing comprehensive task analysis.
Analyze all aspects including technical complexity, implementation approach,
testing requirements, and potential risks.`,
technical: `You are a senior engineer analyzing technical implementation details.
Focus on code architecture, design patterns, technology choices,
and implementation specifics.`,
complexity: `You are a project manager analyzing task complexity and effort estimation.
Focus on breaking down complexity, identifying challenges,
and providing accurate time/effort estimates.`,
dependencies: `You are a systems analyst identifying task dependencies and relationships.
Map out all dependencies, both technical and logical,
and suggest optimal execution order.`,
implementation: `You are an AI coding assistant planning implementation strategy.
Provide specific code structure, file modifications,
and step-by-step implementation plan.`
};
const analysis = await openai.chat.completions.create({
model: "gpt-4",
messages: [{
role: "system",
content: systemPrompts[analysisType]
}, {
role: "user",
content: `Analyze this GitHub issue and provide detailed ${analysisType} analysis:
Issue Title: ${issue.title}
Issue Body: ${issue.body}
Labels: ${issue.labels.map(l => l.name).join(', ')}
Repository Structure Summary:
- Total files: ${fileStructure.length}
- Key directories: ${[...new Set(fileStructure.map(f => f.split('/')[0]))].join(', ')}
Provide analysis in markdown format with:
1. Executive Summary
2. Detailed Analysis
3. Recommendations
4. Implementation Plan (if applicable)
5. Risk Assessment
6. Success Metrics`
}],
temperature: 0.3,
max_tokens: 4000
});
return analysis.choices[0].message.content;
- name: Generate visual diagrams
id: diagrams
run: |
cat > architecture.mmd << 'EOF'
graph TD
A[Issue Analysis] --> B[Task Decomposition]
B --> C[Subtask 1]
B --> D[Subtask 2]
B --> E[Subtask 3]
C --> F[Implementation]
D --> F
E --> F
F --> G[Testing]
G --> H[Deployment]
EOF
npx mmdc -i architecture.mmd -o architecture.png
- name: Post analysis results
uses: actions/github-script@v7
with:
script: |
const issueNumber = ${{ github.event.inputs.issue_number }};
const analysisType = '${{ github.event.inputs.analysis_type }}';
const analysis = `${{ steps.analysis.outputs.result }}`;
// Create detailed comment with analysis
const comment = `# 🤖 AI ${analysisType.charAt(0).toUpperCase() + analysisType.slice(1)} Analysis
${analysis}
## 📊 Analysis Metadata
- Analysis Type: **${analysisType}**
- Performed At: **${new Date().toISOString()}**
- Model: **GPT-4**
- Confidence Level: **High**
## 🔄 Next Steps
1. Review the analysis above
2. Use \`/ai-execute implement\` to start implementation
3. Or use \`/ai-execute analyze [type]\` for different analysis
---
<details>
<summary>🛠 Available Commands</summary>
- \`/ai-execute analyze comprehensive\` - Full analysis
- \`/ai-execute analyze technical\` - Technical deep dive
- \`/ai-execute analyze complexity\` - Complexity assessment
- \`/ai-execute analyze dependencies\` - Dependency mapping
- \`/ai-execute analyze implementation\` - Implementation strategy
- \`/ai-execute implement\` - Start AI implementation
- \`/ai-execute review\` - AI code review
</details>`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: comment
});
// Update issue labels based on analysis
const labels = ['ai-analyzed', `analysis:${analysisType}`];
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels
});
generate-implementation-plan:
name: Generate Implementation Plan
runs-on: ubuntu-latest
needs: analyze-task
if: github.event.inputs.analysis_type == 'implementation'
steps:
- uses: actions/checkout@v4
- name: Create implementation checklist
uses: actions/github-script@v7
with:
script: |
const issueNumber = ${{ github.event.inputs.issue_number }};
// Create implementation checklist as a new comment
const checklist = `## 📋 Implementation Checklist
### Pre-Implementation
- [ ] Review AI analysis
- [ ] Validate technical approach
- [ ] Set up development environment
- [ ] Create feature branch
### Implementation
- [ ] Implement core functionality
- [ ] Add unit tests
- [ ] Add integration tests
- [ ] Update documentation
- [ ] Add inline code comments
### Testing
- [ ] Run unit tests locally
- [ ] Run integration tests
- [ ] Manual testing
- [ ] Cross-browser testing (if applicable)
- [ ] Performance testing
### Code Quality
- [ ] Run linter
- [ ] Run type checker
- [ ] Code review self-check
- [ ] Security scan
### Finalization
- [ ] Update CHANGELOG
- [ ] Create pull request
- [ ] Address review feedback
- [ ] Merge to main branch
---
Use \`/ai-execute implement\` to start automated implementation with AI assistance.`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: checklist
});