feat: add optional claude name and email for git
This commit is contained in:
@@ -20,16 +20,20 @@ interface ClaudeCredentialsInput {
|
||||
export async function setupOAuthCredentials(credentialsJson: string) {
|
||||
try {
|
||||
// Parse the credentials JSON
|
||||
const parsedCredentials: ClaudeCredentialsInput = JSON.parse(credentialsJson);
|
||||
|
||||
const parsedCredentials: ClaudeCredentialsInput =
|
||||
JSON.parse(credentialsJson);
|
||||
|
||||
if (!parsedCredentials.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) {
|
||||
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");
|
||||
@@ -56,4 +60,4 @@ export async function setupOAuthCredentials(credentialsJson: string) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
throw new Error(`Failed to setup OAuth credentials: ${errorMessage}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,12 @@ async function run() {
|
||||
// Step 1: Setup OAuth credentials if provided
|
||||
const claudeCredentials = process.env.CLAUDE_CREDENTIALS;
|
||||
const anthropicApiKey = process.env.ANTHROPIC_API_KEY;
|
||||
|
||||
|
||||
if (claudeCredentials && anthropicApiKey === "use-oauth") {
|
||||
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
|
||||
|
||||
@@ -60,15 +60,18 @@ function runGitCommand(command: string): string {
|
||||
|
||||
// Helper function to ensure git user is configured
|
||||
function ensureGitUserConfigured(): void {
|
||||
const gitName = process.env.CLAUDE_GIT_NAME || "Claude";
|
||||
const gitEmail = process.env.CLAUDE_GIT_EMAIL || "claude@anthropic.com";
|
||||
|
||||
try {
|
||||
// Check if user.email is already configured
|
||||
runGitCommand("git config user.email");
|
||||
console.log(`[LOCAL-GIT-MCP] Git user.email already configured`);
|
||||
} catch (error) {
|
||||
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 {
|
||||
@@ -77,9 +80,9 @@ function ensureGitUserConfigured(): void {
|
||||
console.log(`[LOCAL-GIT-MCP] Git user.name already configured`);
|
||||
} catch (error) {
|
||||
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}"`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user