From d4d7974604c97ec79208ca115b863b41a325d62d Mon Sep 17 00:00:00 2001 From: Ashwin Bhat Date: Thu, 17 Jul 2025 08:11:48 -0700 Subject: [PATCH] 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 * lint --------- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: Ashwin Bhat --- src/github/operations/git-config.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/github/operations/git-config.ts b/src/github/operations/git-config.ts index bc9969f..51a1c99 100644 --- a/src/github/operations/git-config.ts +++ b/src/github/operations/git-config.ts @@ -21,6 +21,13 @@ export async function configureGitAuth( ) { 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 console.log("Configuring git user..."); if (user) { @@ -28,12 +35,12 @@ export async function configureGitAuth( const botId = user.id; console.log(`Setting git user as ${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}`); } else { console.log("No user data in comment, using default bot user"); 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 @@ -47,7 +54,6 @@ export async function configureGitAuth( // Update the remote URL to include the token for 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`; await $`git remote set-url origin ${remoteUrl}`; console.log("✓ Updated remote URL with authentication token");