Skip to content

Commit 9537b9a

Browse files
clsandovalclaude
andauthored
Cc gha v2 (#2068)
* remove old workflows * Add Claude Code GitHub Actions workflows and update commands This commit adds a complete v2 workflow system for automated issue resolution using Claude Code, with proper label management. **New Workflows:** - cc-gha-research.yml: Automates codebase research for issues - cc-gha-plan.yml: Creates implementation plans based on research - cc-gha-implement.yml: Implements the plan and creates PRs - cc-gha-iterate.yml: Allows iteration on research/plans based on feedback **Workflow Labels:** - research_needed/research-done - plan_needed/plan-done - implement/implementation-done - iterate/iteration-done **Fixes:** - Added missing plan-done label to plan workflow for consistency - Updated pr-auto-label.yml to exclude all Claude Code workflow labels from being synced from issues to PRs (prevents label pollution) **Command Updates:** - Updated /create_plan_issue to handle inline content from workflows - Updated /research_codebase_issue to handle inline content from workflows - Both commands now support content passed directly from GitHub Actions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix end-of-file formatting in create_plan_issue.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8fee905 commit 9537b9a

File tree

10 files changed

+823
-777
lines changed

10 files changed

+823
-777
lines changed

.claude/commands/create_plan_issue.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ When this command is invoked, execute ALL steps automatically without user inter
1212
- If not set, use: `thoughts/shared/plans/{descriptive_name}.md`
1313
- Create issue directory if needed: `mkdir -p thoughts/shared/issues/${GITHUB_ISSUE_NUMBER}`
1414

15-
2. **Auto-load all available context:**
15+
2. **Process inline content if provided:**
16+
- If the command invocation includes content (e.g., `/create_plan_issue [issue details]`), treat that as the issue context
17+
- Extract requirements, constraints, and goals from the provided content
18+
- This content typically includes the issue title, body, and comments from the workflow
19+
20+
3. **Auto-load all available context:**
1621
- If GITHUB_ISSUE_NUMBER is set, check for: `thoughts/shared/issues/${GITHUB_ISSUE_NUMBER}/research.md`
1722
- Read research file completely if it exists
18-
- Extract issue requirements from GitHub issue metadata (available in workflow context)
23+
- Extract issue requirements from inline content or GitHub issue metadata (available in workflow context)
1924
- Proceed immediately to research phase
2025

21-
3. **No user interaction required:**
26+
4. **No user interaction required:**
2227
- DO NOT ask for clarifications or wait for input
2328
- Make reasonable technical decisions based on research
2429
- If multiple approaches exist, choose the most practical one

.claude/commands/research_codebase_issue.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ When this command is invoked:
1212
- If not set, use: `thoughts/shared/research/YYYY-MM-DD_HH-MM-SS_topic.md`
1313
- Create issue directory if needed: `mkdir -p thoughts/shared/issues/${GITHUB_ISSUE_NUMBER}`
1414

15-
2. **Respond with context-aware message:**
15+
2. **Check if research content is provided inline:**
16+
- If the command invocation includes additional content (e.g., `/research_codebase_issue [content]`), treat that content as the research query
17+
- If content is provided, skip the ready message and proceed directly to research (step 1 of "Steps to follow after receiving the research query")
18+
- If no content is provided, show the ready message below and wait for input
19+
20+
3. **Respond with context-aware message (only if no inline content):**
1621

1722
If GITHUB_ISSUE_NUMBER is set, respond with:
1823
```
Lines changed: 337 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,337 @@
1+
name: Implement (v2 - Single PR Journey)
2+
3+
on:
4+
issues:
5+
types: [opened, labeled]
6+
7+
concurrency:
8+
group: issue-${{ github.event.issue.number }}
9+
cancel-in-progress: false
10+
11+
jobs:
12+
implement:
13+
if: contains(github.event.issue.labels.*.name, 'implement')
14+
runs-on: ubuntu-latest
15+
timeout-minutes: 30
16+
17+
permissions:
18+
contents: write
19+
issues: write
20+
pull-requests: write
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Setup Node.js
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: "18"
32+
33+
- name: Install Claude Code CLI
34+
run: |
35+
npm install -g @anthropic-ai/claude-code
36+
37+
- name: Install GitHub CLI
38+
run: |
39+
type -p gh >/dev/null || {
40+
sudo apt update
41+
sudo apt install -y gh
42+
}
43+
44+
- name: Setup Python
45+
uses: actions/setup-python@v4
46+
with:
47+
python-version: "3.11"
48+
49+
- name: Install uv
50+
run: |
51+
curl -LsSf https://astral.sh/uv/install.sh | sh
52+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
53+
54+
- name: Checkout branch
55+
run: |
56+
issue_number="${{ github.event.issue.number }}"
57+
branch_name="work-issue-${issue_number}"
58+
59+
git config user.name "github-actions[bot]"
60+
git config user.email "github-actions[bot]@users.noreply.github.com"
61+
62+
# Check if branch exists remotely
63+
if git ls-remote --heads origin "$branch_name" | grep -q "$branch_name"; then
64+
echo "✅ Branch exists, checking out"
65+
git fetch origin "$branch_name"
66+
git checkout "$branch_name"
67+
git pull --rebase origin "$branch_name"
68+
else
69+
echo "❌ Branch $branch_name doesn't exist"
70+
echo "Run research and planning first"
71+
exit 1
72+
fi
73+
74+
echo "Current branch: $(git branch --show-current)"
75+
76+
- name: Find plan file
77+
id: find_plan
78+
run: |
79+
issue_number="${{ github.event.issue.number }}"
80+
plan_file="thoughts/shared/issues/${issue_number}/plan.md"
81+
82+
if [ ! -f "$plan_file" ]; then
83+
echo "❌ No plan file found at $plan_file"
84+
echo "Create a plan first by adding plan_needed label"
85+
exit 1
86+
fi
87+
88+
echo "plan_file=$plan_file" >> $GITHUB_OUTPUT
89+
echo "✅ Found plan: $plan_file"
90+
91+
- name: Get or create PR
92+
id: get_pr
93+
run: |
94+
issue_number="${{ github.event.issue.number }}"
95+
branch_name="work-issue-${issue_number}"
96+
97+
# Check if PR already exists for this branch
98+
pr_number=$(gh pr list --head "$branch_name" --json number --jq '.[0].number' 2>/dev/null || echo "")
99+
100+
if [ -n "$pr_number" ]; then
101+
echo "pr_number=$pr_number" >> $GITHUB_OUTPUT
102+
echo "pr_exists=true" >> $GITHUB_OUTPUT
103+
echo "✅ PR #${pr_number} already exists"
104+
else
105+
echo "pr_exists=false" >> $GITHUB_OUTPUT
106+
echo "📝 No existing PR found, will create new one"
107+
fi
108+
env:
109+
GH_TOKEN: ${{ github.token }}
110+
111+
- name: Create PR
112+
if: steps.get_pr.outputs.pr_exists == 'false'
113+
id: create_pr
114+
run: |
115+
issue_number="${{ github.event.issue.number }}"
116+
branch_name="work-issue-${issue_number}"
117+
118+
# Create PR body
119+
cat > /tmp/pr_body.md << EOF
120+
## 📋 Implementation for #${issue_number}
121+
122+
This PR implements the plan for issue #${issue_number}.
123+
124+
### Files
125+
- Research: \`thoughts/shared/issues/${issue_number}/research.md\`
126+
- Plan: \`thoughts/shared/issues/${issue_number}/plan.md\`
127+
128+
**Discussion**: See issue #${issue_number} for research and plan details
129+
130+
**Status**: Implementation in progress...
131+
132+
**Closes**: #${issue_number}
133+
EOF
134+
135+
pr_url=$(gh pr create \
136+
--title "${{ github.event.issue.title }}" \
137+
--body-file /tmp/pr_body.md \
138+
--base main \
139+
--head "$branch_name" \
140+
| tail -1)
141+
142+
pr_number=$(echo "$pr_url" | grep -oE '[0-9]+$')
143+
144+
echo "pr_number=$pr_number" >> $GITHUB_OUTPUT
145+
echo "✅ Created PR #${pr_number}"
146+
147+
# Post to issue that PR was created
148+
gh issue comment "$issue_number" \
149+
--body "## 🚀 Pull Request Created
150+
151+
PR #${pr_number} has been created for implementation.
152+
153+
**Next**: Implementation will now proceed automatically."
154+
155+
env:
156+
GH_TOKEN: ${{ github.token }}
157+
158+
- name: Set PR number
159+
id: set_pr
160+
run: |
161+
if [ "${{ steps.get_pr.outputs.pr_exists }}" = "true" ]; then
162+
echo "pr_number=${{ steps.get_pr.outputs.pr_number }}" >> $GITHUB_OUTPUT
163+
else
164+
echo "pr_number=${{ steps.create_pr.outputs.pr_number }}" >> $GITHUB_OUTPUT
165+
fi
166+
167+
- name: Run implement_plan command
168+
env:
169+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
170+
GITHUB_ISSUE_NUMBER: ${{ github.event.issue.number }}
171+
run: |
172+
plan_file="${{ steps.find_plan.outputs.plan_file }}"
173+
174+
echo "Starting implementation for issue #${{ github.event.issue.number }}"
175+
echo "Using plan: $plan_file"
176+
177+
claude -p \
178+
--dangerously-skip-permissions \
179+
--max-turns 200 \
180+
--verbose \
181+
"/implement_plan @${plan_file}
182+
183+
IMPORTANT: Do not ask the user any questions during implementation. Make reasonable decisions and proceed with the implementation. If you encounter ambiguity, choose the most straightforward approach." 2>&1 | tee /tmp/claude_output.log
184+
185+
echo "Implementation command completed"
186+
187+
- name: Commit and push changes
188+
id: commit_changes
189+
run: |
190+
issue_number="${{ github.event.issue.number }}"
191+
branch_name="work-issue-${issue_number}"
192+
193+
git add .
194+
195+
if git diff --staged --quiet; then
196+
echo "No changes to commit"
197+
echo "has_changes=false" >> $GITHUB_OUTPUT
198+
else
199+
git commit -m "Implement plan for issue #${issue_number}
200+
201+
- Implemented changes according to plan
202+
203+
Co-authored-by: Claude Code <noreply@anthropic.com>"
204+
205+
git push -u origin "$branch_name"
206+
echo "has_changes=true" >> $GITHUB_OUTPUT
207+
echo "✅ Committed and pushed implementation"
208+
fi
209+
210+
- name: Comment success on PR
211+
if: steps.commit_changes.outputs.has_changes == 'true'
212+
run: |
213+
pr_number="${{ steps.set_pr.outputs.pr_number }}"
214+
215+
cat > /tmp/success_comment.md << 'EOF'
216+
## ✅ Implementation Complete
217+
218+
The implementation has been completed.
219+
220+
**Changes**:
221+
- Implementation follows the plan in `thoughts/shared/issues/${{ github.event.issue.number }}/plan.md`
222+
- Code committed to this PR
223+
224+
**Next steps**:
225+
- Review the implementation changes
226+
- Run tests to verify the changes
227+
- Merge this PR to close issue #${{ github.event.issue.number }}
228+
EOF
229+
230+
gh pr comment "$pr_number" --body-file /tmp/success_comment.md
231+
232+
echo "Posted success comment to PR"
233+
env:
234+
GH_TOKEN: ${{ github.token }}
235+
236+
- name: Update PR to ready for review
237+
if: steps.commit_changes.outputs.has_changes == 'true'
238+
run: |
239+
pr_number="${{ steps.set_pr.outputs.pr_number }}"
240+
241+
# Update PR description to show completion
242+
cat > /tmp/pr_body.md << EOF
243+
## 📋 Research and Implementation for #${{ github.event.issue.number }}
244+
245+
This PR contains the complete workflow for issue #${{ github.event.issue.number }}:
246+
247+
- ✅ Research (completed)
248+
- ✅ Planning (completed)
249+
- ✅ Implementation (completed)
250+
251+
### Research
252+
Research findings are in \`thoughts/shared/issues/${{ github.event.issue.number }}/research.md\`
253+
254+
### Implementation Plan
255+
Plan is in \`thoughts/shared/issues/${{ github.event.issue.number }}/plan.md\`
256+
257+
### Implementation
258+
All changes have been implemented and tested.
259+
260+
**Ready for review and merge!**
261+
262+
**Closes**: #${{ github.event.issue.number }}
263+
EOF
264+
265+
gh pr edit "$pr_number" --body-file /tmp/pr_body.md
266+
267+
echo "✅ Updated PR description"
268+
env:
269+
GH_TOKEN: ${{ github.token }}
270+
271+
- name: Update labels
272+
if: success() && steps.commit_changes.outputs.has_changes == 'true'
273+
run: |
274+
issue_number="${{ github.event.issue.number }}"
275+
276+
# Remove implement label
277+
gh issue edit "${issue_number}" \
278+
--remove-label "implement" \
279+
--add-label "implementation-done"
280+
281+
echo "✅ Removed implement label and added implementation-done label"
282+
283+
# Comment on issue
284+
gh issue comment "${issue_number}" \
285+
--body "## ✅ Implementation Complete
286+
287+
Implementation has been completed and is ready for review in PR #${{ steps.set_pr.outputs.pr_number }}.
288+
289+
Please review the changes and run tests before merging."
290+
291+
echo "✅ Posted completion comment to issue"
292+
env:
293+
GH_TOKEN: ${{ github.token }}
294+
295+
- name: Upload logs
296+
if: always()
297+
uses: actions/upload-artifact@v4
298+
with:
299+
name: claude-output-implement-${{ github.event.issue.number }}
300+
path: /tmp/claude_output.log
301+
retention-days: 7
302+
303+
- name: Handle errors
304+
if: failure()
305+
run: |
306+
issue_number="${{ github.event.issue.number }}"
307+
pr_number="${{ steps.set_pr.outputs.pr_number }}"
308+
309+
cat > /tmp/error_comment.md << 'EOF'
310+
## ❌ Implementation Failed
311+
312+
The implementation workflow encountered an error.
313+
314+
**Issue**: #${{ github.event.issue.number }}
315+
**Workflow Run**: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
316+
317+
**Common issues**:
318+
- No plan file exists (create plan first with plan_needed label)
319+
- Implementation errors
320+
- API errors or timeouts
321+
322+
Check the workflow logs for details.
323+
324+
**To retry**: Remove and re-add the `implement` label.
325+
EOF
326+
327+
# Try to comment on PR first, fallback to issue
328+
if [ -n "$pr_number" ]; then
329+
gh pr comment "$pr_number" --body-file /tmp/error_comment.md || \
330+
gh issue comment "$issue_number" --body-file /tmp/error_comment.md
331+
else
332+
gh issue comment "$issue_number" --body-file /tmp/error_comment.md
333+
fi
334+
335+
echo "Posted error comment"
336+
env:
337+
GH_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)