Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- name: Claude Code - Auto Implementation
- on:
- issues:
- types: [labeled]
- jobs:
- claude-implement:
- # Only run when the 'claude implement' label is added
- if: github.event.label.name == 'claude implement'
- runs-on: ubuntu-latest
- timeout-minutes: 30 # Prevent runaway processes
- permissions:
- contents: write
- pull-requests: write
- issues: write
- steps:
- # Step 1: Checkout the repository
- - name: Checkout Repository
- uses: actions/checkout@v4
- # Step 2: Set up PHP environment for WordPress development
- - name: Setup PHP
- uses: shivammathur/setup-php@v2
- with:
- php-version: '8.1'
- tools: composer, wp-cli
- extensions: mysqli, pdo_mysql, zip, gd, mbstring, curl, xml, bcmath
- # Step 3: Set up Node.js (required for Claude Code)
- - name: Setup Node.js
- uses: actions/setup-node@v4
- with:
- node-version: '20'
- # Step 4: Install Composer dependencies if composer.json exists
- - name: Install PHP Dependencies
- if: hashFiles('composer.json') != ''
- run: composer install --no-progress --prefer-dist --no-dev
- # Step 5: Extract issue details
- - name: Extract Issue Information
- id: issue_info
- uses: actions/github-script@v7
- with:
- github-token: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
- script: |
- const issue = context.payload.issue;
- const issueNumber = issue.number;
- const issueTitle = issue.title;
- const issueBody = issue.body || '';
- // Clean the issue body for use in branch name and commit messages
- const cleanTitle = issueTitle.toLowerCase()
- .replace(/[^a-z0-9]+/g, '-')
- .replace(/^-|-$/g, '')
- .substring(0, 50);
- // Generate branch name following WP Fusion conventions
- const branchName = `feature/gh-issue-${issueNumber}-${cleanTitle}`;
- // Output for use in next steps
- core.setOutput('issue_number', issueNumber);
- core.setOutput('issue_title', issueTitle);
- core.setOutput('issue_body', issueBody);
- core.setOutput('branch_name', branchName);
- console.log(`Processing issue #${issueNumber}: ${issueTitle}`);
- # Step 6: Create a new branch for the implementation
- - name: Create Feature Branch
- run: |
- git config --global user.name "Claude Code Bot"
- git config --global user.email "[email protected]"
- # Check if branch exists on remote and delete it if it does
- if git ls-remote --heads origin ${{ steps.issue_info.outputs.branch_name }} | grep -q ${{ steps.issue_info.outputs.branch_name }}; then
- echo "Branch already exists on remote, deleting it first..."
- git push origin --delete ${{ steps.issue_info.outputs.branch_name }} || true
- fi
- # Create and checkout the new branch
- git checkout -b ${{ steps.issue_info.outputs.branch_name }}
- # Step 7: Run Claude Code to implement the fix/feature
- - name: Implement Fix with Claude Code
- id: claude_implementation
- uses: anthropics/claude-code-base-action@beta
- with:
- prompt: |
- You are working on the WP Fusion WordPress plugin located in the current directory. This is a WordPress plugin that syncs user data between WordPress and various CRM/marketing automation platforms.
- Please implement the following based on issue #${{ steps.issue_info.outputs.issue_number }}:
- Title: ${{ steps.issue_info.outputs.issue_title }}
- Description:
- ${{ steps.issue_info.outputs.issue_body }}
- IMPORTANT INSTRUCTIONS:
- 1. First, use GrepTool to search for files related to the issue described above
- 2. View only the most relevant files - don't try to read every file in the repository
- 3. Make targeted changes to fix the specific issue described - don't try to refactor unrelated code
- 4. Common locations in WP Fusion:
- - includes/ (core PHP logic and CRM integrations)
- - includes/admin/ (admin interface and settings)
- - includes/integrations/ (third-party plugin integrations)
- - includes/crms/ (CRM-specific implementations)
- - assets/js/ (JavaScript files)
- - assets/css/ (CSS stylesheets)
- 5. Identify the root cause of the issue and fix it with minimal changes
- 6. Follow WordPress coding standards
- 7. Ensure compatibility with PHP 7.4+ and WordPress 5.8+
- AFTER implementing the fix, create a TEMPORARY file named `/tmp/pr-description.md` (NOT in the repository) with the following sections:
- ## ๐ Problem Identification
- [Explain what the root cause of the issue was]
- ## ๐ก Solution Approach
- [Explain how you decided to fix it and why this approach was chosen]
- ## ๐ ๏ธ Implementation Details
- [List the specific changes made and which files were modified]
- ## ๐งช Testing Instructions
- [Provide step-by-step instructions to test the fix]
- ## โ ๏ธ Potential Side Effects
- [List any areas that should be checked for regressions]
- BE EFFICIENT: Make only the necessary changes to fix the issue. Focus on solving the specific problem described.
- DO NOT create output.txt or any other files in the repository besides the actual fix.
- claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
- allowed_tools: "View,Edit,Create,GlobTool,GrepTool,Bash"
- max_turns: 30
- # Step 8: Run PHP Standards Enforcement
- - name: Enforce PHP Standards
- continue-on-error: true # Don't fail the workflow if standards checks fail
- run: |
- echo "๐ง Running PHP standards enforcement..."
- # Configure Composer to allow the plugin
- composer global config --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
- # Install PHP CodeSniffer if not already available
- if ! command -v phpcs &> /dev/null; then
- composer global require "squizlabs/php_codesniffer=*"
- export PATH="$PATH:$(composer global config home --quiet)/vendor/bin"
- fi
- # Install WordPress Coding Standards and additional dependencies
- if ! phpcs -i | grep -qi "WordPress"; then
- # Install all required packages including PHPCSUtils
- composer global require \
- "wp-coding-standards/wpcs:^3.0" \
- "phpcsstandards/phpcsutils:^1.0" \
- "phpcsstandards/phpcsextra:^1.0" \
- "sirbrillig/phpcs-variable-analysis:^2.0" \
- "phpcompatibility/php-compatibility:^9.3"
- # Register all paths
- phpcs --config-set installed_paths \
- "$(composer global config home --quiet)/vendor/wp-coding-standards/wpcs,$(composer global config home --quiet)/vendor/phpcompatibility/php-compatibility,$(composer global config home --quiet)/vendor/phpcsstandards/phpcsutils,$(composer global config home --quiet)/vendor/phpcsstandards/phpcsextra,$(composer global config home --quiet)/vendor/sirbrillig/phpcs-variable-analysis"
- fi
- # Run PHP CodeSniffer with WordPress standards
- if [ -f "phpcs.xml" ] || [ -f "phpcs.xml.dist" ]; then
- echo "Using project phpcs configuration"
- # Try to run with project config, but don't fail if there are issues
- phpcs --report=summary || echo "CodeSniffer completed with issues"
- else
- echo "Running with WordPress standards"
- phpcs --standard=WordPress --extensions=php --ignore=vendor/ . --report=summary || echo "CodeSniffer completed with issues"
- fi
- # Run PHP Code Beautifier and Fixer
- if command -v phpcbf &> /dev/null; then
- echo "Running automatic code fixes..."
- if [ -f "phpcs.xml" ] || [ -f "phpcs.xml.dist" ]; then
- phpcbf || echo "Code beautifier completed"
- else
- phpcbf --standard=WordPress --extensions=php --ignore=vendor/ . || echo "Code beautifier completed"
- fi
- fi
- # Step 9: Check if any changes were made
- - name: Check for Changes
- id: check_changes
- run: |
- # Remove output.txt if it was created (we don't want this)
- if [ -f "output.txt" ]; then
- echo "Removing output.txt file..."
- rm output.txt
- fi
- if [[ -n $(git status --porcelain) ]]; then
- echo "changes=true" >> $GITHUB_OUTPUT
- echo "Changes detected, will create PR"
- git status --short
- else
- echo "changes=false" >> $GITHUB_OUTPUT
- echo "No changes made"
- fi
- # Step 10: Commit and push changes
- - name: Commit Changes
- if: steps.check_changes.outputs.changes == 'true'
- run: |
- git add -A
- git commit -m "feat: ${{ steps.issue_info.outputs.issue_title }}
- Automated implementation for issue #${{ steps.issue_info.outputs.issue_number }}
- - Applied WordPress coding standards
- - Implemented requested functionality
- - Added appropriate error handling
- This commit was automatically generated by Claude Code.
- Closes #${{ steps.issue_info.outputs.issue_number }}"
- # Force push to overwrite any existing branch
- git push --force origin ${{ steps.issue_info.outputs.branch_name }}
- # Step 11: Create Pull Request
- - name: Create Pull Request
- if: steps.check_changes.outputs.changes == 'true'
- uses: actions/github-script@v7
- with:
- github-token: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
- script: |
- const issueNumber = ${{ steps.issue_info.outputs.issue_number }};
- const branchName = '${{ steps.issue_info.outputs.branch_name }}';
- const issueTitle = `${{ steps.issue_info.outputs.issue_title }}`;
- // Get repository default branch dynamically
- const { data: repo } = await github.rest.repos.get({
- owner: context.repo.owner,
- repo: context.repo.repo
- });
- const defaultBranch = repo.default_branch;
- // Read the Claude-generated PR description if available
- const fs = require('fs');
- let claudeDescription = '';
- try {
- const descFile = '/tmp/pr-description.md';
- if (fs.existsSync(descFile)) {
- claudeDescription = fs.readFileSync(descFile, 'utf8');
- console.log('Found Claude-generated PR description');
- // Delete the file after reading
- fs.unlinkSync(descFile);
- }
- } catch (e) {
- console.log('Could not read PR description file:', e.message);
- }
- // Generate timestamp
- const timestamp = new Date().toISOString().replace('T', ' ').replace(/\.\d{3}Z$/, ' UTC');
- // Create the PR body
- const prBody = claudeDescription ?
- `## ๐ค Automated Implementation for #${issueNumber}
- ${claudeDescription}
- ---
- ### ๐ Issue Reference
- - **Issue:** #${issueNumber}
- - **Title:** ${issueTitle}
- - **Branch:** \`${branchName}\`
- ### โ ๏ธ Review Requirements
- - [ ] Code review for quality and standards
- - [ ] Functional testing in development environment
- - [ ] Regression testing for related features
- - [ ] Performance impact assessment
- - [ ] Security review if applicable
- ### ๐ Related
- Closes #${issueNumber}
- ---
- *๐ค Generated by Claude Code GitHub Action*
- *๐ Generated at: ${timestamp}*` :
- `## ๐ Automated Implementation
- This pull request was automatically generated by Claude Code to address issue #${issueNumber}.
- ### ๐ Issue Details
- - **Issue:** #${issueNumber}
- - **Title:** ${issueTitle}
- - **Branch:** \`${branchName}\`
- ### ๐ Changes Made
- Claude Code has analyzed and implemented a fix for this issue. Please review the file changes to understand the implementation.
- ### ๐งช Testing Instructions
- 1. Review the implemented changes carefully
- 2. Test the specific functionality mentioned in the issue
- 3. Verify no regressions in related areas
- 4. Check error logs for any warnings or notices
- ### โ ๏ธ Important Notes
- - This implementation was generated automatically
- - **Manual review is required** before merging
- - Test thoroughly in a staging environment
- ### ๐ Related
- Closes #${issueNumber}
- ---
- *๐ค Generated by Claude Code GitHub Action*
- *๐ Generated at: ${timestamp}*`;
- // Create the PR
- const { data: pr } = await github.rest.pulls.create({
- owner: context.repo.owner,
- repo: context.repo.repo,
- title: `๐ค Auto Implementation: ${issueTitle}`,
- body: prBody,
- head: branchName,
- base: defaultBranch,
- draft: true // Create as draft to require manual review
- });
- console.log(`Created PR #${pr.number}: ${pr.html_url}`);
- // Add labels to the PR
- try {
- await github.rest.issues.addLabels({
- owner: context.repo.owner,
- repo: context.repo.repo,
- issue_number: pr.number,
- labels: ['automated', 'needs-review', 'claude-code']
- });
- } catch (labelError) {
- console.log('Could not add labels (they may not exist):', labelError.message);
- }
- // Add a comment on the original issue with summary
- const commentBody = claudeDescription ?
- `๐ค **Claude Code Implementation Complete**
- I've analyzed this issue and created a pull request with the implementation: #${pr.number}
- **Summary of changes:**
- ${claudeDescription.split('## ๐ Problem Identification')[1]?.split('##')[0]?.trim() || 'See PR for details'}
- **Next Steps:**
- 1. Review the PR description for full implementation details
- 2. Test the functionality as described in the PR
- 3. Check for any edge cases or regressions
- 4. Mark the PR as ready for review when satisfied
- The PR is currently in **draft mode** to ensure manual review before merging.` :
- `๐ค **Claude Code Implementation Complete**
- I've analyzed this issue and created a pull request with the implementation: #${pr.number}
- **Next Steps:**
- 1. Review the generated code carefully
- 2. Test the functionality thoroughly
- 3. Check for any edge cases or regressions
- 4. Mark the PR as ready for review when satisfied
- The PR is currently in **draft mode** to ensure manual review before merging.`;
- await github.rest.issues.createComment({
- owner: context.repo.owner,
- repo: context.repo.repo,
- issue_number: issueNumber,
- body: commentBody
- });
- # Step 12: Handle case where no changes were needed
- - name: Comment on Issue (No Changes)
- if: steps.check_changes.outputs.changes == 'false'
- uses: actions/github-script@v7
- with:
- github-token: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
- script: |
- const issueNumber = ${{ steps.issue_info.outputs.issue_number }};
- await github.rest.issues.createComment({
- owner: context.repo.owner,
- repo: context.repo.repo,
- issue_number: issueNumber,
- body: `๐ค **Claude Code Analysis Complete**
- I've analyzed this issue but determined that no code changes are needed at this time.
- **Possible reasons:**
- - โ The functionality already exists
- - ๐ The issue needs more specific requirements
- - ๐ The change requires manual investigation
- - ๐ ๏ธ The implementation needs human expertise
- **Recommendations:**
- 1. Review the issue description for clarity
- 2. Provide specific examples or use cases
- 3. Include steps to reproduce (for bugs)
- 4. Consider if this requires architectural changes
- Feel free to add more details and re-apply the \`claude implement\` label.`
- });
- # Step 13: Error handling
- - name: Handle Errors
- if: failure()
- uses: actions/github-script@v7
- with:
- github-token: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
- script: |
- const issueNumber = ${{ steps.issue_info.outputs.issue_number }};
- await github.rest.issues.createComment({
- owner: context.repo.owner,
- repo: context.repo.repo,
- issue_number: issueNumber,
- body: `๐ด **Claude Code Implementation Failed**
- I encountered an error while trying to implement this issue.
- **Common causes:**
- - ๐ง Complex requirements needing human expertise
- - ๐ Ambiguous or incomplete issue description
- - โ๏ธ Technical limitations or dependencies
- - ๐ Permissions or environment issues
- **Next steps:**
- 1. Check the [workflow logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details
- 2. Consider implementing manually
- 3. Provide more specific requirements
- 4. Break down into smaller, focused issues
- You can re-apply the \`claude implement\` label after addressing potential issues.`
- });
Advertisement
Add Comment
Please, Sign In to add comment