feat: add optional claude name and email for git

This commit is contained in:
Mark Wylde
2025-05-31 10:55:35 +01:00
parent 96524bd1d8
commit 87eac76ba0
6 changed files with 61 additions and 28 deletions

View File

@@ -65,3 +65,10 @@ When adding new MCP tools:
2. **Expose to Claude**: Add the tool name to `BASE_ALLOWED_TOOLS` array in `src/create-prompt/index.ts` 2. **Expose to Claude**: Add the tool name to `BASE_ALLOWED_TOOLS` array in `src/create-prompt/index.ts`
3. **Tool Naming**: Follow the pattern `mcp__server_name__tool_name` (e.g., `mcp__local_git_ops__checkout_branch`) 3. **Tool Naming**: Follow the pattern `mcp__server_name__tool_name` (e.g., `mcp__local_git_ops__checkout_branch`)
4. **Documentation**: Update the prompt's "What You CAN Do" section if the tool adds new capabilities 4. **Documentation**: Update the prompt's "What You CAN Do" section if the tool adds new capabilities
## Feature Development Reminders
When implementing new features that add action inputs, configuration options, or capabilities:
1. Always update README.md to document new inputs in the inputs table
2. Update example workflows to show how new inputs can be used
3. Add appropriate defaults and descriptions to action.yml

View File

@@ -64,26 +64,30 @@ jobs:
with: with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
gitea_token: ${{ secrets.GITEA_TOKEN }} gitea_token: ${{ secrets.GITEA_TOKEN }}
claude_git_name: Claude # optional
claude_git_email: claude@anthropic.com # optional
``` ```
## Inputs ## Inputs
| Input | Description | Required | Default | | Input | Description | Required | Default |
| --------------------- | ------------------------------------------------------------------------------------------------------------------- | -------- | --------- | | --------------------- | ---------------------------------------------------------------------------------------------------------------------------- | -------- | --------- |
| `anthropic_api_key` | Anthropic API key (required for direct API, not needed for Bedrock/Vertex). Set to 'use-oauth' when using claude_credentials | No\* | - | | `anthropic_api_key` | Anthropic API key (required for direct API, not needed for Bedrock/Vertex). Set to 'use-oauth' when using claude_credentials | No\* | - |
| `claude_credentials` | Claude OAuth credentials JSON for Claude AI Max subscription authentication | No | - | | `claude_credentials` | Claude OAuth credentials JSON for Claude AI Max subscription authentication | No | - |
| `direct_prompt` | Direct prompt for Claude to execute automatically without needing a trigger (for automated workflows) | No | - | | `direct_prompt` | Direct prompt for Claude to execute automatically without needing a trigger (for automated workflows) | No | - |
| `timeout_minutes` | Timeout in minutes for execution | No | `30` | | `timeout_minutes` | Timeout in minutes for execution | No | `30` |
| `gitea_token` | Gitea token for Claude to operate with. **Only include this if you're connecting a custom GitHub app of your own!** | No | - | | `gitea_token` | Gitea 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 | - | | `model` | Model to use (provider-specific format required for Bedrock/Vertex) | No | - |
| `anthropic_model` | **DEPRECATED**: Use `model` instead. Kept for backward compatibility. | No | - | | `anthropic_model` | **DEPRECATED**: Use `model` instead. Kept for backward compatibility. | No | - |
| `use_bedrock` | Use Amazon Bedrock with OIDC authentication instead of direct Anthropic API | No | `false` | | `use_bedrock` | Use Amazon Bedrock with OIDC authentication instead of direct Anthropic API | No | `false` |
| `use_vertex` | Use Google Vertex AI with OIDC authentication instead of direct Anthropic API | No | `false` | | `use_vertex` | Use Google Vertex AI with OIDC authentication instead of direct Anthropic API | No | `false` |
| `allowed_tools` | Additional tools for Claude to use (the base GitHub tools will always be included) | No | "" | | `allowed_tools` | Additional tools for Claude to use (the base GitHub tools will always be included) | No | "" |
| `disallowed_tools` | Tools that Claude should never use | No | "" | | `disallowed_tools` | Tools that Claude should never use | No | "" |
| `custom_instructions` | Additional custom instructions to include in the prompt for Claude | No | "" | | `custom_instructions` | Additional custom instructions to include in the prompt for Claude | No | "" |
| `assignee_trigger` | The assignee username that triggers the action (e.g. @claude). Only used for issue assignment | No | - | | `assignee_trigger` | The assignee username that triggers the action (e.g. @claude). Only used for issue assignment | No | - |
| `trigger_phrase` | The trigger phrase to look for in comments, issue/PR bodies, and issue titles | No | `@claude` | | `trigger_phrase` | The trigger phrase to look for in comments, issue/PR bodies, and issue titles | No | `@claude` |
| `claude_git_name` | Git user.name for commits made by Claude | No | `Claude` |
| `claude_git_email` | Git user.email for commits made by Claude | No | `claude@anthropic.com` |
\*Required when using direct Anthropic API (default and when not using Bedrock or Vertex) \*Required when using direct Anthropic API (default and when not using Bedrock or Vertex)
@@ -96,6 +100,7 @@ This action supports authentication using Claude Max OAuth credentials. This all
### Setup ### Setup
1. **Get OAuth Credentials**: Use Claude Code to generate OAuth credentials: 1. **Get OAuth Credentials**: Use Claude Code to generate OAuth credentials:
``` ```
/auth-setup /auth-setup
``` ```
@@ -107,7 +112,7 @@ This action supports authentication using Claude Max OAuth credentials. This all
```yaml ```yaml
- uses: anthropics/claude-code-action@beta - uses: anthropics/claude-code-action@beta
with: with:
anthropic_api_key: 'use-oauth' anthropic_api_key: "use-oauth"
claude_credentials: ${{ secrets.CLAUDE_CREDENTIALS }} claude_credentials: ${{ secrets.CLAUDE_CREDENTIALS }}
gitea_token: ${{ secrets.GITHUB_TOKEN }} gitea_token: ${{ secrets.GITHUB_TOKEN }}
``` ```

View File

@@ -63,6 +63,14 @@ inputs:
description: "Timeout in minutes for execution" description: "Timeout in minutes for execution"
required: false required: false
default: "30" default: "30"
claude_git_name:
description: "Git user.name for commits made by Claude"
required: false
default: "Claude"
claude_git_email:
description: "Git user.email for commits made by Claude"
required: false
default: "claude@anthropic.com"
outputs: outputs:
execution_file: execution_file:
@@ -134,6 +142,10 @@ runs:
GITHUB_TOKEN: ${{ steps.prepare.outputs.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ steps.prepare.outputs.GITHUB_TOKEN }}
GITEA_API_URL: ${{ env.GITHUB_SERVER_URL }} GITEA_API_URL: ${{ env.GITHUB_SERVER_URL }}
# Git configuration
CLAUDE_GIT_NAME: ${{ inputs.claude_git_name }}
CLAUDE_GIT_EMAIL: ${{ inputs.claude_git_email }}
# Provider configuration (for future cloud provider support) # Provider configuration (for future cloud provider support)
ANTHROPIC_BASE_URL: ${{ env.ANTHROPIC_BASE_URL }} ANTHROPIC_BASE_URL: ${{ env.ANTHROPIC_BASE_URL }}
AWS_REGION: ${{ env.AWS_REGION }} AWS_REGION: ${{ env.AWS_REGION }}

View File

@@ -20,16 +20,20 @@ interface ClaudeCredentialsInput {
export async function setupOAuthCredentials(credentialsJson: string) { export async function setupOAuthCredentials(credentialsJson: string) {
try { try {
// Parse the credentials JSON // Parse the credentials JSON
const parsedCredentials: ClaudeCredentialsInput = JSON.parse(credentialsJson); const parsedCredentials: ClaudeCredentialsInput =
JSON.parse(credentialsJson);
if (!parsedCredentials.claudeAiOauth) { if (!parsedCredentials.claudeAiOauth) {
throw new Error("Invalid credentials format: missing claudeAiOauth"); throw new Error("Invalid credentials format: missing claudeAiOauth");
} }
const { accessToken, refreshToken, expiresAt } = parsedCredentials.claudeAiOauth; const { accessToken, refreshToken, expiresAt } =
parsedCredentials.claudeAiOauth;
if (!accessToken || !refreshToken || !expiresAt) { if (!accessToken || !refreshToken || !expiresAt) {
throw new Error("Invalid credentials format: missing required OAuth fields"); throw new Error(
"Invalid credentials format: missing required OAuth fields",
);
} }
const claudeDir = join(homedir(), ".claude"); const claudeDir = join(homedir(), ".claude");
@@ -56,4 +60,4 @@ export async function setupOAuthCredentials(credentialsJson: string) {
const errorMessage = error instanceof Error ? error.message : String(error); const errorMessage = error instanceof Error ? error.message : String(error);
throw new Error(`Failed to setup OAuth credentials: ${errorMessage}`); throw new Error(`Failed to setup OAuth credentials: ${errorMessage}`);
} }
} }

View File

@@ -25,10 +25,12 @@ async function run() {
// Step 1: Setup OAuth credentials if provided // Step 1: Setup OAuth credentials if provided
const claudeCredentials = process.env.CLAUDE_CREDENTIALS; const claudeCredentials = process.env.CLAUDE_CREDENTIALS;
const anthropicApiKey = process.env.ANTHROPIC_API_KEY; const anthropicApiKey = process.env.ANTHROPIC_API_KEY;
if (claudeCredentials && anthropicApiKey === "use-oauth") { if (claudeCredentials && anthropicApiKey === "use-oauth") {
await setupOAuthCredentials(claudeCredentials); await setupOAuthCredentials(claudeCredentials);
console.log("OAuth credentials configured for Claude AI Max subscription"); console.log(
"OAuth credentials configured for Claude AI Max subscription",
);
} }
// Step 2: Setup GitHub token // Step 2: Setup GitHub token

View File

@@ -60,15 +60,18 @@ function runGitCommand(command: string): string {
// Helper function to ensure git user is configured // Helper function to ensure git user is configured
function ensureGitUserConfigured(): void { function ensureGitUserConfigured(): void {
const gitName = process.env.CLAUDE_GIT_NAME || "Claude";
const gitEmail = process.env.CLAUDE_GIT_EMAIL || "claude@anthropic.com";
try { try {
// Check if user.email is already configured // Check if user.email is already configured
runGitCommand("git config user.email"); runGitCommand("git config user.email");
console.log(`[LOCAL-GIT-MCP] Git user.email already configured`); console.log(`[LOCAL-GIT-MCP] Git user.email already configured`);
} catch (error) { } catch (error) {
console.log( console.log(
`[LOCAL-GIT-MCP] Git user.email not configured, setting default`, `[LOCAL-GIT-MCP] Git user.email not configured, setting to: ${gitEmail}`,
); );
runGitCommand('git config user.email "claude@anthropic.com"'); runGitCommand(`git config user.email "${gitEmail}"`);
} }
try { try {
@@ -77,9 +80,9 @@ function ensureGitUserConfigured(): void {
console.log(`[LOCAL-GIT-MCP] Git user.name already configured`); console.log(`[LOCAL-GIT-MCP] Git user.name already configured`);
} catch (error) { } catch (error) {
console.log( console.log(
`[LOCAL-GIT-MCP] Git user.name not configured, setting default`, `[LOCAL-GIT-MCP] Git user.name not configured, setting to: ${gitName}`,
); );
runGitCommand('git config user.name "Claude"'); runGitCommand(`git config user.name "${gitName}"`);
} }
} }