mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-08-22 11:28:55 +08:00
Run checkout auth cleanup when API commit signing is enabled (#1597)
* Run checkout auth cleanup when API commit signing is enabled * Derive git-config test expectations from GITHUB_SERVER_URL No-Verification-Needed: test-only change
This commit is contained in:
@@ -42,6 +42,27 @@ export async function configureGitAuth(
|
||||
await $`git config user.email "${botId}+${botName}@${noreplyDomain}"`;
|
||||
console.log(`✓ Set git user as ${botName}`);
|
||||
|
||||
await replaceCheckoutCredentials(githubToken, context);
|
||||
|
||||
console.log("Git authentication configured successfully");
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the credential that actions/checkout persisted in the working tree.
|
||||
*
|
||||
* actions/checkout stores its token as an `http.<server>/.extraheader` entry
|
||||
* in .git/config for the duration of the job. Claude and the tools it invokes
|
||||
* run inside this working tree, so remove that entry and back git with the
|
||||
* action's own token instead (a credential helper when non-write users are
|
||||
* allowed, otherwise the origin URL). This applies to every mode, including API
|
||||
* commit signing where no other git configuration is needed.
|
||||
*/
|
||||
export async function replaceCheckoutCredentials(
|
||||
githubToken: string,
|
||||
context: GitHubContext,
|
||||
) {
|
||||
const serverUrl = new URL(GITHUB_SERVER_URL);
|
||||
|
||||
// Remove the authorization header that actions/checkout sets
|
||||
console.log("Removing existing git authentication headers...");
|
||||
try {
|
||||
@@ -79,8 +100,6 @@ export async function configureGitAuth(
|
||||
await $`git remote set-url origin ${remoteUrl}`;
|
||||
console.log("✓ Updated remote URL with authentication token");
|
||||
}
|
||||
|
||||
console.log("Git authentication configured successfully");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,6 +3,7 @@ import { prepareMcpConfig } from "../../mcp/install-mcp-server";
|
||||
import { parseAllowedTools } from "./parse-tools";
|
||||
import {
|
||||
configureGitAuth,
|
||||
replaceCheckoutCredentials,
|
||||
setupSshSigning,
|
||||
} from "../../github/operations/git-config";
|
||||
import { checkHumanActor } from "../../github/validation/actor";
|
||||
@@ -62,6 +63,16 @@ export async function prepareAgentMode({
|
||||
console.error("Failed to configure git authentication:", error);
|
||||
// Continue anyway - git operations may still work with default config
|
||||
}
|
||||
} else {
|
||||
// Commits go through the GitHub API, so no git user setup is needed, but
|
||||
// the credential actions/checkout left in git config should still be
|
||||
// replaced with the action's own.
|
||||
try {
|
||||
await replaceCheckoutCredentials(githubToken, context);
|
||||
} catch (error) {
|
||||
console.error("Failed to configure git credentials:", error);
|
||||
// Continue anyway - git operations may still work with default config
|
||||
}
|
||||
}
|
||||
|
||||
// Create prompt directory. Clear any stale files from a prior invocation first —
|
||||
|
||||
@@ -3,6 +3,7 @@ import { createInitialComment } from "../../github/operations/comments/create-in
|
||||
import { setupBranch } from "../../github/operations/branch";
|
||||
import {
|
||||
configureGitAuth,
|
||||
replaceCheckoutCredentials,
|
||||
setupSshSigning,
|
||||
} from "../../github/operations/git-config";
|
||||
import { prepareMcpConfig } from "../../mcp/install-mcp-server";
|
||||
@@ -98,6 +99,16 @@ export async function prepareTagMode({
|
||||
console.error("Failed to configure git authentication:", error);
|
||||
throw error;
|
||||
}
|
||||
} else {
|
||||
// Commits go through the GitHub API, so no git user setup is needed, but
|
||||
// the credential actions/checkout left in git config should still be
|
||||
// replaced with the action's own.
|
||||
try {
|
||||
await replaceCheckoutCredentials(githubToken, context);
|
||||
} catch (error) {
|
||||
console.error("Failed to configure git credentials:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// Create prompt file
|
||||
|
||||
Reference in New Issue
Block a user