Compare commits

..

24 Commits

Author SHA1 Message Date
Bastian Gutschke
a39f0435dc feat: use dynamic fetch depth based on PR commit count
- Replace fixed depth of 20 with dynamic calculation
- Use Math.max(commitCount, 20) to ensure minimum context
2025-06-13 07:56:14 +02:00
Ashwin Bhat
41dd0aa695 feat: use GitHub display name in Co-authored-by trailers (#163)
* feat: use GitHub display name in Co-authored-by trailers

- Add name field to GitHubAuthor type
- Update GraphQL queries to fetch user display names
- Add triggerDisplayName to CommonFields type
- Extract display name from fetched GitHub data in prepareContext
- Update Co-authored-by trailer generation to use display name when available

This ensures consistency with GitHub's web interface behavior where
Co-authored-by trailers use the user's display name rather than username.

Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com>

* fix: update GraphQL queries to handle Actor type correctly

The name field is only available on the User subtype of Actor in GitHub's
GraphQL API. This commit updates the queries to use inline fragments
(... on User) to conditionally access the name field when the actor is
a User type.

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

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor: clarify Co-authored-by instructions in prompt

Replace interpolated values with clear references to XML tags and add
explicit formatting instructions. This makes it clearer how to use the
GitHub display name when available while maintaining the username for
the email portion.

Changes:
- Use explicit references to <trigger_display_name> and <trigger_username> tags
- Add clear formatting instructions and example
- Explain fallback behavior when display name is not available

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

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: fetch trigger user display name via dedicated GraphQL query

Instead of trying to extract the display name from existing data (which
was incomplete due to Actor type limitations), we now:

- Add a dedicated USER_QUERY to fetch user display names
- Pass the trigger username to fetchGitHubData
- Fetch the display name during data collection phase
- Simplify prepareContext to use the pre-fetched display name

This ensures we always get the correct display name for Co-authored-by
trailers, regardless of where the trigger came from.

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

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
2025-06-12 18:16:36 -04:00
GitHub Actions
55966a1dc0 chore: update claude-code-base-action to v0.0.19 2025-06-12 21:55:17 +00:00
GitHub Actions
b10f287695 chore: update claude-code-base-action to v0.0.18 2025-06-11 23:01:51 +00:00
GitHub Actions
56d8eac7ce chore: update claude-code-base-action to v0.0.17 2025-06-11 22:03:34 +00:00
Ashwin Bhat
25f9b8ef9e fix: add baseUrl to Octokit initialization in update_claude_comment (#157)
* fix: add baseUrl to Octokit initialization in update_claude_comment

Fixes Bad credentials error on GitHub Enterprise Server by passing
GITHUB_API_URL as baseUrl when initializing Octokit, consistent with
other Octokit instances in the codebase.

Fixes #156
Related to #107

Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com>

* fix: pass GITHUB_API_URL as env var to MCP server

Update the MCP server initialization to pass GITHUB_API_URL as an
environment variable, allowing it to work correctly with GitHub
Enterprise Server instances.

Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com>

* fix: import GITHUB_API_URL from config in install-mcp-server

Use the centralized GITHUB_API_URL constant from src/github/api/config.ts instead of reading directly from process.env when passing environment variables to the MCP server. This ensures consistency with how the API URL is handled throughout the codebase.

Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com>

* fix

---------

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com>
2025-06-11 17:45:05 -04:00
Ashwin Bhat
3bcfbe7385 feat: add MultiEdit to base_allowed_tools (#155)
Add MultiEdit tool to the BASE_ALLOWED_TOOLS array to enable Claude Code to use the MultiEdit tool for making multiple edits to a single file in one operation.

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com>
2025-06-10 19:36:52 -04:00
GitHub Actions
bdd0c925cb chore: update claude-code-base-action to v0.0.14 2025-06-10 19:08:55 +00:00
atsushi-ishibashi
37ec8e4781 fix: set disallowed_tools as env when runing prepare.ts (#151) 2025-06-10 08:59:55 -04:00
Ashwin Bhat
e5b1633249 feat: add roadmap for Claude Code GitHub Action v1.0 (#150)
Add ROADMAP.md documenting planned features and improvements for reaching v1.0:
- GitHub Action CI results visibility
- Cross-repo support
- Workflow file modification capabilities
- Additional event trigger support
- Configurable commit signing
- Enhanced code review features
- Bot user trigger support
- Customizable base prompts

The roadmap provides transparency on development priorities and invites
community feedback and contributions.
2025-06-09 18:58:08 -04:00
Ashwin Bhat
37483ba112 feat: add max_turns parameter support (#149)
* feat: add max_turns parameter support

- Add max_turns input to action.yml with proper description
- Pass max_turns parameter through to claude-code-base-action
- Update README with documentation and examples for max_turns usage
- Add comprehensive tests to verify max_turns configuration
- Add yaml dependency for test parsing

Closes #148

Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com>

* chore: remove max-turns test and yaml dependency

Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com>

* chore: revert package.json and bun.lock changes

Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com>

* Update action.yml

* prettier

---------

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com>
2025-06-09 13:28:22 -04:00
Sepehr Sobhani
9b50f473cb Update allowed tools align with what is available in github-mcp-server (#145) 2025-06-08 16:24:25 -04:00
GitHub Actions
47ea5c2a69 chore: update claude-code-base-action to v0.0.13 2025-06-06 19:44:49 +00:00
GitHub Actions
4bd9c2053a chore: update claude-code-base-action to v0.0.12 2025-06-06 15:30:07 +00:00
GitHub Actions
f862b5a16a chore: update claude-code-base-action to v0.0.11 2025-06-05 23:19:03 +00:00
Ashwin Bhat
424d1b8f87 update package name (#135) 2025-06-05 13:41:23 -07:00
David Dworken
1d5e695d0c Update package name to reference under the @Anthropic-AI NPM org (#134) 2025-06-05 13:28:36 -07:00
Ashwin Bhat
8e8be41f15 fix: replace github.action_path with GITHUB_ACTION_PATH for containerized workflows (#133)
This change fixes an issue where the action fails in containerized workflow 
jobs. By using ${GITHUB_ACTION_PATH} instead of ${{ github.action_path }}, 
the action can properly locate its resources in container environments.

Fixes #132

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com>
2025-06-05 10:10:43 -07:00
Ashwin Bhat
c7957fda5d chore: update claude-code-base-action to v0.0.10 (#131) 2025-06-05 09:59:42 -07:00
Minsu Lee
1990b0bdb3 Update temp directory paths to use runner temp directory (#129)
* Update temp directory paths to use `runner` temp directory

* Update temp directory paths to use `runner` temp directory
2025-06-05 09:53:56 -07:00
Ashwin Bhat
699aa26b41 fix: only load GitHub MCP server when its tools are allowed (#124)
* fix: only load GitHub MCP server when its tools are allowed

- Add allowedTools parameter to prepareMcpConfig
- Check for mcp__github__ and mcp__github_file_ops__ tool prefixes
- Only include MCP servers when their tools are in allowed_tools
- Maintain backward compatibility when allowed_tools is not specified
- Update tests to reflect the new conditional loading behavior

This optimizes resource usage by not loading unnecessary MCP servers
when their tools are not allowed in the configuration.

Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com>

* fix: always load github_file_ops server regardless of allowed_tools

- Only apply conditional loading to the github MCP server
- Always load github_file_ops server as it contains essential tools
- Update tests to reflect this behavior

Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com>

* refactor: move allowedTools/disallowedTools parsing to parseGitHubContext

- Change allowedTools and disallowedTools from string to string[] in ParsedGitHubContext type
- Parse comma-separated environment variables into arrays in parseGitHubContext function
- Update create-prompt and install-mcp-server to use pre-parsed arrays
- Update all affected test files to use array syntax
- Eliminate duplicate parsing logic across the codebase

* style: apply prettier formatting

---------

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com>
2025-06-04 11:56:56 -07:00
Ashwin Bhat
94c0c31c1b chore: switch to upstream github-mcp-server v0.4.0 (#126)
* chore: switch to upstream github-mcp-server v0.4.0

Switch from anthropics fork to github/github-mcp-server at commit e9f748f
(version 0.4.0) as requested.

Release link: https://github.com/github/github-mcp-server/releases/tag/v0.4.0

Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com>

* fix comment

---------

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com>
2025-06-04 11:42:57 -07:00
Robb Walters
be799cbe7b fix: skip SHA computation for deleted files (#115) 2025-06-03 13:40:52 -07:00
Ashwin Bhat
bd71ac0e8f fix: wrap github MCP config with mcpServers in issue-triage workflow (#118)
Update the MCP configuration structure to properly wrap the github
server configuration within an mcpServers object, matching the
expected format for MCP config files.

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

Co-authored-by: Claude <noreply@anthropic.com>
2025-06-03 11:31:04 -07:00
23 changed files with 311 additions and 107 deletions

View File

@@ -29,4 +29,4 @@ jobs:
Be constructive and specific in your feedback. Give inline comments where applicable.
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
allowed_tools: "mcp__github__add_pull_request_review_comment"
allowed_tools: "mcp__github__create_pending_pull_request_review,mcp__github__add_pull_request_review_comment_to_pending_review,mcp__github__submit_pending_pull_request_review,mcp__github__get_pull_request_diff"

View File

@@ -23,6 +23,7 @@ jobs:
mkdir -p /tmp/mcp-config
cat > /tmp/mcp-config/mcp-servers.json << 'EOF'
{
"mcpServers": {
"github": {
"command": "docker",
"args": [
@@ -38,6 +39,7 @@ jobs:
}
}
}
}
EOF
- name: Create triage prompt

View File

@@ -70,6 +70,8 @@ jobs:
# NODE_ENV: test
# DEBUG: true
# API_URL: https://api.example.com
# Optional: limit the number of conversation turns
# max_turns: "5"
```
## Inputs
@@ -78,6 +80,7 @@ jobs:
| --------------------- | -------------------------------------------------------------------------------------------------------------------- | -------- | --------- |
| `anthropic_api_key` | Anthropic API key (required for direct API, not needed for Bedrock/Vertex) | No\* | - |
| `direct_prompt` | Direct prompt for Claude to execute automatically without needing a trigger (for automated workflows) | No | - |
| `max_turns` | Maximum number of conversation turns Claude can take (limits back-and-forth exchanges) | No | - |
| `timeout_minutes` | Timeout in minutes for execution | No | `30` |
| `github_token` | GitHub token for Claude to operate with. **Only include this if you're connecting a custom GitHub app of your own!** | No | - |
| `model` | Model to use (provider-specific format required for Bedrock/Vertex) | No | - |
@@ -311,6 +314,24 @@ You can pass custom environment variables to Claude Code execution using the `cl
The `claude_env` input accepts YAML format where each line defines a key-value pair. These environment variables will be available to Claude Code during execution, allowing it to run tests, build processes, or other commands that depend on specific environment configurations.
### Limiting Conversation Turns
You can use the `max_turns` parameter to limit the number of back-and-forth exchanges Claude can have during task execution. This is useful for:
- Controlling costs by preventing runaway conversations
- Setting time boundaries for automated workflows
- Ensuring predictable behavior in CI/CD pipelines
```yaml
- uses: anthropics/claude-code-action@beta
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
max_turns: "5" # Limit to 5 conversation turns
# ... other inputs
```
When the turn limit is reached, Claude will stop execution gracefully. Choose a value that gives Claude enough turns to complete typical tasks while preventing excessive usage.
### Custom Tools
By default, Claude only has access to:

20
ROADMAP.md Normal file
View File

@@ -0,0 +1,20 @@
# Claude Code GitHub Action Roadmap
Thank you for trying out the beta of our GitHub Action! This document outlines our path to `v1.0`. Items are not necessarily in priority order.
## Path to 1.0
- **Ability to see GitHub Action CI results** - This will enable Claude to look at CI failures and make updates to PRs to fix test failures, lint errors, and the like.
- **Cross-repo support** - Enable Claude to work across multiple repositories in a single session
- **Ability to modify workflow files** - Let Claude update GitHub Actions workflows and other CI configuration files
- **Support for workflow_dispatch and repository_dispatch events** - Dispatch Claude on events triggered via API from other workflows or from other services
- **Ability to disable commit signing** - Option to turn off GPG signing for environments where it's not required. This will enable Claude to use normal `git` bash commands for committing. This will likely become the default behavior once added.
- **Better code review behavior** - Support inline comments on specific lines, provide higher quality reviews with more actionable feedback
- **Support triggering @claude from bot users** - Allow automation and bot accounts to invoke Claude
- **Customizable base prompts** - Full control over Claude's initial context with template variables like `$PR_COMMENTS`, `$PR_FILES`, etc. Users can replace our default prompt entirely while still accessing key contextual data
---
**Note:** This roadmap represents our current vision for reaching `v1.0` and is subject to change based on user feedback and development priorities.
We welcome feedback on these planned features! If you're interested in contributing to any of these features, please open an issue to discuss implementation details with us. We're also open to suggestions for new features not listed here.

View File

@@ -62,6 +62,10 @@ inputs:
required: false
default: "false"
max_turns:
description: "Maximum number of conversation turns"
required: false
default: ""
timeout_minutes:
description: "Timeout in minutes for execution"
required: false
@@ -83,19 +87,20 @@ runs:
- name: Install Dependencies
shell: bash
run: |
cd ${{ github.action_path }}
cd ${GITHUB_ACTION_PATH}
bun install
- name: Prepare action
id: prepare
shell: bash
run: |
bun run ${{ github.action_path }}/src/entrypoints/prepare.ts
bun run ${GITHUB_ACTION_PATH}/src/entrypoints/prepare.ts
env:
TRIGGER_PHRASE: ${{ inputs.trigger_phrase }}
ASSIGNEE_TRIGGER: ${{ inputs.assignee_trigger }}
BASE_BRANCH: ${{ inputs.base_branch }}
ALLOWED_TOOLS: ${{ inputs.allowed_tools }}
DISALLOWED_TOOLS: ${{ inputs.disallowed_tools }}
CUSTOM_INSTRUCTIONS: ${{ inputs.custom_instructions }}
DIRECT_PROMPT: ${{ inputs.direct_prompt }}
MCP_CONFIG: ${{ inputs.mcp_config }}
@@ -105,12 +110,13 @@ runs:
- name: Run Claude Code
id: claude-code
if: steps.prepare.outputs.contains_trigger == 'true'
uses: anthropics/claude-code-base-action@1370ac97fbba9bddec20ea2924b5726bf10d8b94 # v0.0.9
uses: anthropics/claude-code-base-action@ebd8558e902b3db132e89863de49565fcb9aec46 # v0.0.19
with:
prompt_file: /tmp/claude-prompts/claude-prompt.txt
prompt_file: ${{ runner.temp }}/claude-prompts/claude-prompt.txt
allowed_tools: ${{ env.ALLOWED_TOOLS }}
disallowed_tools: ${{ env.DISALLOWED_TOOLS }}
timeout_minutes: ${{ inputs.timeout_minutes }}
max_turns: ${{ inputs.max_turns }}
model: ${{ inputs.model || inputs.anthropic_model }}
mcp_config: ${{ steps.prepare.outputs.mcp_config }}
use_bedrock: ${{ inputs.use_bedrock }}
@@ -147,7 +153,7 @@ runs:
if: steps.prepare.outputs.contains_trigger == 'true' && steps.prepare.outputs.claude_comment_id && always()
shell: bash
run: |
bun run ${{ github.action_path }}/src/entrypoints/update-comment-link.ts
bun run ${GITHUB_ACTION_PATH}/src/entrypoints/update-comment-link.ts
env:
REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ github.event.issue.number || github.event.pull_request.number }}

View File

@@ -2,7 +2,7 @@
"lockfileVersion": 1,
"workspaces": {
"": {
"name": "claude-pr-action",
"name": "@anthropic-ai/claude-code-action",
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.1",

View File

@@ -35,4 +35,4 @@ jobs:
Provide constructive feedback with specific suggestions for improvement.
Use inline comments to highlight specific areas of concern.
# allowed_tools: "mcp__github__add_pull_request_review_comment"
# allowed_tools: "mcp__github__create_pending_pull_request_review,mcp__github__add_pull_request_review_comment_to_pending_review,mcp__github__submit_pending_pull_request_review,mcp__github__get_pull_request_diff"

View File

@@ -1,5 +1,5 @@
{
"name": "claude-pr-action",
"name": "@anthropic-ai/claude-code-action",
"version": "1.0.0",
"private": true,
"scripts": {

View File

@@ -24,6 +24,7 @@ export type { CommonFields, PreparedContext } from "./types";
const BASE_ALLOWED_TOOLS = [
"Edit",
"MultiEdit",
"Glob",
"Grep",
"LS",
@@ -35,38 +36,35 @@ const BASE_ALLOWED_TOOLS = [
];
const DISALLOWED_TOOLS = ["WebSearch", "WebFetch"];
export function buildAllowedToolsString(customAllowedTools?: string): string {
export function buildAllowedToolsString(customAllowedTools?: string[]): string {
let baseTools = [...BASE_ALLOWED_TOOLS];
let allAllowedTools = baseTools.join(",");
if (customAllowedTools) {
allAllowedTools = `${allAllowedTools},${customAllowedTools}`;
if (customAllowedTools && customAllowedTools.length > 0) {
allAllowedTools = `${allAllowedTools},${customAllowedTools.join(",")}`;
}
return allAllowedTools;
}
export function buildDisallowedToolsString(
customDisallowedTools?: string,
allowedTools?: string,
customDisallowedTools?: string[],
allowedTools?: string[],
): string {
let disallowedTools = [...DISALLOWED_TOOLS];
// If user has explicitly allowed some hardcoded disallowed tools, remove them from disallowed list
if (allowedTools) {
const allowedToolsArray = allowedTools
.split(",")
.map((tool) => tool.trim());
if (allowedTools && allowedTools.length > 0) {
disallowedTools = disallowedTools.filter(
(tool) => !allowedToolsArray.includes(tool),
(tool) => !allowedTools.includes(tool),
);
}
let allDisallowedTools = disallowedTools.join(",");
if (customDisallowedTools) {
if (customDisallowedTools && customDisallowedTools.length > 0) {
if (allDisallowedTools) {
allDisallowedTools = `${allDisallowedTools},${customDisallowedTools}`;
allDisallowedTools = `${allDisallowedTools},${customDisallowedTools.join(",")}`;
} else {
allDisallowedTools = customDisallowedTools;
allDisallowedTools = customDisallowedTools.join(",");
}
}
return allDisallowedTools;
@@ -120,8 +118,10 @@ export function prepareContext(
triggerPhrase,
...(triggerUsername && { triggerUsername }),
...(customInstructions && { customInstructions }),
...(allowedTools && { allowedTools }),
...(disallowedTools && { disallowedTools }),
...(allowedTools.length > 0 && { allowedTools: allowedTools.join(",") }),
...(disallowedTools.length > 0 && {
disallowedTools: disallowedTools.join(","),
}),
...(directPrompt && { directPrompt }),
...(claudeBranch && { claudeBranch }),
};
@@ -418,6 +418,7 @@ ${
}
<claude_comment_id>${context.claudeCommentId}</claude_comment_id>
<trigger_username>${context.triggerUsername ?? "Unknown"}</trigger_username>
<trigger_display_name>${githubData.triggerDisplayName ?? context.triggerUsername ?? "Unknown"}</trigger_display_name>
<trigger_phrase>${context.triggerPhrase}</trigger_phrase>
${
(eventData.eventName === "issue_comment" ||
@@ -503,12 +504,14 @@ ${context.directPrompt ? ` - DIRECT INSTRUCTION: A direct instruction was prov
? `
- Push directly using mcp__github_file_ops__commit_files to the existing branch (works for both new and existing files).
- Use mcp__github_file_ops__commit_files to commit files atomically in a single commit (supports single or multiple files).
- When pushing changes with this tool and TRIGGER_USERNAME is not "Unknown", include a "Co-authored-by: ${context.triggerUsername} <${context.triggerUsername}@users.noreply.github.com>" line in the commit message.`
- When pushing changes with this tool and the trigger user is not "Unknown", include a Co-authored-by trailer in the commit message.
- Use: "Co-authored-by: ${githubData.triggerDisplayName ?? context.triggerUsername} <${context.triggerUsername}@users.noreply.github.com>"`
: `
- You are already on the correct branch (${eventData.claudeBranch || "the PR branch"}). Do not create a new branch.
- Push changes directly to the current branch using mcp__github_file_ops__commit_files (works for both new and existing files)
- Use mcp__github_file_ops__commit_files to commit files atomically in a single commit (supports single or multiple files).
- When pushing changes and TRIGGER_USERNAME is not "Unknown", include a "Co-authored-by: ${context.triggerUsername} <${context.triggerUsername}@users.noreply.github.com>" line in the commit message.
- When pushing changes and the trigger user is not "Unknown", include a Co-authored-by trailer in the commit message.
- Use: "Co-authored-by: ${githubData.triggerDisplayName ?? context.triggerUsername} <${context.triggerUsername}@users.noreply.github.com>"
${
eventData.claudeBranch
? `- Provide a URL to create a PR manually in this format:
@@ -621,7 +624,9 @@ export async function createPrompt(
claudeBranch,
);
await mkdir("/tmp/claude-prompts", { recursive: true });
await mkdir(`${process.env.RUNNER_TEMP}/claude-prompts`, {
recursive: true,
});
// Generate the prompt
const promptContent = generatePrompt(preparedContext, githubData);
@@ -632,15 +637,18 @@ export async function createPrompt(
console.log("=======================");
// Write the prompt file
await writeFile("/tmp/claude-prompts/claude-prompt.txt", promptContent);
await writeFile(
`${process.env.RUNNER_TEMP}/claude-prompts/claude-prompt.txt`,
promptContent,
);
// Set allowed tools
const allAllowedTools = buildAllowedToolsString(
preparedContext.allowedTools,
context.inputs.allowedTools,
);
const allDisallowedTools = buildDisallowedToolsString(
preparedContext.disallowedTools,
preparedContext.allowedTools,
context.inputs.disallowedTools,
context.inputs.allowedTools,
);
core.exportVariable("ALLOWED_TOOLS", allAllowedTools);

View File

@@ -59,6 +59,7 @@ async function run() {
repository: `${context.repository.owner}/${context.repository.repo}`,
prNumber: context.entityNumber.toString(),
isPR: context.isPR,
triggerUsername: context.actor,
});
// Step 8: Setup branch
@@ -92,6 +93,7 @@ async function run() {
branch: branchInfo.currentBranch,
additionalMcpConfig,
claudeCommentId: commentId.toString(),
allowedTools: context.inputs.allowedTools,
});
core.setOutput("mcp_config", mcpConfig);
} catch (error) {

View File

@@ -104,3 +104,11 @@ export const ISSUE_QUERY = `
}
}
`;
export const USER_QUERY = `
query($login: String!) {
user(login: $login) {
name
}
}
`;

View File

@@ -28,8 +28,8 @@ export type ParsedGitHubContext = {
inputs: {
triggerPhrase: string;
assigneeTrigger: string;
allowedTools: string;
disallowedTools: string;
allowedTools: string[];
disallowedTools: string[];
customInstructions: string;
directPrompt: string;
baseBranch?: string;
@@ -52,8 +52,14 @@ export function parseGitHubContext(): ParsedGitHubContext {
inputs: {
triggerPhrase: process.env.TRIGGER_PHRASE ?? "@claude",
assigneeTrigger: process.env.ASSIGNEE_TRIGGER ?? "",
allowedTools: process.env.ALLOWED_TOOLS ?? "",
disallowedTools: process.env.DISALLOWED_TOOLS ?? "",
allowedTools: (process.env.ALLOWED_TOOLS ?? "")
.split(",")
.map((tool) => tool.trim())
.filter((tool) => tool.length > 0),
disallowedTools: (process.env.DISALLOWED_TOOLS ?? "")
.split(",")
.map((tool) => tool.trim())
.filter((tool) => tool.length > 0),
customInstructions: process.env.CUSTOM_INSTRUCTIONS ?? "",
directPrompt: process.env.DIRECT_PROMPT ?? "",
baseBranch: process.env.BASE_BRANCH,

View File

@@ -1,23 +1,24 @@
import { execSync } from "child_process";
import type { Octokits } from "../api/client";
import { ISSUE_QUERY, PR_QUERY, USER_QUERY } from "../api/queries/github";
import type {
GitHubPullRequest,
GitHubIssue,
GitHubComment,
GitHubFile,
GitHubIssue,
GitHubPullRequest,
GitHubReview,
PullRequestQueryResponse,
IssueQueryResponse,
PullRequestQueryResponse,
} from "../types";
import { PR_QUERY, ISSUE_QUERY } from "../api/queries/github";
import type { Octokits } from "../api/client";
import { downloadCommentImages } from "../utils/image-downloader";
import type { CommentWithImages } from "../utils/image-downloader";
import { downloadCommentImages } from "../utils/image-downloader";
type FetchDataParams = {
octokits: Octokits;
repository: string;
prNumber: string;
isPR: boolean;
triggerUsername?: string;
};
export type GitHubFileWithSHA = GitHubFile & {
@@ -31,6 +32,7 @@ export type FetchDataResult = {
changedFilesWithSHA: GitHubFileWithSHA[];
reviewData: { nodes: GitHubReview[] } | null;
imageUrlMap: Map<string, string>;
triggerDisplayName?: string | null;
};
export async function fetchGitHubData({
@@ -38,6 +40,7 @@ export async function fetchGitHubData({
repository,
prNumber,
isPR,
triggerUsername,
}: FetchDataParams): Promise<FetchDataResult> {
const [owner, repo] = repository.split("/");
if (!owner || !repo) {
@@ -101,6 +104,14 @@ export async function fetchGitHubData({
let changedFilesWithSHA: GitHubFileWithSHA[] = [];
if (isPR && changedFiles.length > 0) {
changedFilesWithSHA = changedFiles.map((file) => {
// Don't compute SHA for deleted files
if (file.changeType === "DELETED") {
return {
...file,
sha: "deleted",
};
}
try {
// Use git hash-object to compute the SHA for the current file content
const sha = execSync(`git hash-object "${file.path}"`, {
@@ -183,6 +194,12 @@ export async function fetchGitHubData({
allComments,
);
// Fetch trigger user display name if username is provided
let triggerDisplayName: string | null | undefined;
if (triggerUsername) {
triggerDisplayName = await fetchUserDisplayName(octokits, triggerUsername);
}
return {
contextData,
comments,
@@ -190,5 +207,27 @@ export async function fetchGitHubData({
changedFilesWithSHA,
reviewData,
imageUrlMap,
triggerDisplayName,
};
}
export type UserQueryResponse = {
user: {
name: string | null;
};
};
export async function fetchUserDisplayName(
octokits: Octokits,
login: string,
): Promise<string | null> {
try {
const result = await octokits.graphql<UserQueryResponse>(USER_QUERY, {
login,
});
return result.user.name;
} catch (error) {
console.warn(`Failed to fetch user display name for ${login}:`, error);
return null;
}
}

View File

@@ -45,9 +45,16 @@ export async function setupBranch(
const branchName = prData.headRefName;
// Execute git commands to checkout PR branch (shallow fetch for performance)
// Fetch the branch with a depth of 20 to avoid fetching too much history, while still allowing for some context
await $`git fetch origin --depth=20 ${branchName}`;
// Determine optimal fetch depth based on PR commit count, with a minimum of 20
const commitCount = prData.commits.totalCount;
const fetchDepth = Math.max(commitCount, 20);
console.log(
`PR #${entityNumber}: ${commitCount} commits, using fetch depth ${fetchDepth}`,
);
// Execute git commands to checkout PR branch (dynamic depth based on PR size)
await $`git fetch origin --depth=${fetchDepth} ${branchName}`;
await $`git checkout ${branchName}`;
console.log(`Successfully checked out PR branch for PR #${entityNumber}`);

View File

@@ -1,6 +1,7 @@
// Types for GitHub GraphQL query responses
export type GitHubAuthor = {
login: string;
name?: string;
};
export type GitHubComment = {

View File

@@ -466,6 +466,7 @@ server.tool(
const octokit = new Octokit({
auth: githubToken,
baseUrl: GITHUB_API_URL,
});
const isPullRequestReviewComment =

View File

@@ -1,4 +1,5 @@
import * as core from "@actions/core";
import { GITHUB_API_URL } from "../github/api/config";
type PrepareConfigParams = {
githubToken: string;
@@ -7,6 +8,7 @@ type PrepareConfigParams = {
branch: string;
additionalMcpConfig?: string;
claudeCommentId?: string;
allowedTools: string[];
};
export async function prepareMcpConfig(
@@ -19,24 +21,17 @@ export async function prepareMcpConfig(
branch,
additionalMcpConfig,
claudeCommentId,
allowedTools,
} = params;
try {
const baseMcpConfig = {
const allowedToolsList = allowedTools || [];
const hasGitHubMcpTools = allowedToolsList.some((tool) =>
tool.startsWith("mcp__github__"),
);
const baseMcpConfig: { mcpServers: Record<string, unknown> } = {
mcpServers: {
github: {
command: "docker",
args: [
"run",
"-i",
"--rm",
"-e",
"GITHUB_PERSONAL_ACCESS_TOKEN",
"ghcr.io/anthropics/github-mcp-server:sha-7382253",
],
env: {
GITHUB_PERSONAL_ACCESS_TOKEN: githubToken,
},
},
github_file_ops: {
command: "bun",
args: [
@@ -52,11 +47,29 @@ export async function prepareMcpConfig(
...(claudeCommentId && { CLAUDE_COMMENT_ID: claudeCommentId }),
GITHUB_EVENT_NAME: process.env.GITHUB_EVENT_NAME || "",
IS_PR: process.env.IS_PR || "false",
GITHUB_API_URL: GITHUB_API_URL,
},
},
},
};
if (hasGitHubMcpTools) {
baseMcpConfig.mcpServers.github = {
command: "docker",
args: [
"run",
"-i",
"--rm",
"-e",
"GITHUB_PERSONAL_ACCESS_TOKEN",
"ghcr.io/github/github-mcp-server:sha-e9f748f", // https://github.com/github/github-mcp-server/releases/tag/v0.4.0
],
env: {
GITHUB_PERSONAL_ACCESS_TOKEN: githubToken,
},
};
}
// Merge with additional MCP config if provided
if (additionalMcpConfig && additionalMcpConfig.trim()) {
try {

View File

@@ -316,7 +316,7 @@ describe("generatePrompt", () => {
expect(prompt).toContain("<trigger_username>johndoe</trigger_username>");
expect(prompt).toContain(
"Co-authored-by: johndoe <johndoe@users.noreply.github.com>",
'Use: "Co-authored-by: johndoe <johndoe@users.noreply.github.com>"',
);
});
@@ -652,7 +652,7 @@ describe("buildAllowedToolsString", () => {
});
test("should append custom tools when provided", () => {
const customTools = "Tool1,Tool2,Tool3";
const customTools = ["Tool1", "Tool2", "Tool3"];
const result = buildAllowedToolsString(customTools);
// Base tools should be present
@@ -683,7 +683,7 @@ describe("buildDisallowedToolsString", () => {
});
test("should append custom disallowed tools when provided", () => {
const customDisallowedTools = "BadTool1,BadTool2";
const customDisallowedTools = ["BadTool1", "BadTool2"];
const result = buildDisallowedToolsString(customDisallowedTools);
// Base disallowed tools should be present
@@ -701,8 +701,8 @@ describe("buildDisallowedToolsString", () => {
});
test("should remove hardcoded disallowed tools if they are in allowed tools", () => {
const customDisallowedTools = "BadTool1,BadTool2";
const allowedTools = "WebSearch,SomeOtherTool";
const customDisallowedTools = ["BadTool1", "BadTool2"];
const allowedTools = ["WebSearch", "SomeOtherTool"];
const result = buildDisallowedToolsString(
customDisallowedTools,
allowedTools,
@@ -720,7 +720,7 @@ describe("buildDisallowedToolsString", () => {
});
test("should remove all hardcoded disallowed tools if they are all in allowed tools", () => {
const allowedTools = "WebSearch,WebFetch,SomeOtherTool";
const allowedTools = ["WebSearch", "WebFetch", "SomeOtherTool"];
const result = buildDisallowedToolsString(undefined, allowedTools);
// Both hardcoded disallowed tools should be removed
@@ -732,8 +732,8 @@ describe("buildDisallowedToolsString", () => {
});
test("should handle custom disallowed tools when all hardcoded tools are overridden", () => {
const customDisallowedTools = "BadTool1,BadTool2";
const allowedTools = "WebSearch,WebFetch";
const customDisallowedTools = ["BadTool1", "BadTool2"];
const allowedTools = ["WebSearch", "WebFetch"];
const result = buildDisallowedToolsString(
customDisallowedTools,
allowedTools,

View File

@@ -24,21 +24,19 @@ describe("prepareMcpConfig", () => {
processExitSpy.mockRestore();
});
test("should return base config when no additional config is provided", async () => {
test("should return base config when no additional config is provided and no allowed_tools", async () => {
const result = await prepareMcpConfig({
githubToken: "test-token",
owner: "test-owner",
repo: "test-repo",
branch: "test-branch",
allowedTools: [],
});
const parsed = JSON.parse(result);
expect(parsed.mcpServers).toBeDefined();
expect(parsed.mcpServers.github).toBeDefined();
expect(parsed.mcpServers.github).not.toBeDefined();
expect(parsed.mcpServers.github_file_ops).toBeDefined();
expect(parsed.mcpServers.github.env.GITHUB_PERSONAL_ACCESS_TOKEN).toBe(
"test-token",
);
expect(parsed.mcpServers.github_file_ops.env.GITHUB_TOKEN).toBe(
"test-token",
);
@@ -49,6 +47,60 @@ describe("prepareMcpConfig", () => {
);
});
test("should include github MCP server when mcp__github__ tools are allowed", async () => {
const result = await prepareMcpConfig({
githubToken: "test-token",
owner: "test-owner",
repo: "test-repo",
branch: "test-branch",
allowedTools: [
"mcp__github__create_issue",
"mcp__github_file_ops__commit_files",
],
});
const parsed = JSON.parse(result);
expect(parsed.mcpServers).toBeDefined();
expect(parsed.mcpServers.github).toBeDefined();
expect(parsed.mcpServers.github_file_ops).toBeDefined();
expect(parsed.mcpServers.github.env.GITHUB_PERSONAL_ACCESS_TOKEN).toBe(
"test-token",
);
});
test("should not include github MCP server when only file_ops tools are allowed", async () => {
const result = await prepareMcpConfig({
githubToken: "test-token",
owner: "test-owner",
repo: "test-repo",
branch: "test-branch",
allowedTools: [
"mcp__github_file_ops__commit_files",
"mcp__github_file_ops__update_claude_comment",
],
});
const parsed = JSON.parse(result);
expect(parsed.mcpServers).toBeDefined();
expect(parsed.mcpServers.github).not.toBeDefined();
expect(parsed.mcpServers.github_file_ops).toBeDefined();
});
test("should include file_ops server even when no GitHub tools are allowed", async () => {
const result = await prepareMcpConfig({
githubToken: "test-token",
owner: "test-owner",
repo: "test-repo",
branch: "test-branch",
allowedTools: ["Edit", "Read", "Write"],
});
const parsed = JSON.parse(result);
expect(parsed.mcpServers).toBeDefined();
expect(parsed.mcpServers.github).not.toBeDefined();
expect(parsed.mcpServers.github_file_ops).toBeDefined();
});
test("should return base config when additional config is empty string", async () => {
const result = await prepareMcpConfig({
githubToken: "test-token",
@@ -56,11 +108,12 @@ describe("prepareMcpConfig", () => {
repo: "test-repo",
branch: "test-branch",
additionalMcpConfig: "",
allowedTools: [],
});
const parsed = JSON.parse(result);
expect(parsed.mcpServers).toBeDefined();
expect(parsed.mcpServers.github).toBeDefined();
expect(parsed.mcpServers.github).not.toBeDefined();
expect(parsed.mcpServers.github_file_ops).toBeDefined();
expect(consoleWarningSpy).not.toHaveBeenCalled();
});
@@ -72,11 +125,12 @@ describe("prepareMcpConfig", () => {
repo: "test-repo",
branch: "test-branch",
additionalMcpConfig: " \n\t ",
allowedTools: [],
});
const parsed = JSON.parse(result);
expect(parsed.mcpServers).toBeDefined();
expect(parsed.mcpServers.github).toBeDefined();
expect(parsed.mcpServers.github).not.toBeDefined();
expect(parsed.mcpServers.github_file_ops).toBeDefined();
expect(consoleWarningSpy).not.toHaveBeenCalled();
});
@@ -100,6 +154,10 @@ describe("prepareMcpConfig", () => {
repo: "test-repo",
branch: "test-branch",
additionalMcpConfig: additionalConfig,
allowedTools: [
"mcp__github__create_issue",
"mcp__github_file_ops__commit_files",
],
});
const parsed = JSON.parse(result);
@@ -133,6 +191,10 @@ describe("prepareMcpConfig", () => {
repo: "test-repo",
branch: "test-branch",
additionalMcpConfig: additionalConfig,
allowedTools: [
"mcp__github__create_issue",
"mcp__github_file_ops__commit_files",
],
});
const parsed = JSON.parse(result);
@@ -169,12 +231,13 @@ describe("prepareMcpConfig", () => {
repo: "test-repo",
branch: "test-branch",
additionalMcpConfig: additionalConfig,
allowedTools: [],
});
const parsed = JSON.parse(result);
expect(parsed.customProperty).toBe("custom-value");
expect(parsed.anotherProperty).toEqual({ nested: "value" });
expect(parsed.mcpServers.github).toBeDefined();
expect(parsed.mcpServers.github).not.toBeDefined();
expect(parsed.mcpServers.custom_server).toBeDefined();
});
@@ -187,13 +250,14 @@ describe("prepareMcpConfig", () => {
repo: "test-repo",
branch: "test-branch",
additionalMcpConfig: invalidJson,
allowedTools: [],
});
const parsed = JSON.parse(result);
expect(consoleWarningSpy).toHaveBeenCalledWith(
expect.stringContaining("Failed to parse additional MCP config:"),
);
expect(parsed.mcpServers.github).toBeDefined();
expect(parsed.mcpServers.github).not.toBeDefined();
expect(parsed.mcpServers.github_file_ops).toBeDefined();
});
@@ -206,6 +270,7 @@ describe("prepareMcpConfig", () => {
repo: "test-repo",
branch: "test-branch",
additionalMcpConfig: nonObjectJson,
allowedTools: [],
});
const parsed = JSON.parse(result);
@@ -215,7 +280,7 @@ describe("prepareMcpConfig", () => {
expect(consoleWarningSpy).toHaveBeenCalledWith(
expect.stringContaining("MCP config must be a valid JSON object"),
);
expect(parsed.mcpServers.github).toBeDefined();
expect(parsed.mcpServers.github).not.toBeDefined();
expect(parsed.mcpServers.github_file_ops).toBeDefined();
});
@@ -228,6 +293,7 @@ describe("prepareMcpConfig", () => {
repo: "test-repo",
branch: "test-branch",
additionalMcpConfig: nullJson,
allowedTools: [],
});
const parsed = JSON.parse(result);
@@ -237,7 +303,7 @@ describe("prepareMcpConfig", () => {
expect(consoleWarningSpy).toHaveBeenCalledWith(
expect.stringContaining("MCP config must be a valid JSON object"),
);
expect(parsed.mcpServers.github).toBeDefined();
expect(parsed.mcpServers.github).not.toBeDefined();
expect(parsed.mcpServers.github_file_ops).toBeDefined();
});
@@ -250,6 +316,7 @@ describe("prepareMcpConfig", () => {
repo: "test-repo",
branch: "test-branch",
additionalMcpConfig: arrayJson,
allowedTools: [],
});
const parsed = JSON.parse(result);
@@ -258,7 +325,7 @@ describe("prepareMcpConfig", () => {
expect(consoleInfoSpy).toHaveBeenCalledWith(
"Merging additional MCP server configuration with built-in servers",
);
expect(parsed.mcpServers.github).toBeDefined();
expect(parsed.mcpServers.github).not.toBeDefined();
expect(parsed.mcpServers.github_file_ops).toBeDefined();
// The array will be spread into the config (0: 1, 1: 2, 2: 3)
expect(parsed[0]).toBe(1);
@@ -295,12 +362,13 @@ describe("prepareMcpConfig", () => {
repo: "test-repo",
branch: "test-branch",
additionalMcpConfig: additionalConfig,
allowedTools: [],
});
const parsed = JSON.parse(result);
expect(parsed.mcpServers.server1).toBeDefined();
expect(parsed.mcpServers.server2).toBeDefined();
expect(parsed.mcpServers.github).toBeDefined();
expect(parsed.mcpServers.github).not.toBeDefined();
expect(parsed.mcpServers.github_file_ops.command).toBe("overridden");
expect(parsed.mcpServers.github_file_ops.env.CUSTOM).toBe("value");
expect(parsed.otherConfig.nested.deeply).toBe("value");
@@ -315,6 +383,7 @@ describe("prepareMcpConfig", () => {
owner: "test-owner",
repo: "test-repo",
branch: "test-branch",
allowedTools: [],
});
const parsed = JSON.parse(result);
@@ -334,6 +403,7 @@ describe("prepareMcpConfig", () => {
owner: "test-owner",
repo: "test-repo",
branch: "test-branch",
allowedTools: [],
});
const parsed = JSON.parse(result);

View File

@@ -11,8 +11,8 @@ const defaultInputs = {
triggerPhrase: "/claude",
assigneeTrigger: "",
anthropicModel: "claude-3-7-sonnet-20250219",
allowedTools: "",
disallowedTools: "",
allowedTools: [] as string[],
disallowedTools: [] as string[],
customInstructions: "",
directPrompt: "",
useBedrock: false,

View File

@@ -62,8 +62,8 @@ describe("checkWritePermissions", () => {
inputs: {
triggerPhrase: "@claude",
assigneeTrigger: "",
allowedTools: "",
disallowedTools: "",
allowedTools: [],
disallowedTools: [],
customInstructions: "",
directPrompt: "",
},

View File

@@ -242,7 +242,7 @@ describe("parseEnvVarsWithContext", () => {
...mockPullRequestCommentContext,
inputs: {
...mockPullRequestCommentContext.inputs,
allowedTools: "Tool1,Tool2",
allowedTools: ["Tool1", "Tool2"],
},
});
const result = prepareContext(contextWithAllowedTools, "12345");

View File

@@ -30,8 +30,8 @@ describe("checkContainsTrigger", () => {
triggerPhrase: "/claude",
assigneeTrigger: "",
directPrompt: "Fix the bug in the login form",
allowedTools: "",
disallowedTools: "",
allowedTools: [],
disallowedTools: [],
customInstructions: "",
},
});
@@ -56,8 +56,8 @@ describe("checkContainsTrigger", () => {
triggerPhrase: "/claude",
assigneeTrigger: "",
directPrompt: "",
allowedTools: "",
disallowedTools: "",
allowedTools: [],
disallowedTools: [],
customInstructions: "",
},
});
@@ -228,8 +228,8 @@ describe("checkContainsTrigger", () => {
triggerPhrase: "@claude",
assigneeTrigger: "",
directPrompt: "",
allowedTools: "",
disallowedTools: "",
allowedTools: [],
disallowedTools: [],
customInstructions: "",
},
});
@@ -255,8 +255,8 @@ describe("checkContainsTrigger", () => {
triggerPhrase: "@claude",
assigneeTrigger: "",
directPrompt: "",
allowedTools: "",
disallowedTools: "",
allowedTools: [],
disallowedTools: [],
customInstructions: "",
},
});
@@ -282,8 +282,8 @@ describe("checkContainsTrigger", () => {
triggerPhrase: "@claude",
assigneeTrigger: "",
directPrompt: "",
allowedTools: "",
disallowedTools: "",
allowedTools: [],
disallowedTools: [],
customInstructions: "",
},
});