mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 15:04:13 +08:00
Compare commits
34 Commits
test-gh-co
...
test-autof
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56229f4488 | ||
|
|
a44c75d118 | ||
|
|
536d74a854 | ||
|
|
42fce56d3f | ||
|
|
4a40e4252f | ||
|
|
47c2eb29f7 | ||
|
|
d48897c1f8 | ||
|
|
7fc38f28c0 | ||
|
|
71431089b5 | ||
|
|
130eff6d9c | ||
|
|
54d68a2a5f | ||
|
|
110acf1b44 | ||
|
|
e9dc3050fb | ||
|
|
9700ba8130 | ||
|
|
0a82bcdb04 | ||
|
|
a37014c520 | ||
|
|
3005c85cee | ||
|
|
7ccb615087 | ||
|
|
f317d3c55d | ||
|
|
50aee38198 | ||
|
|
39b3855841 | ||
|
|
d0f938f59a | ||
|
|
d6a4b9c857 | ||
|
|
1dd746f3e2 | ||
|
|
89eda5e432 | ||
|
|
dc5d6645af | ||
|
|
ff46b61169 | ||
|
|
e2e4286857 | ||
|
|
6c58dba4ad | ||
|
|
74ee3b534f | ||
|
|
583874c9e0 | ||
|
|
0932e8cf26 | ||
|
|
c9bad6e9cb | ||
|
|
14e99e2a2b |
31
.claude/agents/deep-thinker.md
Normal file
31
.claude/agents/deep-thinker.md
Normal file
@@ -0,0 +1,31 @@
|
||||
---
|
||||
name: deep-thinker
|
||||
description: A subagent that performs deep analysis with extended thinking
|
||||
tools:
|
||||
- "*"
|
||||
proactive: false
|
||||
---
|
||||
|
||||
# Deep Thinker Subagent
|
||||
|
||||
You are a specialized subagent designed to perform deep, thorough analysis of complex problems using extended thinking capabilities.
|
||||
|
||||
## Your Purpose
|
||||
|
||||
You excel at:
|
||||
- Breaking down complex problems into smaller components
|
||||
- Analyzing trade-offs and implications
|
||||
- Providing comprehensive, well-reasoned solutions
|
||||
- Exploring edge cases and potential issues
|
||||
|
||||
## Instructions
|
||||
|
||||
When given a task:
|
||||
1. Use extended thinking to thoroughly analyze the problem
|
||||
2. Consider multiple approaches and their trade-offs
|
||||
3. Identify potential issues or edge cases
|
||||
4. Provide a detailed, well-structured response
|
||||
|
||||
## Important
|
||||
|
||||
Always think deeply before responding. Take your time to ensure thoroughness and accuracy in your analysis.
|
||||
54
.claude/commands/fix-ci-commit.md
Normal file
54
.claude/commands/fix-ci-commit.md
Normal file
@@ -0,0 +1,54 @@
|
||||
---
|
||||
description: Fix CI failures and commit changes (for use when branch already exists)
|
||||
allowed_tools: "*"
|
||||
---
|
||||
|
||||
# Fix CI Failures and Commit
|
||||
|
||||
You are on a branch that was created to fix CI failures. Your task is to fix the issues and commit the changes.
|
||||
|
||||
## CI Failure Information
|
||||
|
||||
$ARGUMENTS
|
||||
|
||||
## Your Tasks
|
||||
|
||||
1. **Analyze the failures** - Understand what went wrong from the logs
|
||||
2. **Fix the issues** - Make the necessary code changes
|
||||
3. **Commit your fixes** - Use git to commit all changes
|
||||
|
||||
## Step-by-Step Instructions
|
||||
|
||||
### 1. Fix the Issues
|
||||
|
||||
Based on the error logs:
|
||||
- Fix syntax errors
|
||||
- Fix formatting issues
|
||||
- Fix test failures
|
||||
- Fix any other CI problems
|
||||
|
||||
### 2. Commit Your Changes (REQUIRED)
|
||||
|
||||
After fixing ALL issues, you MUST:
|
||||
|
||||
Use the `mcp__github_file_ops__commit_files` tool to commit all your changes with a descriptive message like:
|
||||
|
||||
```
|
||||
Fix CI failures
|
||||
|
||||
- Fixed syntax errors
|
||||
- Fixed formatting issues
|
||||
- Fixed test failures
|
||||
[List actual fixes made]
|
||||
```
|
||||
|
||||
**IMPORTANT**: You MUST use the MCP file ops tool to commit your changes. The workflow expects you to commit your changes.
|
||||
|
||||
### 3. Verify (Optional)
|
||||
|
||||
If possible, run verification commands:
|
||||
- `bun run format:check` for formatting
|
||||
- `bun test` for tests
|
||||
- `bun run typecheck` for TypeScript
|
||||
|
||||
Begin by analyzing the failure logs and then fix the issues.
|
||||
67
.claude/commands/fix-ci.md
Normal file
67
.claude/commands/fix-ci.md
Normal file
@@ -0,0 +1,67 @@
|
||||
---
|
||||
description: Analyze and fix CI failures by examining logs and making targeted fixes
|
||||
allowed_tools: "*"
|
||||
---
|
||||
|
||||
# Fix CI Failures
|
||||
|
||||
You are tasked with analyzing CI failure logs and fixing the issues. Follow these steps:
|
||||
|
||||
## Context Provided
|
||||
|
||||
$ARGUMENTS
|
||||
|
||||
## Step 1: Analyze the Failure
|
||||
|
||||
Parse the provided CI failure information to understand:
|
||||
- Which jobs failed and why
|
||||
- The specific error messages and stack traces
|
||||
- Whether failures are test-related, build-related, or linting issues
|
||||
|
||||
## Step 2: Search and Understand the Codebase
|
||||
|
||||
Use search tools to locate the failing code:
|
||||
- Search for the failing test names or functions
|
||||
- Find the source files mentioned in error messages
|
||||
- Review related configuration files (package.json, tsconfig.json, etc.)
|
||||
|
||||
## Step 3: Apply Targeted Fixes
|
||||
|
||||
Make minimal, focused changes:
|
||||
- **For test failures**: Determine if the test or implementation needs fixing
|
||||
- **For type errors**: Fix type definitions or correct the code logic
|
||||
- **For linting issues**: Apply formatting using the project's tools
|
||||
- **For build errors**: Resolve dependency or configuration issues
|
||||
- **For missing imports**: Add the necessary imports or install packages
|
||||
|
||||
Requirements:
|
||||
- Only fix the actual CI failures, avoid unrelated changes
|
||||
- Follow existing code patterns and conventions
|
||||
- Ensure changes are production-ready, not temporary hacks
|
||||
- Preserve existing functionality while fixing issues
|
||||
|
||||
## Step 4: Commit Changes
|
||||
|
||||
After applying ALL fixes:
|
||||
1. Use the `mcp__github_file_ops__commit_files` tool to commit your changes
|
||||
2. Include a descriptive commit message explaining what was fixed
|
||||
3. Document which CI jobs/tests were addressed in the commit message
|
||||
4. Important: Use the MCP file ops tool, not git commands directly
|
||||
|
||||
## Step 5: Verify Fixes Locally
|
||||
|
||||
Run available verification commands:
|
||||
- Execute the failing tests locally to confirm they pass
|
||||
- Run the project's lint command (check package.json for scripts)
|
||||
- Run type checking if available
|
||||
- Execute any build commands to ensure compilation succeeds
|
||||
|
||||
## Important Guidelines
|
||||
|
||||
- Focus exclusively on fixing the reported CI failures
|
||||
- Maintain code quality and follow the project's established patterns
|
||||
- If a fix requires significant refactoring, document why it's necessary
|
||||
- When multiple solutions exist, choose the simplest one that maintains code quality
|
||||
- Add clear comments only if the fix is non-obvious
|
||||
|
||||
Begin by analyzing the failure details provided above.
|
||||
22
.claude/commands/review.md
Normal file
22
.claude/commands/review.md
Normal file
@@ -0,0 +1,22 @@
|
||||
---
|
||||
allowed-tools: Bash(gh pr comment:*), Bash(gh pr diff:*), Bash(gh pr view:*), Read, Glob, Grep
|
||||
description: Code review a pull request
|
||||
---
|
||||
|
||||
Review the current pull request and provide feedback.
|
||||
|
||||
1. Use `gh pr view` to get the PR details and `gh pr diff` to see the changes
|
||||
2. Look for potential bugs, issues, or improvements
|
||||
3. Always post a comment with your findings using `gh pr comment`
|
||||
|
||||
Format your comment like this:
|
||||
|
||||
## Code Review
|
||||
|
||||
[Your feedback here - be specific and constructive]
|
||||
|
||||
- If you find issues, describe them clearly
|
||||
- If everything looks good, say so
|
||||
- Link to specific lines when relevant
|
||||
|
||||
🤖 Generated with [Claude Code](https://claude.ai/code)
|
||||
177
.github/workflows/auto-fix-ci-inline.yml
vendored
Normal file
177
.github/workflows/auto-fix-ci-inline.yml
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
name: Auto Fix CI Failures (Inline)
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["CI"]
|
||||
types:
|
||||
- completed
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
actions: read
|
||||
issues: write
|
||||
|
||||
jobs:
|
||||
auto-fix:
|
||||
if: |
|
||||
github.event.workflow_run.conclusion == 'failure' &&
|
||||
github.event.workflow_run.name != 'Auto Fix CI Failures' &&
|
||||
github.event.workflow_run.name != 'Auto Fix CI Failures (Inline)'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event.workflow_run.head_branch }}
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Setup git
|
||||
run: |
|
||||
git config --global user.name "claude[bot]"
|
||||
git config --global user.email "198276+claude[bot]@users.noreply.github.com"
|
||||
|
||||
- name: Create fix branch
|
||||
id: branch
|
||||
run: |
|
||||
BRANCH_NAME="claude-auto-fix-ci-${{ github.event.workflow_run.head_branch }}-${{ github.run_id }}"
|
||||
git checkout -b "$BRANCH_NAME"
|
||||
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Get CI failure details
|
||||
id: failure_details
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const run = await github.rest.actions.getWorkflowRun({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
run_id: ${{ github.event.workflow_run.id }}
|
||||
});
|
||||
|
||||
const jobs = await github.rest.actions.listJobsForWorkflowRun({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
run_id: ${{ github.event.workflow_run.id }}
|
||||
});
|
||||
|
||||
const failedJobs = jobs.data.jobs.filter(job => job.conclusion === 'failure');
|
||||
|
||||
let errorLogs = [];
|
||||
for (const job of failedJobs) {
|
||||
const logs = await github.rest.actions.downloadJobLogsForWorkflowRun({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
job_id: job.id
|
||||
});
|
||||
errorLogs.push({
|
||||
jobName: job.name,
|
||||
logs: logs.data
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
runUrl: run.data.html_url,
|
||||
failedJobs: failedJobs.map(j => j.name),
|
||||
errorLogs: errorLogs
|
||||
};
|
||||
|
||||
- name: Fix CI failures with Claude
|
||||
uses: anthropics/claude-code-action@v1-dev
|
||||
with:
|
||||
prompt: |
|
||||
You are tasked with analyzing CI failure logs and fixing the issues. Follow these steps:
|
||||
|
||||
## Context Provided
|
||||
|
||||
Failed CI Run: ${{ fromJSON(steps.failure_details.outputs.result).runUrl }}
|
||||
Failed Jobs: ${{ join(fromJSON(steps.failure_details.outputs.result).failedJobs, ', ') }}
|
||||
|
||||
Error logs:
|
||||
${{ toJSON(fromJSON(steps.failure_details.outputs.result).errorLogs) }}
|
||||
|
||||
## Step 1: Analyze the Failure
|
||||
|
||||
Parse the provided CI failure information to understand:
|
||||
- Which jobs failed and why
|
||||
- The specific error messages and stack traces
|
||||
- Whether failures are test-related, build-related, or linting issues
|
||||
|
||||
## Step 2: Search and Understand the Codebase
|
||||
|
||||
Use search tools to locate the failing code:
|
||||
- Search for the failing test names or functions
|
||||
- Find the source files mentioned in error messages
|
||||
- Review related configuration files (package.json, tsconfig.json, etc.)
|
||||
|
||||
## Step 3: Apply Targeted Fixes
|
||||
|
||||
Make minimal, focused changes:
|
||||
- **For test failures**: Determine if the test or implementation needs fixing
|
||||
- **For type errors**: Fix type definitions or correct the code logic
|
||||
- **For linting issues**: Apply formatting using the project's tools
|
||||
- **For build errors**: Resolve dependency or configuration issues
|
||||
- **For missing imports**: Add the necessary imports or install packages
|
||||
|
||||
Requirements:
|
||||
- Only fix the actual CI failures, avoid unrelated changes
|
||||
- Follow existing code patterns and conventions
|
||||
- Ensure changes are production-ready, not temporary hacks
|
||||
- Preserve existing functionality while fixing issues
|
||||
|
||||
## Step 4: Commit Changes
|
||||
|
||||
After applying ALL fixes:
|
||||
1. Stage all modified files with `git add -A`
|
||||
2. Commit with: `git commit -m "Fix CI failures: prettier formatting and syntax errors"`
|
||||
3. Important: You MUST commit your changes - the branch already exists
|
||||
|
||||
## Step 5: Verify Fixes Locally
|
||||
|
||||
Run available verification commands:
|
||||
- Execute the failing tests locally to confirm they pass
|
||||
- Run the project's lint command (check package.json for scripts)
|
||||
- Run type checking if available
|
||||
- Execute any build commands to ensure compilation succeeds
|
||||
|
||||
## Important Guidelines
|
||||
|
||||
- Focus exclusively on fixing the reported CI failures
|
||||
- Maintain code quality and follow the project's established patterns
|
||||
- If a fix requires significant refactoring, document why it's necessary
|
||||
- When multiple solutions exist, choose the simplest one that maintains code quality
|
||||
|
||||
Begin by analyzing the failure details provided above.
|
||||
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
timeout_minutes: "30"
|
||||
use_sticky_comment: "true"
|
||||
use_commit_signing: "true"
|
||||
allowed_tools: "Edit,MultiEdit,Write,Read,Glob,Grep,LS,Bash,mcp__github_file_ops__commit_files,mcp__github_file_ops__delete_files"
|
||||
claude_args: "--max-turns 15"
|
||||
|
||||
- name: Push fix branch
|
||||
if: success()
|
||||
run: |
|
||||
git push origin ${{ steps.branch.outputs.branch_name }}
|
||||
|
||||
- name: Create pull request comment
|
||||
if: success()
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const branchName = '${{ steps.branch.outputs.branch_name }}';
|
||||
const baseBranch = '${{ github.event.workflow_run.head_branch }}';
|
||||
const prUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/compare/${baseBranch}...${branchName}?quick_pull=1`;
|
||||
|
||||
const issueNumber = ${{ github.event.workflow_run.pull_requests[0] && github.event.workflow_run.pull_requests[0].number || 'null' }};
|
||||
|
||||
if (issueNumber) {
|
||||
await github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: issueNumber,
|
||||
body: `## 🤖 CI Auto-Fix Available\n\nClaude has analyzed the CI failures and prepared fixes.\n\n[**→ Create pull request to fix CI**](${prUrl})\n\n_This fix was generated automatically based on the [failed CI run](${{ fromJSON(steps.failure_details.outputs.result).runUrl }})._`
|
||||
});
|
||||
}
|
||||
119
.github/workflows/auto-fix-ci.yml
vendored
Normal file
119
.github/workflows/auto-fix-ci.yml
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
name: Auto Fix CI Failures
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["CI"]
|
||||
types:
|
||||
- completed
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
actions: read
|
||||
issues: write
|
||||
|
||||
jobs:
|
||||
auto-fix:
|
||||
if: |
|
||||
github.event.workflow_run.conclusion == 'failure' &&
|
||||
github.event.workflow_run.name != 'Auto Fix CI Failures'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event.workflow_run.head_branch }}
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Setup git
|
||||
run: |
|
||||
git config --global user.name "claude[bot]"
|
||||
git config --global user.email "198276+claude[bot]@users.noreply.github.com"
|
||||
|
||||
- name: Create fix branch
|
||||
id: branch
|
||||
run: |
|
||||
BRANCH_NAME="claude-auto-fix-ci-${{ github.event.workflow_run.head_branch }}-${{ github.run_id }}"
|
||||
git checkout -b "$BRANCH_NAME"
|
||||
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Get CI failure details
|
||||
id: failure_details
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const run = await github.rest.actions.getWorkflowRun({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
run_id: ${{ github.event.workflow_run.id }}
|
||||
});
|
||||
|
||||
const jobs = await github.rest.actions.listJobsForWorkflowRun({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
run_id: ${{ github.event.workflow_run.id }}
|
||||
});
|
||||
|
||||
const failedJobs = jobs.data.jobs.filter(job => job.conclusion === 'failure');
|
||||
|
||||
let errorLogs = [];
|
||||
for (const job of failedJobs) {
|
||||
const logs = await github.rest.actions.downloadJobLogsForWorkflowRun({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
job_id: job.id
|
||||
});
|
||||
errorLogs.push({
|
||||
jobName: job.name,
|
||||
logs: logs.data
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
runUrl: run.data.html_url,
|
||||
failedJobs: failedJobs.map(j => j.name),
|
||||
errorLogs: errorLogs
|
||||
};
|
||||
|
||||
- name: Fix CI failures with Claude
|
||||
uses: anthropics/claude-code-action@v1-dev
|
||||
with:
|
||||
prompt: |
|
||||
/fix-ci-commit Failed CI Run: ${{ fromJSON(steps.failure_details.outputs.result).runUrl }}
|
||||
Failed Jobs: ${{ join(fromJSON(steps.failure_details.outputs.result).failedJobs, ', ') }}
|
||||
|
||||
Error logs:
|
||||
${{ toJSON(fromJSON(steps.failure_details.outputs.result).errorLogs) }}
|
||||
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
timeout_minutes: "30"
|
||||
use_sticky_comment: "true"
|
||||
use_commit_signing: "true"
|
||||
allowed_tools: "Edit,MultiEdit,Write,Read,Glob,Grep,LS,Bash,mcp__github_file_ops__commit_files,mcp__github_file_ops__delete_files"
|
||||
claude_args: "--max-turns 15"
|
||||
|
||||
- name: Push fix branch
|
||||
if: success()
|
||||
run: |
|
||||
git push origin ${{ steps.branch.outputs.branch_name }}
|
||||
|
||||
- name: Create pull request comment
|
||||
if: success()
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const branchName = '${{ steps.branch.outputs.branch_name }}';
|
||||
const baseBranch = '${{ github.event.workflow_run.head_branch }}';
|
||||
const prUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/compare/${baseBranch}...${branchName}?quick_pull=1`;
|
||||
|
||||
const issueNumber = ${{ github.event.workflow_run.pull_requests[0] && github.event.workflow_run.pull_requests[0].number || 'null' }};
|
||||
|
||||
if (issueNumber) {
|
||||
await github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: issueNumber,
|
||||
body: `## 🤖 CI Auto-Fix Available\n\nClaude has analyzed the CI failures and prepared fixes.\n\n[**→ Create pull request to fix CI**](${prUrl})\n\n_This fix was generated automatically based on the [failed CI run](${{ fromJSON(steps.failure_details.outputs.result).runUrl }})._`
|
||||
});
|
||||
}
|
||||
19
.github/workflows/claude-auto-review-test.yml
vendored
19
.github/workflows/claude-auto-review-test.yml
vendored
@@ -2,7 +2,7 @@ name: Auto review PRs
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize]
|
||||
types: [opened]
|
||||
|
||||
jobs:
|
||||
auto-review:
|
||||
@@ -18,21 +18,16 @@ jobs:
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Auto review PR
|
||||
uses: ./
|
||||
uses: anthropics/claude-code-action@v1-dev
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
prompt: |
|
||||
Please review this PR and provide comprehensive feedback.
|
||||
|
||||
Focus on:
|
||||
Please review this PR. Look at the changes and provide thoughtful feedback on:
|
||||
- Code quality and best practices
|
||||
- Potential bugs or issues
|
||||
- Suggestions for improvements
|
||||
- Overall architecture and design decisions
|
||||
- Documentation consistency
|
||||
|
||||
Use the GitHub MCP tools to create a proper PR review with comments.
|
||||
You can use mcp__github__create_pending_pull_request_review to start a review
|
||||
and mcp__github__submit_pull_request_review to submit it as a COMMENT (not APPROVE).
|
||||
- Documentation consistency: Verify that README.md and other documentation files are updated to reflect any code changes (especially new inputs, features, or configuration options)
|
||||
|
||||
Be constructive and specific in your feedback. Give inline comments where applicable.
|
||||
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
||||
claude_args: "--allowedTools mcp__github__create_pending_pull_request_review,mcp__github__submit_pull_request_review,Read,Grep,Glob"
|
||||
claude_args: "--allowedTools mcp__github-comment-server__create_pending_pull_request_review,mcp__github-comment-server__add_comment_to_pending_review,mcp__github-comment-server__submit_pending_pull_request_review,mcp__github-comment-server__get_pull_request_diff"
|
||||
|
||||
26
.github/workflows/claude-auto-review.yml
vendored
Normal file
26
.github/workflows/claude-auto-review.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
name: Auto Review PRs
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize]
|
||||
|
||||
jobs:
|
||||
auto-review:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
issues: write
|
||||
id-token: write
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Auto review PR
|
||||
uses: anthropics/claude-code-action@v1-dev
|
||||
with:
|
||||
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
||||
prompt: /review
|
||||
6
.github/workflows/claude.yml
vendored
6
.github/workflows/claude.yml
vendored
@@ -31,9 +31,13 @@ jobs:
|
||||
|
||||
- name: Run Claude Code
|
||||
id: claude
|
||||
uses: anthropics/claude-code-action@beta
|
||||
uses: janeapp/claude-code-action@main
|
||||
with:
|
||||
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
||||
allowed_tools: "Bash(bun install),Bash(bun test:*),Bash(bun run format),Bash(bun typecheck)"
|
||||
custom_instructions: "You have also been granted tools for editing files and running bun commands (install, run, test, typecheck) for testing your changes: bun install, bun test, bun run format, bun typecheck."
|
||||
model: "claude-opus-4-1-20250805"
|
||||
# Testing PR 411 - sticky comment customization
|
||||
use_sticky_comment: true
|
||||
sticky_comment_app_bot_id: "209825114"
|
||||
sticky_comment_app_bot_name: "claude"
|
||||
|
||||
20
README.md
20
README.md
@@ -1,6 +1,6 @@
|
||||

|
||||
|
||||
# Claude Code Action - No Approval Test
|
||||
# Claude Code Action (Final Test)
|
||||
|
||||
A general-purpose [Claude Code](https://claude.ai/code) action for GitHub PRs and issues that can answer questions and implement code changes. This action listens for a trigger phrase in comments and activates Claude act on the request. It supports multiple authentication methods including Anthropic direct API, Amazon Bedrock, and Google Vertex AI.
|
||||
|
||||
@@ -57,21 +57,3 @@ Having issues or questions? Check out our [Frequently Asked Questions](./docs/fa
|
||||
## License
|
||||
|
||||
This project is licensed under the MIT License—see the LICENSE file for details.
|
||||
|
||||
|
||||
## Testing token fix
|
||||
|
||||
|
||||
## Testing token fix v2
|
||||
|
||||
|
||||
## Testing token fix v3
|
||||
|
||||
|
||||
## Testing review tools
|
||||
|
||||
|
||||
## Testing MCP server fix
|
||||
|
||||
|
||||
## Testing gh comment command
|
||||
|
||||
@@ -81,6 +81,10 @@ inputs:
|
||||
description: "Enable commit signing using GitHub's commit signature verification. When false, Claude uses standard git commands"
|
||||
required: false
|
||||
default: "false"
|
||||
allowed_tools:
|
||||
description: "Comma-separated list of tools to allow Claude to use (e.g., 'Edit,MultiEdit,Write,Read'). If not set, mode defaults apply."
|
||||
required: false
|
||||
default: ""
|
||||
experimental_allowed_domains:
|
||||
description: "Restrict network access to these domains only (newline-separated). If not set, no restrictions are applied. Provider domains are auto-detected."
|
||||
required: false
|
||||
@@ -130,6 +134,7 @@ runs:
|
||||
ADDITIONAL_PERMISSIONS: ${{ inputs.additional_permissions }}
|
||||
CLAUDE_ARGS: ${{ inputs.claude_args }}
|
||||
MCP_CONFIG: ${{ inputs.mcp_config }}
|
||||
ALLOWED_TOOLS: ${{ inputs.allowed_tools }}
|
||||
|
||||
- name: Install Base Action Dependencies
|
||||
if: steps.prepare.outputs.contains_trigger == 'true'
|
||||
|
||||
@@ -79,4 +79,37 @@ export async function setupClaudeCodeSettings(
|
||||
console.log(`Slash commands directory not found or error copying: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Copy subagent files from repository to Claude's agents directory
|
||||
// CLAUDE_WORKING_DIR is set by the action to point to the repo being processed
|
||||
const workingDir = process.env.CLAUDE_WORKING_DIR || process.cwd();
|
||||
const repoAgentsDir = `${workingDir}/.claude/agents`;
|
||||
const targetAgentsDir = `${home}/.claude/agents`;
|
||||
|
||||
try {
|
||||
const agentsDirExists = await $`test -d ${repoAgentsDir}`.quiet().nothrow();
|
||||
if (agentsDirExists.exitCode === 0) {
|
||||
console.log(`Found subagents directory at ${repoAgentsDir}`);
|
||||
|
||||
// Create target agents directory if it doesn't exist
|
||||
await $`mkdir -p ${targetAgentsDir}`.quiet();
|
||||
console.log(`Created target agents directory at ${targetAgentsDir}`);
|
||||
|
||||
// Copy all .md files from repo agents to Claude's agents directory
|
||||
const copyResult = await $`cp -r ${repoAgentsDir}/*.md ${targetAgentsDir}/ 2>/dev/null`.quiet().nothrow();
|
||||
|
||||
if (copyResult.exitCode === 0) {
|
||||
// List copied agents for logging
|
||||
const agents = await $`ls -la ${targetAgentsDir}/*.md 2>/dev/null | wc -l`.quiet().text();
|
||||
const agentCount = parseInt(agents.trim()) || 0;
|
||||
console.log(`Successfully copied ${agentCount} subagent(s) to ${targetAgentsDir}`);
|
||||
} else {
|
||||
console.log(`No subagent files found in ${repoAgentsDir}`);
|
||||
}
|
||||
} else {
|
||||
console.log(`No subagents directory found at ${repoAgentsDir}`);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(`Error handling subagents: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
54
slash-commands/fix-ci-commit.md
Normal file
54
slash-commands/fix-ci-commit.md
Normal file
@@ -0,0 +1,54 @@
|
||||
---
|
||||
description: Fix CI failures and commit changes (for use when branch already exists)
|
||||
allowed_tools: "*"
|
||||
---
|
||||
|
||||
# Fix CI Failures and Commit
|
||||
|
||||
You are on a branch that was created to fix CI failures. Your task is to fix the issues and commit the changes.
|
||||
|
||||
## CI Failure Information
|
||||
|
||||
$ARGUMENTS
|
||||
|
||||
## Your Tasks
|
||||
|
||||
1. **Analyze the failures** - Understand what went wrong from the logs
|
||||
2. **Fix the issues** - Make the necessary code changes
|
||||
3. **Commit your fixes** - Use git to commit all changes
|
||||
|
||||
## Step-by-Step Instructions
|
||||
|
||||
### 1. Fix the Issues
|
||||
|
||||
Based on the error logs:
|
||||
- Fix syntax errors
|
||||
- Fix formatting issues
|
||||
- Fix test failures
|
||||
- Fix any other CI problems
|
||||
|
||||
### 2. Commit Your Changes (REQUIRED)
|
||||
|
||||
After fixing ALL issues, you MUST:
|
||||
|
||||
Use the `mcp__github_file_ops__commit_files` tool to commit all your changes with a descriptive message like:
|
||||
|
||||
```
|
||||
Fix CI failures
|
||||
|
||||
- Fixed syntax errors
|
||||
- Fixed formatting issues
|
||||
- Fixed test failures
|
||||
[List actual fixes made]
|
||||
```
|
||||
|
||||
**IMPORTANT**: You MUST use the MCP file ops tool to commit your changes. The workflow expects you to commit your changes.
|
||||
|
||||
### 3. Verify (Optional)
|
||||
|
||||
If possible, run verification commands:
|
||||
- `bun run format:check` for formatting
|
||||
- `bun test` for tests
|
||||
- `bun run typecheck` for TypeScript
|
||||
|
||||
Begin by analyzing the failure logs and then fix the issues.
|
||||
67
slash-commands/fix-ci.md
Normal file
67
slash-commands/fix-ci.md
Normal file
@@ -0,0 +1,67 @@
|
||||
---
|
||||
description: Analyze and fix CI failures by examining logs and making targeted fixes
|
||||
allowed_tools: "*"
|
||||
---
|
||||
|
||||
# Fix CI Failures
|
||||
|
||||
You are tasked with analyzing CI failure logs and fixing the issues. Follow these steps:
|
||||
|
||||
## Context Provided
|
||||
|
||||
$ARGUMENTS
|
||||
|
||||
## Step 1: Analyze the Failure
|
||||
|
||||
Parse the provided CI failure information to understand:
|
||||
- Which jobs failed and why
|
||||
- The specific error messages and stack traces
|
||||
- Whether failures are test-related, build-related, or linting issues
|
||||
|
||||
## Step 2: Search and Understand the Codebase
|
||||
|
||||
Use search tools to locate the failing code:
|
||||
- Search for the failing test names or functions
|
||||
- Find the source files mentioned in error messages
|
||||
- Review related configuration files (package.json, tsconfig.json, etc.)
|
||||
|
||||
## Step 3: Apply Targeted Fixes
|
||||
|
||||
Make minimal, focused changes:
|
||||
- **For test failures**: Determine if the test or implementation needs fixing
|
||||
- **For type errors**: Fix type definitions or correct the code logic
|
||||
- **For linting issues**: Apply formatting using the project's tools
|
||||
- **For build errors**: Resolve dependency or configuration issues
|
||||
- **For missing imports**: Add the necessary imports or install packages
|
||||
|
||||
Requirements:
|
||||
- Only fix the actual CI failures, avoid unrelated changes
|
||||
- Follow existing code patterns and conventions
|
||||
- Ensure changes are production-ready, not temporary hacks
|
||||
- Preserve existing functionality while fixing issues
|
||||
|
||||
## Step 4: Commit Changes
|
||||
|
||||
After applying fixes:
|
||||
1. Use the `mcp__github_file_ops__commit_files` tool to commit your changes
|
||||
2. Include a descriptive commit message explaining what was fixed
|
||||
3. Document which CI jobs/tests were addressed in the commit message
|
||||
4. Important: Use the MCP file ops tool to commit your changes
|
||||
|
||||
## Step 5: Verify Fixes Locally
|
||||
|
||||
Run available verification commands:
|
||||
- Execute the failing tests locally to confirm they pass
|
||||
- Run the project's lint command (check package.json for scripts)
|
||||
- Run type checking if available
|
||||
- Execute any build commands to ensure compilation succeeds
|
||||
|
||||
## Important Guidelines
|
||||
|
||||
- Focus exclusively on fixing the reported CI failures
|
||||
- Maintain code quality and follow the project's established patterns
|
||||
- If a fix requires significant refactoring, document why it's necessary
|
||||
- When multiple solutions exist, choose the simplest one that maintains code quality
|
||||
- Add clear comments only if the fix is non-obvious
|
||||
|
||||
Begin by analyzing the failure details provided above.
|
||||
@@ -56,7 +56,6 @@ async function run() {
|
||||
mode,
|
||||
githubToken,
|
||||
});
|
||||
core.setOutput("GITHUB_TOKEN", githubToken);
|
||||
|
||||
// MCP config is handled by individual modes (tag/agent) and included in their claude_args output
|
||||
|
||||
|
||||
@@ -111,29 +111,10 @@ export async function prepareMcpConfig(
|
||||
};
|
||||
}
|
||||
|
||||
// Include inline comment server for experimental review mode
|
||||
if (context.inputs.mode === "experimental-review" && context.isPR) {
|
||||
baseMcpConfig.mcpServers.github_inline_comment = {
|
||||
command: "bun",
|
||||
args: [
|
||||
"run",
|
||||
`${process.env.GITHUB_ACTION_PATH}/src/mcp/github-inline-comment-server.ts`,
|
||||
],
|
||||
env: {
|
||||
GITHUB_TOKEN: githubToken,
|
||||
REPO_OWNER: owner,
|
||||
REPO_NAME: repo,
|
||||
PR_NUMBER: context.entityNumber?.toString() || "",
|
||||
GITHUB_API_URL: GITHUB_API_URL,
|
||||
},
|
||||
};
|
||||
}
|
||||
// CI server is included when we have a workflow token and context is a PR
|
||||
const hasWorkflowToken = !!process.env.DEFAULT_WORKFLOW_TOKEN;
|
||||
|
||||
// Only add CI server if we have actions:read permission and we're in a PR context
|
||||
const hasActionsReadPermission =
|
||||
context.inputs.additionalPermissions.get("actions") === "read";
|
||||
|
||||
if (context.isPR && hasActionsReadPermission) {
|
||||
if (context.isPR && hasWorkflowToken) {
|
||||
// Verify the token actually has actions:read permission
|
||||
const actuallyHasPermission = await checkActionsReadPermission(
|
||||
process.env.DEFAULT_WORKFLOW_TOKEN || "",
|
||||
|
||||
@@ -2,16 +2,6 @@ import * as core from "@actions/core";
|
||||
import { mkdir, writeFile } from "fs/promises";
|
||||
import type { Mode, ModeOptions, ModeResult } from "../types";
|
||||
import type { PreparedContext } from "../../create-prompt/types";
|
||||
import { GITHUB_API_URL, GITHUB_SERVER_URL } from "../../github/api/config";
|
||||
import { fetchGitHubData } from "../../github/data/fetcher";
|
||||
import {
|
||||
formatContext,
|
||||
formatBody,
|
||||
formatComments,
|
||||
formatReviewComments,
|
||||
formatChangedFilesWithSHA
|
||||
} from "../../github/data/formatter";
|
||||
import { isEntityContext } from "../../github/context";
|
||||
|
||||
/**
|
||||
* Agent mode implementation.
|
||||
@@ -49,64 +39,19 @@ export const agentMode: Mode = {
|
||||
return false;
|
||||
},
|
||||
|
||||
async prepare({ context, githubToken, octokit }: ModeOptions): Promise<ModeResult> {
|
||||
async prepare({ context, githubToken }: ModeOptions): Promise<ModeResult> {
|
||||
// Agent mode handles automation events and any event with explicit prompts
|
||||
|
||||
console.log(`Agent mode: githubToken provided: ${!!githubToken}, length: ${githubToken?.length || 0}`);
|
||||
|
||||
// TODO: handle by createPrompt (similar to tag and review modes)
|
||||
// Create prompt directory
|
||||
await mkdir(`${process.env.RUNNER_TEMP}/claude-prompts`, {
|
||||
recursive: true,
|
||||
});
|
||||
|
||||
// Fetch GitHub context data if we're in an entity context (PR/issue)
|
||||
let githubContextPrefix = '';
|
||||
if (isEntityContext(context)) {
|
||||
try {
|
||||
const githubData = await fetchGitHubData({
|
||||
octokits: octokit,
|
||||
repository: `${context.repository.owner}/${context.repository.repo}`,
|
||||
prNumber: context.entityNumber.toString(),
|
||||
isPR: context.isPR,
|
||||
triggerUsername: context.actor,
|
||||
});
|
||||
|
||||
// Format the GitHub data into a readable context
|
||||
const formattedContext = formatContext(githubData.contextData, context.isPR);
|
||||
const formattedBody = githubData.contextData?.body
|
||||
? formatBody(githubData.contextData.body, githubData.imageUrlMap)
|
||||
: "No description provided";
|
||||
const formattedComments = formatComments(githubData.comments, githubData.imageUrlMap);
|
||||
|
||||
// Build the context prefix
|
||||
githubContextPrefix = `## GitHub Context
|
||||
|
||||
${formattedContext}
|
||||
|
||||
### Description
|
||||
${formattedBody}`;
|
||||
|
||||
if (formattedComments && formattedComments.trim()) {
|
||||
githubContextPrefix += `\n\n### Comments\n${formattedComments}`;
|
||||
}
|
||||
|
||||
if (context.isPR && githubData.changedFilesWithSHA) {
|
||||
const formattedFiles = formatChangedFilesWithSHA(githubData.changedFilesWithSHA);
|
||||
githubContextPrefix += `\n\n### Changed Files\n${formattedFiles}`;
|
||||
}
|
||||
|
||||
githubContextPrefix += '\n\n## Your Task\n\n';
|
||||
} catch (error) {
|
||||
console.warn('Failed to fetch GitHub context:', error);
|
||||
// Continue without GitHub context if fetching fails
|
||||
}
|
||||
}
|
||||
|
||||
// Write the prompt file with GitHub context prefix
|
||||
const userPrompt = context.inputs.prompt ||
|
||||
// Write the prompt file - the base action requires a prompt_file parameter.
|
||||
// Use the unified prompt field from v1.0.
|
||||
const promptContent =
|
||||
context.inputs.prompt ||
|
||||
`Repository: ${context.repository.owner}/${context.repository.repo}`;
|
||||
const promptContent = githubContextPrefix + userPrompt;
|
||||
|
||||
await writeFile(
|
||||
`${process.env.RUNNER_TEMP}/claude-prompts/claude-prompt.txt`,
|
||||
promptContent,
|
||||
@@ -115,12 +60,12 @@ ${formattedBody}`;
|
||||
// Agent mode: User has full control via claudeArgs
|
||||
// No default tools are enforced - Claude Code's defaults will apply
|
||||
|
||||
// Include both GitHub comment server and main GitHub MCP server by default
|
||||
// This ensures comprehensive GitHub tools work out of the box
|
||||
// Always include the GitHub comment server in agent mode
|
||||
// This ensures GitHub tools (PR reviews, comments, etc.) work out of the box
|
||||
// without requiring users to manually configure the MCP server
|
||||
const mcpConfig: any = {
|
||||
mcpServers: {
|
||||
// GitHub comment server for updating Claude comments
|
||||
github_comment: {
|
||||
"github-comment-server": {
|
||||
command: "bun",
|
||||
args: [
|
||||
"run",
|
||||
@@ -130,54 +75,33 @@ ${formattedBody}`;
|
||||
GITHUB_TOKEN: githubToken || "",
|
||||
REPO_OWNER: context.repository.owner,
|
||||
REPO_NAME: context.repository.repo,
|
||||
CLAUDE_COMMENT_ID: process.env.CLAUDE_COMMENT_ID || "",
|
||||
PR_NUMBER: (context as any).entityNumber?.toString() || process.env.GITHUB_EVENT_PULL_REQUEST_NUMBER || "",
|
||||
ISSUE_NUMBER: (context as any).entityNumber?.toString() || "",
|
||||
GITHUB_EVENT_NAME: process.env.GITHUB_EVENT_NAME || "",
|
||||
GITHUB_API_URL:
|
||||
process.env.GITHUB_API_URL || "https://api.github.com",
|
||||
},
|
||||
},
|
||||
// Main GitHub MCP server for comprehensive GitHub operations
|
||||
github: {
|
||||
command: "docker",
|
||||
args: [
|
||||
"run",
|
||||
"-i",
|
||||
"--rm",
|
||||
"-e",
|
||||
"GITHUB_PERSONAL_ACCESS_TOKEN",
|
||||
"-e",
|
||||
"GITHUB_HOST",
|
||||
"ghcr.io/github/github-mcp-server:sha-efef8ae", // https://github.com/github/github-mcp-server/releases/tag/v0.9.0
|
||||
],
|
||||
env: {
|
||||
GITHUB_PERSONAL_ACCESS_TOKEN: githubToken || "",
|
||||
GITHUB_HOST: GITHUB_SERVER_URL,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// Include inline comment server for PR contexts
|
||||
if (context.eventName === "pull_request" || context.eventName === "pull_request_review") {
|
||||
// Get PR number from the context payload
|
||||
const prNumber = (context as any).payload?.pull_request?.number ||
|
||||
(context as any).entityNumber ||
|
||||
"";
|
||||
|
||||
mcpConfig.mcpServers.github_inline_comment = {
|
||||
|
||||
// Add GitHub file ops server when using commit signing
|
||||
if (context.inputs?.useCommitSigning) {
|
||||
mcpConfig.mcpServers["github-file-ops-server"] = {
|
||||
command: "bun",
|
||||
args: [
|
||||
"run",
|
||||
`${process.env.GITHUB_ACTION_PATH}/src/mcp/github-inline-comment-server.ts`,
|
||||
`${process.env.GITHUB_ACTION_PATH}/src/mcp/github-file-ops-server.ts`,
|
||||
],
|
||||
env: {
|
||||
GITHUB_TOKEN: githubToken || "",
|
||||
REPO_OWNER: context.repository.owner,
|
||||
REPO_NAME: context.repository.repo,
|
||||
PR_NUMBER: prNumber.toString(),
|
||||
GITHUB_API_URL: process.env.GITHUB_API_URL || "https://api.github.com",
|
||||
BRANCH_NAME: "", // Agent mode doesn't pre-create branches
|
||||
BASE_BRANCH: "",
|
||||
REPO_DIR: process.env.GITHUB_WORKSPACE || process.cwd(),
|
||||
GITHUB_EVENT_NAME: process.env.GITHUB_EVENT_NAME || "",
|
||||
IS_PR: "false", // Agent mode doesn't create PRs by default
|
||||
GITHUB_API_URL:
|
||||
process.env.GITHUB_API_URL || "https://api.github.com",
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -200,12 +124,23 @@ ${formattedBody}`;
|
||||
}
|
||||
}
|
||||
|
||||
// Agent mode: pass through user's claude_args with MCP config
|
||||
// Agent mode: pass through user's claude_args with MCP config and allowed_tools
|
||||
const userClaudeArgs = process.env.CLAUDE_ARGS || "";
|
||||
const userAllowedTools = process.env.ALLOWED_TOOLS || "";
|
||||
const escapedMcpConfig = JSON.stringify(mcpConfig).replace(/'/g, "'\\''");
|
||||
const claudeArgs =
|
||||
`--mcp-config '${escapedMcpConfig}' ${userClaudeArgs}`.trim();
|
||||
core.setOutput("claude_args", claudeArgs);
|
||||
let claudeArgs = `--mcp-config '${escapedMcpConfig}'`;
|
||||
|
||||
// Add allowed_tools if specified
|
||||
if (userAllowedTools) {
|
||||
claudeArgs += ` --allowedTools "${userAllowedTools}"`;
|
||||
}
|
||||
|
||||
// Add user's additional claude_args
|
||||
if (userClaudeArgs) {
|
||||
claudeArgs += ` ${userClaudeArgs}`;
|
||||
}
|
||||
|
||||
core.setOutput("claude_args", claudeArgs.trim());
|
||||
|
||||
return {
|
||||
commentId: undefined,
|
||||
|
||||
13
test-failure.ts
Normal file
13
test-failure.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
// This file intentionally has TypeScript errors to trigger CI failure
|
||||
// Testing auto-fix with MCP file ops enabled
|
||||
const testFunction = (param: string): number => {
|
||||
// Type error: returning string instead of number
|
||||
return "this should be a number";
|
||||
}
|
||||
|
||||
// Syntax error: missing closing brace
|
||||
function brokenFunction() {
|
||||
console.log("missing closing brace"
|
||||
}
|
||||
|
||||
export { testFunction, brokenFunction };
|
||||
Reference in New Issue
Block a user