fix: use GITHUB_SERVER_URL to determine email domain for GitHub Enterprise (#290)

* fix: use GITHUB_SERVER_URL to determine email domain for GitHub Enterprise

- Extract hostname from GITHUB_SERVER_URL environment variable
- Use users.noreply.github.com for GitHub.com
- Use users.noreply.{hostname} for GitHub Enterprise instances

Fixes #288

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

* lint

---------

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Ashwin Bhat <ashwin-ant@users.noreply.github.com>
This commit is contained in:
Ashwin Bhat
2025-07-17 08:11:48 -07:00
committed by GitHub
parent 8fcb8e16b8
commit d4d7974604

View File

@@ -21,6 +21,13 @@ export async function configureGitAuth(
) { ) {
console.log("Configuring git authentication for non-signing mode"); console.log("Configuring git authentication for non-signing mode");
// Determine the noreply email domain based on GITHUB_SERVER_URL
const serverUrl = new URL(GITHUB_SERVER_URL);
const noreplyDomain =
serverUrl.hostname === "github.com"
? "users.noreply.github.com"
: `users.noreply.${serverUrl.hostname}`;
// Configure git user based on the comment creator // Configure git user based on the comment creator
console.log("Configuring git user..."); console.log("Configuring git user...");
if (user) { if (user) {
@@ -28,12 +35,12 @@ export async function configureGitAuth(
const botId = user.id; const botId = user.id;
console.log(`Setting git user as ${botName}...`); console.log(`Setting git user as ${botName}...`);
await $`git config user.name "${botName}"`; await $`git config user.name "${botName}"`;
await $`git config user.email "${botId}+${botName}@users.noreply.github.com"`; await $`git config user.email "${botId}+${botName}@${noreplyDomain}"`;
console.log(`✓ Set git user as ${botName}`); console.log(`✓ Set git user as ${botName}`);
} else { } else {
console.log("No user data in comment, using default bot user"); console.log("No user data in comment, using default bot user");
await $`git config user.name "github-actions[bot]"`; await $`git config user.name "github-actions[bot]"`;
await $`git config user.email "41898282+github-actions[bot]@users.noreply.github.com"`; await $`git config user.email "41898282+github-actions[bot]@${noreplyDomain}"`;
} }
// Remove the authorization header that actions/checkout sets // Remove the authorization header that actions/checkout sets
@@ -47,7 +54,6 @@ export async function configureGitAuth(
// Update the remote URL to include the token for authentication // Update the remote URL to include the token for authentication
console.log("Updating remote URL with authentication..."); console.log("Updating remote URL with authentication...");
const serverUrl = new URL(GITHUB_SERVER_URL);
const remoteUrl = `https://x-access-token:${githubToken}@${serverUrl.host}/${context.repository.owner}/${context.repository.repo}.git`; const remoteUrl = `https://x-access-token:${githubToken}@${serverUrl.host}/${context.repository.owner}/${context.repository.repo}.git`;
await $`git remote set-url origin ${remoteUrl}`; await $`git remote set-url origin ${remoteUrl}`;
console.log("✓ Updated remote URL with authentication token"); console.log("✓ Updated remote URL with authentication token");