From 56454779dd509a5a0bc50547e76f80edb4bf31ca Mon Sep 17 00:00:00 2001 From: Copilot Date: Mon, 16 Feb 2026 18:58:54 +0000 Subject: [PATCH] Simplify serverHost extraction in push_repo_memory.cjs Extract serverHost from githubServerUrl once at the top of main() function instead of duplicating the extraction pattern 3 times throughout the code. Changes: - Add serverHost extraction after githubServerUrl initialization (line 63) - Remove duplicate extraction in checkout branch section (line 135-136) - Remove duplicate extraction in pull section (line 347-348) - Remove duplicate extraction in push section (line 359-360) Benefits: - Eliminates code duplication (DRY principle) - Single source of truth for server host extraction - Easier to maintain and modify - Clearer code structure All functionality preserved - no behavioral changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- actions/setup/js/push_repo_memory.cjs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/actions/setup/js/push_repo_memory.cjs b/actions/setup/js/push_repo_memory.cjs index f7e055dac4..30f40f9e5a 100644 --- a/actions/setup/js/push_repo_memory.cjs +++ b/actions/setup/js/push_repo_memory.cjs @@ -60,6 +60,7 @@ async function main() { const ghToken = process.env.GH_TOKEN; const githubRunId = process.env.GITHUB_RUN_ID || "unknown"; const githubServerUrl = process.env.GITHUB_SERVER_URL || "https://github.com"; + const serverHost = githubServerUrl.replace(/^https?:\/\//, ""); // Log environment variable configuration for debugging core.info("Environment configuration:"); @@ -132,8 +133,6 @@ async function main() { // Checkout or create the memory branch core.info(`Checking out branch: ${branchName}...`); try { - // Extract host from server URL (remove https:// prefix) - const serverHost = githubServerUrl.replace(/^https?:\/\//, ""); const repoUrl = `https://x-access-token:${ghToken}@${serverHost}/${targetRepo}.git`; // Try to fetch the branch @@ -345,8 +344,6 @@ async function main() { // Pull with merge strategy (ours wins on conflicts) core.info(`Pulling latest changes from ${branchName}...`); try { - // Extract host from server URL (remove https:// prefix) - const serverHost = githubServerUrl.replace(/^https?:\/\//, ""); const repoUrl = `https://x-access-token:${ghToken}@${serverHost}/${targetRepo}.git`; execGitSync(["pull", "--no-rebase", "-X", "ours", repoUrl, branchName], { stdio: "inherit" }); } catch (error) { @@ -357,8 +354,6 @@ async function main() { // Push changes core.info(`Pushing changes to ${branchName}...`); try { - // Extract host from server URL (remove https:// prefix) - const serverHost = githubServerUrl.replace(/^https?:\/\//, ""); const repoUrl = `https://x-access-token:${ghToken}@${serverHost}/${targetRepo}.git`; execGitSync(["push", repoUrl, `HEAD:${branchName}`], { stdio: "inherit" }); core.info(`Successfully pushed changes to ${branchName} branch`);