fix: simplify Claude workflows with clean username checks

- Simplify all permission checks to single username validation
- Remove complex permission logic for cleaner workflows
- Streamline issue implementation workflow
- Streamline PR assistant workflow
- Keep only essential functionality
- Fix YAML syntax issues
- Validate all workflows successfully

Changes:
- Single username check: context.actor !== 'bvdaakster'
- Simplified error messages
- Clean YAML structure
- Reduced complexity while maintaining functionality

All workflows now use simple, reliable permission checks.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-18 21:32:12 +02:00
parent cabe6eda96
commit ec635fb707
3 changed files with 71 additions and 474 deletions

View File

@@ -12,21 +12,9 @@ on:
jobs: jobs:
claude-review: claude-review:
# Permission filter: Only allow bvdaakster to trigger reviews # Only allow bvdaakster to trigger reviews
if: github.event.pull_request.user.login == 'bvdaakster' if: github.event.pull_request.user.login == 'bvdaakster'
# Alternative filters (comment out the above and use one of these):
# Only for external contributors:
# if: github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR'
# Only for specific users:
# if: contains(fromJSON('["username1", "username2"]'), github.event.pull_request.user.login)
# Only for non-admins (let admins skip review):
# if: |
# github.event.pull_request.author_association != 'OWNER' &&
# github.event.pull_request.author_association != 'MEMBER'
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
contents: read contents: read

View File

@@ -26,75 +26,16 @@ jobs:
uses: actions/github-script@v7 uses: actions/github-script@v7
with: with:
script: | script: |
const username = context.actor; if (context.actor !== 'bvdaakster') {
// Method 1: Specific privileged users list
const privilegedUsers = [
'bvdaakster' // Only this user can use Claude
];
// Method 2: Check repository permission level
const { data: collaborator } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: username
});
// Method 3: Check organization membership (if applicable)
let isOrgMember = false;
try {
await github.rest.orgs.getMembershipForUser({
org: context.repo.owner,
username: username
});
isOrgMember = true;
} catch (error) {
// User is not an org member or org doesn't exist
isOrgMember = false;
}
// Combined permission check
const isPrivilegedUser = privilegedUsers.includes(username);
const hasAdminAccess = collaborator.permission === 'admin';
const hasWriteAccess = ['admin', 'write'].includes(collaborator.permission);
// Choose your permission strategy:
// Option A: Only specific users
const allowedByUserList = isPrivilegedUser;
// Option B: Only admins
const allowedByAdminAccess = hasAdminAccess;
// Option C: Admin + specific users
const allowedByAdminOrPrivileged = hasAdminAccess || isPrivilegedUser;
// Option D: Organization members with write access
const allowedByOrgAndWrite = isOrgMember && hasWriteAccess;
// Set your chosen strategy here:
const isAllowed = isPrivilegedUser; // Only bvdaakster can use Claude
if (!isAllowed) {
const errorMessage = `❌ **Access Denied**: Claude implementation is restricted to privileged users only.
**Your access level**: ${collaborator.permission}
**Privileged user**: ${isPrivilegedUser ? 'Yes' : 'No'}
**Organization member**: ${isOrgMember ? 'Yes' : 'No'}
Contact a repository administrator for access.`;
await github.rest.issues.createComment({ await github.rest.issues.createComment({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: context.issue.number, issue_number: context.issue.number,
body: errorMessage body: '❌ **Access Denied**: Only bvdaakster can use Claude implementation.'
}); });
throw new Error('Insufficient permissions for Claude implementation'); throw new Error('Unauthorized user');
} }
// Log successful access
console.log(`✅ Access granted to ${username} (${collaborator.permission})`);
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
@@ -110,18 +51,15 @@ jobs:
- name: Install pnpm - name: Install pnpm
run: npm install -g pnpm@10.12.4 run: npm install -g pnpm@10.12.4
- name: Create Claude implementation branch - name: Create branch
id: create-branch id: create-branch
run: | run: |
# Create a unique branch name based on issue number and timestamp
BRANCH_NAME="claude/issue-${{ github.event.issue.number }}-$(date +%Y%m%d-%H%M%S)" BRANCH_NAME="claude/issue-${{ github.event.issue.number }}-$(date +%Y%m%d-%H%M%S)"
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
# Create and switch to the new branch
git checkout -b "$BRANCH_NAME" git checkout -b "$BRANCH_NAME"
git push origin "$BRANCH_NAME" git push origin "$BRANCH_NAME"
- name: Add comment with implementation start - name: Notify start
uses: actions/github-script@v7 uses: actions/github-script@v7
with: with:
script: | script: |
@@ -129,26 +67,13 @@ jobs:
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: context.issue.number, issue_number: context.issue.number,
body: `🤖 **Claude Implementation Started** body: `🤖 **Claude Implementation Started**\n\n📋 **Issue**: #${{ github.event.issue.number }}\n🌿 **Branch**: \`${{ steps.create-branch.outputs.branch_name }}\`\n\nImplementing your request...`
I'm now working on implementing this issue. Here's what I'm doing:
📋 **Issue**: #${{ github.event.issue.number }} - ${{ github.event.issue.title }}
🌿 **Branch**: \`${{ steps.create-branch.outputs.branch_name }}\`
⏱️ **Started**: ${new Date().toISOString()}
I'll analyze the requirements and create a pull request with the implementation. This may take a few minutes...
You can track the progress in the [Actions tab](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}).`
}); });
- name: Implement with Claude - name: Implement with Claude
id: implementation
uses: anthropics/claude-code-action@beta uses: anthropics/claude-code-action@beta
with: with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
# Direct prompt with issue context
direct_prompt: | direct_prompt: |
Please implement the feature or fix described in this GitHub issue: Please implement the feature or fix described in this GitHub issue:
@@ -157,232 +82,93 @@ jobs:
**Issue Description**: **Issue Description**:
${{ github.event.issue.body }} ${{ github.event.issue.body }}
**Implementation Request**: **User Request**:
${{ github.event.comment.body }} ${{ github.event.comment.body }}
**Instructions**: **Instructions**:
1. Analyze the issue requirements carefully 1. Analyze the issue requirements carefully
2. Follow the existing code patterns and conventions in this PayloadCMS plugin 2. Follow existing code patterns and conventions
3. Add appropriate tests if needed (check for existing test patterns) 3. Use TypeScript with proper typing
4. Update documentation if necessary 4. Follow ESM module structure with .js extensions
5. Ensure the implementation is complete and working 5. Add tests if needed
6. Use TypeScript with proper typing 6. Update documentation if necessary
7. Follow the project's ESM module structure with .js extensions
The implementation should be production-ready and follow best practices for a PayloadCMS plugin. This is the @xtr-dev/payload-billing plugin for PayloadCMS.
**Repository Context**: This is the @xtr-dev/payload-billing plugin for PayloadCMS.
**Branch**: ${{ steps.create-branch.outputs.branch_name }}
# Allow Claude to run necessary commands
allowed_tools: "Bash(pnpm build),Bash(pnpm typecheck),Bash(pnpm lint),Bash(npm run test)" allowed_tools: "Bash(pnpm build),Bash(pnpm typecheck),Bash(pnpm lint),Bash(npm run test)"
- name: Check for changes - name: Check for changes
id: changes id: changes
run: | run: |
# Check both staged and unstaged changes
if git diff --quiet && git diff --cached --quiet; then if git diff --quiet && git diff --cached --quiet; then
echo "has_changes=false" >> $GITHUB_OUTPUT echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No changes were made during implementation"
else else
echo "has_changes=true" >> $GITHUB_OUTPUT echo "has_changes=true" >> $GITHUB_OUTPUT
echo "Changes detected, preparing commit"
# Show what changed for debugging
echo "=== Changed files ==="
git diff --name-only
git diff --cached --name-only
echo "===================="
fi fi
- name: Commit changes - name: Commit and push
if: steps.changes.outputs.has_changes == 'true' if: steps.changes.outputs.has_changes == 'true'
run: | run: |
git config --local user.email "action@github.com" git config --local user.email "action@github.com"
git config --local user.name "Claude Implementation Bot" git config --local user.name "Claude Implementation Bot"
git add . git add .
git commit -m "$(cat <<'EOF' git commit -m "feat: implement issue #${{ github.event.issue.number }}
feat: implement issue #${{ github.event.issue.number }} - ${{ github.event.issue.title }}
Implemented via Claude automation based on issue requirements. Implemented via Claude automation.
Issue: #${{ github.event.issue.number }} Issue: #${{ github.event.issue.number }}
Requested by: @${{ github.event.comment.user.login }} Requested by: @${{ github.event.comment.user.login }}
🤖 Generated with Claude Automation 🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
EOF
)"
Co-Authored-By: Claude <noreply@anthropic.com>"
git push origin ${{ steps.create-branch.outputs.branch_name }} git push origin ${{ steps.create-branch.outputs.branch_name }}
- name: Create Pull Request - name: Create PR
if: steps.changes.outputs.has_changes == 'true' if: steps.changes.outputs.has_changes == 'true'
uses: actions/github-script@v7 uses: actions/github-script@v7
id: create-pr id: create-pr
with: with:
script: | script: |
try { const { data: pr } = await github.rest.pulls.create({
// Get the list of changed files for the PR description owner: context.repo.owner,
const { data: comparison } = await github.rest.repos.compareCommits({ repo: context.repo.repo,
owner: context.repo.owner, title: `🤖 Implement: ${{ github.event.issue.title }}`,
repo: context.repo.repo, head: '${{ steps.create-branch.outputs.branch_name }}',
base: 'dev', base: 'dev',
head: '${{ steps.create-branch.outputs.branch_name }}' body: `## 🤖 Claude Implementation
});
const changedFiles = comparison.files || []; This PR implements issue #${{ github.event.issue.number }}.
const filesList = changedFiles.map(file => `- \`${file.filename}\``).join('\n');
const { data: pr } = await github.rest.pulls.create({ **Issue**: #${{ github.event.issue.number }}
owner: context.repo.owner, **Requested by**: @${{ github.event.comment.user.login }}
repo: context.repo.repo, **Branch**: \`${{ steps.create-branch.outputs.branch_name }}\`
title: `🤖 Implement: ${{ github.event.issue.title }}`,
head: '${{ steps.create-branch.outputs.branch_name }}',
base: 'dev',
body: `## 🤖 Claude Implementation
This PR was automatically created by Claude to implement the feature/fix requested in issue #${{ github.event.issue.number }}. ### Review Checklist
- [ ] Code follows project conventions
- [ ] Build passes
- [ ] Tests pass
- [ ] Implementation matches requirements
### 📋 Issue Details Closes #${{ github.event.issue.number }}
- **Issue**: #${{ github.event.issue.number }}
- **Title**: ${{ github.event.issue.title }}
- **Requested by**: @${{ github.event.comment.user.login }}
- **Branch**: \`${{ steps.create-branch.outputs.branch_name }}\`
- **Implementation Date**: ${new Date().toISOString()}
### 📁 Files Changed 🤖 Generated with Claude Code`
${filesList || 'No files were changed'} });
return pr.number;
### 🔍 Implementation - name: Notify success
Claude analyzed the issue requirements and implemented the requested changes following the project's coding standards and best practices.
### ✅ Review Checklist
- [ ] Code follows project conventions
- [ ] Tests are included (if applicable)
- [ ] Documentation is updated (if needed)
- [ ] Implementation matches issue requirements
- [ ] No breaking changes (unless intended)
- [ ] Build passes (\`pnpm build\`)
- [ ] Type checking passes (\`pnpm typecheck\`)
- [ ] Linting passes (\`pnpm lint\`)
### 🔗 Related
Closes #${{ github.event.issue.number }}
### 🚀 Deployment
After merging this PR:
1. Version will be automatically bumped
2. Package will be built and published
3. Changes will be available in the next release
---
**Note**: This implementation was generated automatically by Claude. Please review carefully before merging.
🤖 *Generated with [Claude Code](https://claude.ai/code)*
🔧 *Triggered by @${{ github.event.comment.user.login }}*`
});
console.log(`✅ PR created successfully: #${pr.number}`);
return pr.number;
} catch (error) {
console.error('Failed to create PR:', error);
throw error;
}
- name: Fallback PR Creation
if: steps.changes.outputs.has_changes == 'true' && failure() && steps.create-pr.conclusion == 'failure'
uses: actions/github-script@v7
id: fallback-pr
with:
script: |
console.log('Primary PR creation failed, attempting fallback...');
try {
const { data: pr } = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `🤖 Implement: ${{ github.event.issue.title }}`,
head: '${{ steps.create-branch.outputs.branch_name }}',
base: 'dev',
body: `## 🤖 Claude Implementation (Fallback)
This PR was automatically created by Claude to implement issue #${{ github.event.issue.number }}.
**Issue**: #${{ github.event.issue.number }} - ${{ github.event.issue.title }}
**Requested by**: @${{ github.event.comment.user.login }}
**Branch**: \`${{ steps.create-branch.outputs.branch_name }}\`
⚠️ *This PR was created via fallback method due to an error in the primary creation process.*
### 🔍 Implementation
Claude has implemented the requested changes. Please review the code changes in this PR.
### ✅ Review Required
- [ ] Verify implementation meets issue requirements
- [ ] Check code quality and conventions
- [ ] Test the changes
- [ ] Ensure no breaking changes
Closes #${{ github.event.issue.number }}
🤖 *Generated with Claude Automation*`
});
console.log(`✅ Fallback PR created successfully: #${pr.number}`);
return pr.number;
} catch (error) {
console.error('Fallback PR creation also failed:', error);
return null;
}
- name: Update issue with success
if: steps.changes.outputs.has_changes == 'true' if: steps.changes.outputs.has_changes == 'true'
uses: actions/github-script@v7 uses: actions/github-script@v7
with: with:
script: | script: |
const prNumber = '${{ steps.create-pr.outputs.result }}' || '${{ steps.fallback-pr.outputs.result }}'; const prNumber = '${{ steps.create-pr.outputs.result }}';
const prLink = prNumber ? `#${prNumber}` : 'Could not determine PR number';
await github.rest.issues.createComment({ await github.rest.issues.createComment({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: context.issue.number, issue_number: context.issue.number,
body: `✅ **Implementation Complete!** body: `✅ **Implementation Complete!**\n\n🎯 **Pull Request**: #${prNumber}\n🌿 **Branch**: \`${{ steps.create-branch.outputs.branch_name }}\`\n\nReady for review! 🚀`
I've successfully implemented the requested changes and created a pull request:
🎯 **Pull Request**: ${prLink}
🌿 **Branch**: \`${{ steps.create-branch.outputs.branch_name }}\`
⏱️ **Completed**: ${new Date().toISOString()}
🔧 **Triggered by**: @${{ github.event.comment.user.login }}
## 📋 What Was Done
- ✅ Analyzed issue requirements
- ✅ Implemented requested features/fixes
- ✅ Followed project coding standards
- ✅ Created pull request for review
- ✅ Applied proper branch naming (\`claude/issue-${{ github.event.issue.number }}-*\`)
## 🔍 Next Steps
1. **Review** the implementation in the pull request
2. **Test** the changes locally if needed
3. **Check** that build/typecheck/lint passes
4. **Merge** the PR if everything looks good
## 🛠️ Quality Checks
The implementation includes:
- TypeScript with proper typing
- ESM module structure with .js extensions
- Following existing code patterns
- Appropriate documentation updates
**Ready for review!** 🚀`
}); });
- name: Update issue with no changes - name: Handle no changes
if: steps.changes.outputs.has_changes == 'false' if: steps.changes.outputs.has_changes == 'false'
uses: actions/github-script@v7 uses: actions/github-script@v7
with: with:
@@ -391,26 +177,14 @@ The implementation includes:
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: context.issue.number, issue_number: context.issue.number,
body: ` **Implementation Completed - No Changes** body: ` **No Changes Needed**\n\nI analyzed the issue but no code changes are required.`
I analyzed the issue but determined that no code changes are needed. This might be because:
- The feature is already implemented
- The issue requires clarification
- The request is not actionable as a code change
- Additional information is needed
🌿 **Branch**: \`${{ steps.create-branch.outputs.branch_name }}\` (will be cleaned up)
Please review the issue requirements and provide additional details if needed.`
}); });
- name: Clean up branch if no changes - name: Clean up on no changes
if: steps.changes.outputs.has_changes == 'false' if: steps.changes.outputs.has_changes == 'false'
run: | run: git push origin --delete ${{ steps.create-branch.outputs.branch_name }} || true
git push origin --delete ${{ steps.create-branch.outputs.branch_name }} || true
- name: Handle implementation failure - name: Handle failure
if: failure() if: failure()
uses: actions/github-script@v7 uses: actions/github-script@v7
with: with:
@@ -419,14 +193,5 @@ The implementation includes:
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: context.issue.number, issue_number: context.issue.number,
body: `❌ **Implementation Failed** body: `❌ **Implementation Failed**\n\nCheck the [workflow logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.`
I encountered an error while trying to implement this issue. Please check the [workflow logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.
Common reasons for failure:
- Issue requirements are unclear or incomplete
- Technical constraints prevent implementation
- Repository permissions or configuration issues
You can try again by commenting \`@claude implement\` or provide more specific requirements.`
}); });

View File

@@ -12,7 +12,6 @@ permissions:
jobs: jobs:
claude-pr-assist: claude-pr-assist:
# Only run on PR comments (not issue comments)
if: | if: |
github.event.issue.pull_request && github.event.issue.pull_request &&
github.event.issue_comment.issue.state == 'open' && github.event.issue_comment.issue.state == 'open' &&
@@ -31,34 +30,16 @@ jobs:
uses: actions/github-script@v7 uses: actions/github-script@v7
with: with:
script: | script: |
const username = context.actor; if (context.actor !== 'bvdaakster') {
// Only allow bvdaakster to use Claude PR assistance
const privilegedUsers = [
'bvdaakster' // Only this user can use Claude
];
const isPrivilegedUser = privilegedUsers.includes(username);
if (!isPrivilegedUser) {
const errorMessage = `❌ **Access Denied**: Claude PR assistance is restricted to privileged users only.
**User**: ${username}
**Privileged user**: No
Contact a repository administrator for access.`;
await github.rest.issues.createComment({ await github.rest.issues.createComment({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: context.issue.number, issue_number: context.issue.number,
body: errorMessage body: '❌ **Access Denied**: Only bvdaakster can use Claude PR assistance.'
}); });
throw new Error('Insufficient permissions for Claude PR assistance'); throw new Error('Unauthorized user');
} }
console.log(`✅ Access granted to ${username}`);
- name: Get PR details - name: Get PR details
id: pr-details id: pr-details
uses: actions/github-script@v7 uses: actions/github-script@v7
@@ -69,14 +50,10 @@ jobs:
repo: context.repo.repo, repo: context.repo.repo,
pull_number: context.issue.number pull_number: context.issue.number
}); });
return { return {
head_ref: pr.head.ref, head_ref: pr.head.ref,
head_sha: pr.head.sha,
base_ref: pr.base.ref,
title: pr.title, title: pr.title,
body: pr.body, body: pr.body
user: pr.user.login
}; };
- name: Checkout PR branch - name: Checkout PR branch
@@ -95,7 +72,7 @@ jobs:
- name: Install pnpm - name: Install pnpm
run: npm install -g pnpm@10.12.4 run: npm install -g pnpm@10.12.4
- name: Add comment with start notification - name: Notify start
uses: actions/github-script@v7 uses: actions/github-script@v7
with: with:
script: | script: |
@@ -103,32 +80,15 @@ jobs:
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: context.issue.number, issue_number: context.issue.number,
body: `🤖 **Claude PR Assistant Started** body: `🤖 **Claude PR Assistant Started**\n\n💬 **Request**: ${{ github.event.comment.body }}\n🌿 **Branch**: \`${{ fromJson(steps.pr-details.outputs.result).head_ref }}\`\n\nWorking on your request...`
I'm now working on your request in this pull request:
📋 **PR**: #${{ github.event.issue.number }} - ${{ fromJson(steps.pr-details.outputs.result).title }}
🌿 **Branch**: \`${{ fromJson(steps.pr-details.outputs.result).head_ref }}\`
💬 **Request**:
\`\`\`
${{ github.event.comment.body }}
\`\`\`
⏱️ **Started**: ${new Date().toISOString()}
I'll analyze the current PR and implement your requested changes. This may take a few minutes...
You can track the progress in the [Actions tab](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}).`
}); });
- name: Assist with Claude - name: Assist with Claude
id: assistance
uses: anthropics/claude-code-action@beta uses: anthropics/claude-code-action@beta
with: with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
# Direct prompt with PR context
direct_prompt: | direct_prompt: |
You are assisting with a GitHub Pull Request. Please help with the following request: You are assisting with a GitHub Pull Request. Please help with this request:
**Pull Request #${{ github.event.issue.number }}**: ${{ fromJson(steps.pr-details.outputs.result).title }} **Pull Request #${{ github.event.issue.number }}**: ${{ fromJson(steps.pr-details.outputs.result).title }}
@@ -138,78 +98,44 @@ jobs:
**User Request**: **User Request**:
${{ github.event.comment.body }} ${{ github.event.comment.body }}
**Context**:
- Repository: @xtr-dev/payload-billing (PayloadCMS plugin)
- Branch: ${{ fromJson(steps.pr-details.outputs.result).head_ref }}
- Base branch: ${{ fromJson(steps.pr-details.outputs.result).base_ref }}
- Requested by: @${{ github.event.comment.user.login }}
**Instructions**: **Instructions**:
1. Analyze the current PR changes and the user's request 1. Analyze the current PR changes and the user's request
2. Implement the requested improvements, fixes, or changes 2. Implement the requested improvements, fixes, or changes
3. Follow existing code patterns and conventions 3. Follow existing code patterns and conventions
4. Ensure TypeScript typing is correct 4. Use TypeScript with proper typing
5. Use ESM module structure with .js extensions 5. Follow ESM module structure with .js extensions
6. Run quality checks (build, typecheck, lint) 6. Run quality checks if needed
7. If the request is unclear, make reasonable assumptions based on context
**Types of requests to handle**: This is the @xtr-dev/payload-billing plugin for PayloadCMS.
- Code improvements and refactoring Please implement the requested changes directly on this PR branch.
- Bug fixes within the PR
- Adding missing features or functionality
- Updating documentation
- Fixing type errors or lint issues
- Performance optimizations
- Adding tests
Please implement the requested changes directly in the current branch.
# Allow Claude to run necessary commands
allowed_tools: "Bash(pnpm build),Bash(pnpm typecheck),Bash(pnpm lint),Bash(npm run test)" allowed_tools: "Bash(pnpm build),Bash(pnpm typecheck),Bash(pnpm lint),Bash(npm run test)"
- name: Check for changes - name: Check for changes
id: changes id: changes
run: | run: |
# Check both staged and unstaged changes
if git diff --quiet && git diff --cached --quiet; then if git diff --quiet && git diff --cached --quiet; then
echo "has_changes=false" >> $GITHUB_OUTPUT echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No changes were made during assistance"
else else
echo "has_changes=true" >> $GITHUB_OUTPUT echo "has_changes=true" >> $GITHUB_OUTPUT
echo "Changes detected, preparing commit"
# Show what changed for debugging
echo "=== Changed files ==="
git diff --name-only
git diff --cached --name-only
echo "===================="
fi fi
- name: Commit changes - name: Commit and push
if: steps.changes.outputs.has_changes == 'true' if: steps.changes.outputs.has_changes == 'true'
run: | run: |
git config --local user.email "action@github.com" git config --local user.email "action@github.com"
git config --local user.name "Claude PR Assistant" git config --local user.name "Claude PR Assistant"
git add . git add .
git commit -m "$(cat <<'EOF' git commit -m "feat: Claude PR assistance - ${{ github.event.comment.user.login }} request
feat: Claude PR assistance - ${{ github.event.comment.user.login }} request
Implemented requested changes via Claude PR Assistant.
PR: #${{ github.event.issue.number }}
Request: ${{ github.event.comment.body }} Request: ${{ github.event.comment.body }}
Requested by: @${{ github.event.comment.user.login }} PR: #${{ github.event.issue.number }}
🤖 Generated with Claude PR Assistant 🤖 Generated with Claude PR Assistant
Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Claude <noreply@anthropic.com>"
EOF
)"
git push origin ${{ fromJson(steps.pr-details.outputs.result).head_ref }} git push origin ${{ fromJson(steps.pr-details.outputs.result).head_ref }}
- name: Update PR with success - name: Notify success
if: steps.changes.outputs.has_changes == 'true' if: steps.changes.outputs.has_changes == 'true'
uses: actions/github-script@v7 uses: actions/github-script@v7
with: with:
@@ -218,43 +144,10 @@ jobs:
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: context.issue.number, issue_number: context.issue.number,
body: `✅ **PR Assistance Complete!** body: `✅ **PR Assistance Complete!**\n\n🔧 **Changes Made**: Implemented your requested improvements\n🌿 **Branch**: \`${{ fromJson(steps.pr-details.outputs.result).head_ref }}\`\n\nChanges are ready for review! 🚀`
I've successfully implemented your requested changes:
💬 **Your Request**:
\`\`\`
${{ github.event.comment.body }}
\`\`\`
🔧 **Changes Made**:
- ✅ Analyzed PR context and requirements
- ✅ Implemented requested improvements/fixes
- ✅ Followed project coding standards
- ✅ Updated the current PR branch
- ✅ Committed changes with descriptive message
🌿 **Branch**: \`${{ fromJson(steps.pr-details.outputs.result).head_ref }}\`
⏱️ **Completed**: ${new Date().toISOString()}
## 🔍 What's Next
The changes have been pushed to this PR branch. You can:
1. **Review** the new changes in the Files Changed tab
2. **Test** the implementation locally
3. **Verify** the changes meet your requirements
4. **Request** additional changes if needed
## 🛠️ Quality Assurance
The implementation includes:
- TypeScript with proper typing
- ESM module structure with .js extensions
- Following existing code patterns
- Quality checks passed (build/typecheck/lint)
**Changes are ready for review!** 🚀`
}); });
- name: Update PR with no changes - name: Handle no changes
if: steps.changes.outputs.has_changes == 'false' if: steps.changes.outputs.has_changes == 'false'
uses: actions/github-script@v7 uses: actions/github-script@v7
with: with:
@@ -263,35 +156,10 @@ The implementation includes:
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: context.issue.number, issue_number: context.issue.number,
body: ` **PR Assistance Complete - No Changes** body: ` **No Changes Needed**\n\nI analyzed your request but no code changes are required.`
I analyzed your request but determined that no code changes are needed:
💬 **Your Request**:
\`\`\`
${{ github.event.comment.body }}
\`\`\`
## 🔍 Analysis Result
This might be because:
- The requested feature is already implemented
- The issue mentioned is already fixed
- The request requires clarification
- The change is not actionable as code modification
🌿 **Branch**: \`${{ fromJson(steps.pr-details.outputs.result).head_ref }}\` (unchanged)
## 💡 Suggestions
If you need specific changes:
1. Provide more detailed requirements
2. Point to specific files or functions
3. Include code examples of desired changes
4. Try a different @claude command
Feel free to comment again with more specific instructions!`
}); });
- name: Handle assistance failure - name: Handle failure
if: failure() if: failure()
uses: actions/github-script@v7 uses: actions/github-script@v7
with: with:
@@ -300,29 +168,5 @@ Feel free to comment again with more specific instructions!`
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: context.issue.number, issue_number: context.issue.number,
body: `❌ **PR Assistance Failed** body: `❌ **PR Assistance Failed**\n\nCheck the [workflow logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.`
I encountered an error while trying to assist with this PR.
💬 **Your Request**:
\`\`\`
${{ github.event.comment.body }}
\`\`\`
## 🔍 Troubleshooting
Please check the [workflow logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.
Common reasons for failure:
- Request is unclear or too complex
- Technical constraints prevent implementation
- Permission or configuration issues
- Conflicting changes in the PR
## 🔄 Try Again
You can try again by:
- Providing more specific instructions
- Breaking down complex requests into smaller parts
- Commenting with a different @claude command
**Available commands**: \`@claude implement\`, \`@claude fix\`, \`@claude improve\`, \`@claude update\`, \`@claude refactor\`, \`@claude help\``
}); });