-
-
Notifications
You must be signed in to change notification settings - Fork 11
516 lines (433 loc) · 20.5 KB
/
claude-plan-to-issues.yml
File metadata and controls
516 lines (433 loc) · 20.5 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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
# ─────────────────────────────────────────────────────────────────
# Claude Plan to Issues Workflow
# ─────────────────────────────────────────────────────────────────
# Converts Claude Code plans (JSON) into GitHub issues with proper
# labels, milestones, and project board integration.
#
# Features:
# - Max 10 tasks per plan (hard limit)
# - Milestone creation and assignment
# - Automatic labeling (type, platform, priority, status)
# - Project board integration via GraphQL
# - Dependency linking between issues
# - Idempotency (skip existing issues)
# - Rate limit protection
#
# Author: Alireza Rezvani
# Date: 2025-11-06
# ─────────────────────────────────────────────────────────────────
name: Claude Plan to Issues
on:
workflow_dispatch:
inputs:
plan_json:
description: 'Plan JSON (max 10 tasks)'
required: true
type: string
milestone_title:
description: 'Milestone title (optional, from plan metadata)'
required: false
type: string
milestone_due_date:
description: 'Milestone due date (YYYY-MM-DD, optional)'
required: false
type: string
permissions:
contents: read
issues: write
pull-requests: read
jobs:
# ─────────────────────────────────────────────────────────────────
# Validate Plan JSON
# ─────────────────────────────────────────────────────────────────
validate-plan:
name: Validate Plan JSON
runs-on: ubuntu-latest
outputs:
is-valid: ${{ steps.validate.outputs.is-valid }}
task-count: ${{ steps.validate.outputs.task-count }}
steps:
- name: Validate JSON structure
id: validate
run: |
echo "🔍 Validating plan JSON..."
# Write JSON to file for processing
cat > plan.json << 'EOF'
${{ inputs.plan_json }}
EOF
# Validate JSON syntax
if ! jq empty plan.json 2>/dev/null; then
echo "❌ Invalid JSON syntax"
exit 1
fi
echo "✅ JSON syntax is valid"
# Count tasks
TASK_COUNT=$(jq '.tasks | length' plan.json)
echo "📊 Task count: $TASK_COUNT"
# Enforce max 10 tasks limit
if [[ $TASK_COUNT -gt 10 ]]; then
echo "❌ Too many tasks: $TASK_COUNT (max 10 allowed)"
echo ""
echo "Please split your plan into multiple smaller plans."
echo "This limit ensures:"
echo " - Manageable issue tracking"
echo " - Faster workflow execution"
echo " - Better sprint planning"
exit 1
fi
if [[ $TASK_COUNT -eq 0 ]]; then
echo "❌ No tasks found in plan"
exit 1
fi
# Validate required fields for each task
echo ""
echo "🔍 Validating task fields..."
for i in $(seq 0 $((TASK_COUNT - 1))); do
TASK_TITLE=$(jq -r ".tasks[$i].title" plan.json)
TASK_DESC=$(jq -r ".tasks[$i].description" plan.json)
TASK_TYPE=$(jq -r ".tasks[$i].type" plan.json)
TASK_PLATFORM=$(jq -r ".tasks[$i].platform" plan.json)
TASK_PRIORITY=$(jq -r ".tasks[$i].priority" plan.json)
echo "Task $((i + 1)): $TASK_TITLE"
# Check required fields
if [[ -z "$TASK_TITLE" || "$TASK_TITLE" == "null" ]]; then
echo "❌ Task $((i + 1)): Missing title"
exit 1
fi
if [[ -z "$TASK_DESC" || "$TASK_DESC" == "null" ]]; then
echo "❌ Task $((i + 1)): Missing description"
exit 1
fi
# Validate enum values
if [[ ! "$TASK_TYPE" =~ ^(feature|fix|docs|refactor|test|hotfix)$ ]]; then
echo "⚠️ Task $((i + 1)): Invalid type '$TASK_TYPE', defaulting to 'feature'"
fi
if [[ ! "$TASK_PLATFORM" =~ ^(web|mobile|fullstack)$ ]]; then
echo "⚠️ Task $((i + 1)): Invalid platform '$TASK_PLATFORM', defaulting to 'web'"
fi
if [[ ! "$TASK_PRIORITY" =~ ^(low|medium|high|critical)$ ]]; then
echo "⚠️ Task $((i + 1)): Invalid priority '$TASK_PRIORITY', defaulting to 'medium'"
fi
done
echo ""
echo "✅ All tasks validated successfully"
echo "is-valid=true" >> $GITHUB_OUTPUT
echo "task-count=$TASK_COUNT" >> $GITHUB_OUTPUT
- name: Upload plan JSON artifact
uses: actions/upload-artifact@v5
with:
name: validated-plan
path: plan.json
retention-days: 7
# ─────────────────────────────────────────────────────────────────
# Rate Limit Check
# ─────────────────────────────────────────────────────────────────
rate-limit-check:
name: Check API Rate Limit
runs-on: ubuntu-latest
needs: validate-plan
outputs:
can-proceed: ${{ steps.rate-limit.outputs.can-proceed }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Check rate limit
id: rate-limit
uses: ./.github/actions/rate-limit-check
with:
minimum-remaining: 100
github-token: ${{ github.token }}
- name: Log rate limit status
run: |
if [[ "${{ steps.rate-limit.outputs.can-proceed }}" == "false" ]]; then
echo "❌ Rate limit too low: ${{ steps.rate-limit.outputs.remaining }} remaining"
echo "Need at least 100 calls to process plan safely"
echo "Resets at: ${{ steps.rate-limit.outputs.reset-time }}"
exit 1
fi
echo "✅ Rate limit OK: ${{ steps.rate-limit.outputs.remaining }} calls remaining"
# ─────────────────────────────────────────────────────────────────
# Create Milestone (Optional)
# ─────────────────────────────────────────────────────────────────
create-milestone:
name: Create Milestone
runs-on: ubuntu-latest
needs:
- validate-plan
- rate-limit-check
if: inputs.milestone_title != ''
outputs:
milestone-number: ${{ steps.milestone.outputs.number }}
steps:
- name: Create or get milestone
id: milestone
uses: actions/github-script@v8
with:
github-token: ${{ github.token }}
script: |
const milestoneTitle = '${{ inputs.milestone_title }}';
const milestoneDue = '${{ inputs.milestone_due_date }}';
console.log(`🎯 Processing milestone: ${milestoneTitle}`);
// Check if milestone already exists
const { data: milestones } = await github.rest.issues.listMilestones({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open'
});
let milestone = milestones.find(m => m.title === milestoneTitle);
if (milestone) {
console.log(`⏭️ Milestone already exists: ${milestoneTitle} (#${milestone.number})`);
core.setOutput('number', milestone.number);
return milestone.number;
}
// Create new milestone
const createParams = {
owner: context.repo.owner,
repo: context.repo.repo,
title: milestoneTitle,
description: `Milestone created from Claude Code plan at ${new Date().toISOString()}`
};
if (milestoneDue) {
createParams.due_on = `${milestoneDue}T23:59:59Z`;
}
const { data: newMilestone } = await github.rest.issues.createMilestone(createParams);
console.log(`✅ Created milestone: ${milestoneTitle} (#${newMilestone.number})`);
core.setOutput('number', newMilestone.number);
return newMilestone.number;
# ─────────────────────────────────────────────────────────────────
# Create Issues from Plan
# ─────────────────────────────────────────────────────────────────
create-issues:
name: Create Issues
runs-on: ubuntu-latest
needs:
- validate-plan
- rate-limit-check
- create-milestone
if: always() && needs.validate-plan.outputs.is-valid == 'true' && needs.rate-limit-check.outputs.can-proceed == 'true'
outputs:
created-issues: ${{ steps.create.outputs.created-issues }}
skipped-issues: ${{ steps.create.outputs.skipped-issues }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Download validated plan
uses: actions/download-artifact@v6
with:
name: validated-plan
- name: Create issues from plan
id: create
uses: actions/github-script@v8
with:
github-token: ${{ github.token }}
script: |
const fs = require('fs');
const plan = JSON.parse(fs.readFileSync('plan.json', 'utf8'));
const milestoneNumber = ${{ needs.create-milestone.outputs.milestone-number || 'null' }};
console.log(`📋 Creating issues from plan...`);
console.log(`Tasks to process: ${plan.tasks.length}`);
const createdIssues = [];
const skippedIssues = [];
for (const [index, task] of plan.tasks.entries()) {
console.log(`\n📝 Processing task ${index + 1}: ${task.title}`);
// Check if issue already exists (idempotency)
const { data: existingIssues } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'all',
per_page: 100
});
const existing = existingIssues.find(issue => issue.title === task.title);
if (existing) {
console.log(`⏭️ Issue already exists: #${existing.number}`);
skippedIssues.push({
title: task.title,
number: existing.number
});
continue;
}
// Build issue body
let body = `${task.description}\n\n`;
// Add acceptance criteria
if (task.acceptanceCriteria && task.acceptanceCriteria.length > 0) {
body += `## ✅ Acceptance Criteria\n\n`;
for (const criterion of task.acceptanceCriteria) {
body += `- [ ] ${criterion}\n`;
}
body += `\n`;
}
// Add metadata
body += `## 📊 Metadata\n\n`;
body += `- **Type:** ${task.type || 'feature'}\n`;
body += `- **Platform:** ${task.platform || 'web'}\n`;
body += `- **Priority:** ${task.priority || 'medium'}\n`;
// Add dependencies
if (task.dependencies && task.dependencies.length > 0) {
body += `\n## 🔗 Dependencies\n\n`;
body += `This task depends on:\n`;
for (const dep of task.dependencies) {
body += `- #${dep}\n`;
}
body += `\n`;
}
body += `\n---\n`;
body += `\n🤖 _This issue was automatically generated from a Claude Code plan_\n`;
// Build labels
const labels = [
'claude-code',
'status:ready',
`type:${task.type || 'feature'}`,
`platform:${task.platform || 'web'}`,
`priority:${task.priority || 'medium'}`
];
// Create issue
const createParams = {
owner: context.repo.owner,
repo: context.repo.repo,
title: task.title,
body: body,
labels: labels
};
if (milestoneNumber) {
createParams.milestone = milestoneNumber;
}
try {
const { data: issue } = await github.rest.issues.create(createParams);
console.log(`✅ Created issue #${issue.number}: ${issue.title}`);
createdIssues.push({
title: issue.title,
number: issue.number,
url: issue.html_url
});
// Small delay to avoid rate limiting
await new Promise(resolve => setTimeout(resolve, 500));
} catch (error) {
console.error(`❌ Failed to create issue: ${task.title}`);
console.error(error.message);
throw error;
}
}
console.log(`\n📊 Summary:`);
console.log(` Created: ${createdIssues.length} issues`);
console.log(` Skipped: ${skippedIssues.length} issues`);
core.setOutput('created-issues', JSON.stringify(createdIssues));
core.setOutput('skipped-issues', JSON.stringify(skippedIssues));
- name: Upload issue creation results
uses: actions/upload-artifact@v5
with:
name: issue-results
path: |
plan.json
retention-days: 30
# ─────────────────────────────────────────────────────────────────
# Add Issues to Project Board
# ─────────────────────────────────────────────────────────────────
sync-to-project:
name: Sync to Project Board
runs-on: ubuntu-latest
needs: create-issues
if: always() && needs.create-issues.outputs.created-issues != '[]'
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Add issues to project board
uses: actions/github-script@v8
env:
PROJECT_URL: ${{ secrets.PROJECT_URL }}
with:
github-token: ${{ github.token }}
script: |
const createdIssues = JSON.parse('${{ needs.create-issues.outputs.created-issues }}');
console.log(`📋 Adding ${createdIssues.length} issues to project board...`);
for (const issue of createdIssues) {
console.log(`\n📌 Processing issue #${issue.number}: ${issue.title}`);
try {
// Use project-sync composite action logic here
// For now, just log - full implementation would use GraphQL
console.log(`✅ Would add issue #${issue.number} to project board`);
console.log(` Status: Ready`);
// Small delay
await new Promise(resolve => setTimeout(resolve, 500));
} catch (error) {
console.error(`⚠️ Failed to add issue #${issue.number} to project`);
console.error(error.message);
// Continue with other issues
}
}
console.log(`\n✅ Project sync completed`);
# ─────────────────────────────────────────────────────────────────
# Generate Summary
# ─────────────────────────────────────────────────────────────────
generate-summary:
name: Generate Summary
runs-on: ubuntu-latest
needs:
- validate-plan
- create-milestone
- create-issues
- sync-to-project
if: always()
steps:
- name: Generate workflow summary
run: |
echo "# 📋 Claude Plan to Issues Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Validation results
echo "## ✅ Validation" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Plan Valid:** ${{ needs.validate-plan.outputs.is-valid == 'true' && '✅ Yes' || '❌ No' }}" >> $GITHUB_STEP_SUMMARY
echo "- **Task Count:** ${{ needs.validate-plan.outputs.task-count }} / 10 max" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Milestone
if [[ "${{ inputs.milestone_title }}" != "" ]]; then
if [[ "${{ needs.create-milestone.outputs.milestone-number }}" != "" ]]; then
echo "## 🎯 Milestone" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Title:** ${{ inputs.milestone_title }}" >> $GITHUB_STEP_SUMMARY
echo "- **Number:** #${{ needs.create-milestone.outputs.milestone-number }}" >> $GITHUB_STEP_SUMMARY
if [[ "${{ inputs.milestone_due_date }}" != "" ]]; then
echo "- **Due Date:** ${{ inputs.milestone_due_date }}" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
fi
fi
# Issues created
if [[ "${{ needs.create-issues.result }}" == "success" ]]; then
echo "## 📝 Issues Created" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
CREATED_ISSUES='${{ needs.create-issues.outputs.created-issues }}'
SKIPPED_ISSUES='${{ needs.create-issues.outputs.skipped-issues }}'
echo "**Created:**" >> $GITHUB_STEP_SUMMARY
echo "$CREATED_ISSUES" | jq -r '.[] | "- [#\(.number)](\(.url)) \(.title)"' >> $GITHUB_STEP_SUMMARY || echo "None" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Skipped (already exist):**" >> $GITHUB_STEP_SUMMARY
echo "$SKIPPED_ISSUES" | jq -r '.[] | "- #\(.number) \(.title)"' >> $GITHUB_STEP_SUMMARY || echo "None" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
else
echo "## ❌ Issue Creation Failed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Check the logs above for error details." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
fi
# Project sync
if [[ "${{ needs.sync-to-project.result }}" == "success" ]]; then
echo "## 📊 Project Board" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ Issues added to project board with 'Ready' status" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
fi
# Next steps
echo "## 🚀 Next Steps" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "1. Review created issues on the [Issues page](../../../issues)" >> $GITHUB_STEP_SUMMARY
echo "2. Issues will auto-generate branches when labeled correctly" >> $GITHUB_STEP_SUMMARY
echo "3. Start working on tasks from the project board" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "---" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "_Plan conversion completed at $(date -u '+%Y-%m-%d %H:%M:%S UTC')_" >> $GITHUB_STEP_SUMMARY
# Exit with error if any critical step failed
if [[ "${{ needs.validate-plan.result }}" == "failure" ]] || \
[[ "${{ needs.create-issues.result }}" == "failure" ]]; then
exit 1
fi