mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 23:14:13 +08:00
Compare commits
1 Commits
test-gh-co
...
ashwin/v1-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
25f9c680f7 |
38
.github/workflows/claude-auto-review-test.yml
vendored
38
.github/workflows/claude-auto-review-test.yml
vendored
@@ -1,38 +0,0 @@
|
|||||||
name: Auto review PRs
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
types: [opened, synchronize]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
auto-review:
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
id-token: write
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 1
|
|
||||||
|
|
||||||
- name: Auto review PR
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
prompt: |
|
|
||||||
Please review this PR and provide comprehensive feedback.
|
|
||||||
|
|
||||||
Focus 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).
|
|
||||||
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"
|
|
||||||
33
.github/workflows/claude-review.yml
vendored
Normal file
33
.github/workflows/claude-review.yml
vendored
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
name: Auto review PRs
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
auto-review:
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
id-token: write
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 1
|
||||||
|
|
||||||
|
- name: Auto review PR
|
||||||
|
uses: anthropics/claude-code-action@main
|
||||||
|
with:
|
||||||
|
direct_prompt: |
|
||||||
|
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: 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 }}
|
||||||
|
allowed_tools: "mcp__github__create_pending_pull_request_review,mcp__github__add_comment_to_pending_review,mcp__github__submit_pending_pull_request_review,mcp__github__get_pull_request_diff"
|
||||||
20
README.md
20
README.md
@@ -1,6 +1,6 @@
|
|||||||

|

|
||||||
|
|
||||||
# Claude Code Action - No Approval Test
|
# Claude Code Action
|
||||||
|
|
||||||
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.
|
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
|
## License
|
||||||
|
|
||||||
This project is licensed under the MIT License—see the LICENSE file for details.
|
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
|
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ runs:
|
|||||||
echo "Base-action dependencies installed"
|
echo "Base-action dependencies installed"
|
||||||
cd -
|
cd -
|
||||||
# Install Claude Code globally
|
# Install Claude Code globally
|
||||||
bun install -g @anthropic-ai/claude-code@1.0.72
|
bun install -g @anthropic-ai/claude-code@1.0.73
|
||||||
|
|
||||||
- name: Setup Network Restrictions
|
- name: Setup Network Restrictions
|
||||||
if: steps.prepare.outputs.contains_trigger == 'true' && inputs.experimental_allowed_domains != ''
|
if: steps.prepare.outputs.contains_trigger == 'true' && inputs.experimental_allowed_domains != ''
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ runs:
|
|||||||
|
|
||||||
- name: Install Claude Code
|
- name: Install Claude Code
|
||||||
shell: bash
|
shell: bash
|
||||||
run: bun install -g @anthropic-ai/claude-code@1.0.72
|
run: bun install -g @anthropic-ai/claude-code@1.0.73
|
||||||
|
|
||||||
- name: Run Claude Code Action
|
- name: Run Claude Code Action
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ async function run() {
|
|||||||
mode,
|
mode,
|
||||||
githubToken,
|
githubToken,
|
||||||
});
|
});
|
||||||
core.setOutput("GITHUB_TOKEN", githubToken);
|
|
||||||
|
|
||||||
// MCP config is handled by individual modes (tag/agent) and included in their claude_args output
|
// 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
|
// CI server is included when we have a workflow token and context is a PR
|
||||||
if (context.inputs.mode === "experimental-review" && context.isPR) {
|
const hasWorkflowToken = !!process.env.DEFAULT_WORKFLOW_TOKEN;
|
||||||
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,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only add CI server if we have actions:read permission and we're in a PR context
|
if (context.isPR && hasWorkflowToken) {
|
||||||
const hasActionsReadPermission =
|
|
||||||
context.inputs.additionalPermissions.get("actions") === "read";
|
|
||||||
|
|
||||||
if (context.isPR && hasActionsReadPermission) {
|
|
||||||
// Verify the token actually has actions:read permission
|
// Verify the token actually has actions:read permission
|
||||||
const actuallyHasPermission = await checkActionsReadPermission(
|
const actuallyHasPermission = await checkActionsReadPermission(
|
||||||
process.env.DEFAULT_WORKFLOW_TOKEN || "",
|
process.env.DEFAULT_WORKFLOW_TOKEN || "",
|
||||||
|
|||||||
@@ -2,16 +2,6 @@ import * as core from "@actions/core";
|
|||||||
import { mkdir, writeFile } from "fs/promises";
|
import { mkdir, writeFile } from "fs/promises";
|
||||||
import type { Mode, ModeOptions, ModeResult } from "../types";
|
import type { Mode, ModeOptions, ModeResult } from "../types";
|
||||||
import type { PreparedContext } from "../../create-prompt/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.
|
* Agent mode implementation.
|
||||||
@@ -49,64 +39,19 @@ export const agentMode: Mode = {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
async prepare({ context, githubToken, octokit }: ModeOptions): Promise<ModeResult> {
|
async prepare({ context }: ModeOptions): Promise<ModeResult> {
|
||||||
// Agent mode handles automation events and any event with explicit prompts
|
// 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
|
// Create prompt directory
|
||||||
await mkdir(`${process.env.RUNNER_TEMP}/claude-prompts`, {
|
await mkdir(`${process.env.RUNNER_TEMP}/claude-prompts`, {
|
||||||
recursive: true,
|
recursive: true,
|
||||||
});
|
});
|
||||||
|
// Write the prompt file - the base action requires a prompt_file parameter.
|
||||||
// Fetch GitHub context data if we're in an entity context (PR/issue)
|
// Use the unified prompt field from v1.0.
|
||||||
let githubContextPrefix = '';
|
const promptContent =
|
||||||
if (isEntityContext(context)) {
|
context.inputs.prompt ||
|
||||||
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 ||
|
|
||||||
`Repository: ${context.repository.owner}/${context.repository.repo}`;
|
`Repository: ${context.repository.owner}/${context.repository.repo}`;
|
||||||
const promptContent = githubContextPrefix + userPrompt;
|
|
||||||
|
|
||||||
await writeFile(
|
await writeFile(
|
||||||
`${process.env.RUNNER_TEMP}/claude-prompts/claude-prompt.txt`,
|
`${process.env.RUNNER_TEMP}/claude-prompts/claude-prompt.txt`,
|
||||||
promptContent,
|
promptContent,
|
||||||
@@ -115,73 +60,29 @@ ${formattedBody}`;
|
|||||||
// Agent mode: User has full control via claudeArgs
|
// Agent mode: User has full control via claudeArgs
|
||||||
// No default tools are enforced - Claude Code's defaults will apply
|
// No default tools are enforced - Claude Code's defaults will apply
|
||||||
|
|
||||||
// Include both GitHub comment server and main GitHub MCP server by default
|
// Always include the GitHub comment server in agent mode
|
||||||
// This ensures comprehensive GitHub tools work out of the box
|
// 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 = {
|
const mcpConfig: any = {
|
||||||
mcpServers: {
|
mcpServers: {
|
||||||
// GitHub comment server for updating Claude comments
|
"github-comment-server": {
|
||||||
github_comment: {
|
|
||||||
command: "bun",
|
command: "bun",
|
||||||
args: [
|
args: [
|
||||||
"run",
|
"run",
|
||||||
`${process.env.GITHUB_ACTION_PATH}/src/mcp/github-comment-server.ts`,
|
`${process.env.GITHUB_ACTION_PATH}/src/mcp/github-comment-server.ts`,
|
||||||
],
|
],
|
||||||
env: {
|
env: {
|
||||||
GITHUB_TOKEN: githubToken || "",
|
GITHUB_TOKEN: process.env.GITHUB_TOKEN || "",
|
||||||
REPO_OWNER: context.repository.owner,
|
REPO_OWNER: context.repository.owner,
|
||||||
REPO_NAME: context.repository.repo,
|
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_EVENT_NAME: process.env.GITHUB_EVENT_NAME || "",
|
||||||
GITHUB_API_URL:
|
GITHUB_API_URL:
|
||||||
process.env.GITHUB_API_URL || "https://api.github.com",
|
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 = {
|
|
||||||
command: "bun",
|
|
||||||
args: [
|
|
||||||
"run",
|
|
||||||
`${process.env.GITHUB_ACTION_PATH}/src/mcp/github-inline-comment-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",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add user-provided additional MCP config if any
|
// Add user-provided additional MCP config if any
|
||||||
const additionalMcpConfig = process.env.MCP_CONFIG || "";
|
const additionalMcpConfig = process.env.MCP_CONFIG || "";
|
||||||
if (additionalMcpConfig.trim()) {
|
if (additionalMcpConfig.trim()) {
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
Custom prompt content
|
|
||||||
Reference in New Issue
Block a user