Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/github/operations/git-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,21 @@ export async function configureGitAuth(
console.log("No existing authentication headers to remove");
}

// Update the remote URL to include the token for authentication
// Inject auth token into the existing remote URL, preserving the original
// repo (which may differ from context.repository if a different repo was checked out)
console.log("Updating remote URL with authentication...");
const remoteUrl = `https://x-access-token:${githubToken}@${serverUrl.host}/${context.repository.owner}/${context.repository.repo}.git`;
let remoteUrl: string;
try {
const currentUrl = (await $`git remote get-url origin`.text()).trim();
const parsed = new URL(
currentUrl.endsWith(".git") ? currentUrl : currentUrl + ".git",
);
parsed.username = "x-access-token";
parsed.password = githubToken;
remoteUrl = parsed.toString();
} catch {
remoteUrl = `https://x-access-token:${githubToken}@${serverUrl.host}/${context.repository.owner}/${context.repository.repo}.git`;
}
await $`git remote set-url origin ${remoteUrl}`;
console.log("✓ Updated remote URL with authentication token");

Expand Down