From f14e2a27170f380352fd9dd9f20619d08f8ee0af Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 27 Jul 2026 05:07:15 +0000 Subject: [PATCH] jsweep: remove duplicated normalizeBranchName from upload_assets.cjs Import normalizeBranchName from normalize_branch_name.cjs instead of maintaining a copy. The two implementations were identical (upload_assets lacked the optional salt parameter which defaults to null and has no effect when omitted). Also remove the stale sync-reminder comment from normalize_branch_name.cjs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- actions/setup/js/normalize_branch_name.cjs | 2 - actions/setup/js/upload_assets.cjs | 45 +--------------------- 2 files changed, 1 insertion(+), 46 deletions(-) diff --git a/actions/setup/js/normalize_branch_name.cjs b/actions/setup/js/normalize_branch_name.cjs index 96aa5b16720..6d20e27dbcb 100644 --- a/actions/setup/js/normalize_branch_name.cjs +++ b/actions/setup/js/normalize_branch_name.cjs @@ -4,8 +4,6 @@ /** * Normalizes a branch name to be a valid git branch name. * - * IMPORTANT: Keep this function in sync with the normalizeBranchName function in upload_assets.cjs - * * Valid characters: alphanumeric (a-z, A-Z, 0-9), dash (-), underscore (_), forward slash (/), dot (.) * Max length: 128 characters (before salt is appended) * diff --git a/actions/setup/js/upload_assets.cjs b/actions/setup/js/upload_assets.cjs index e0a8217bd21..2e4ce07edcc 100644 --- a/actions/setup/js/upload_assets.cjs +++ b/actions/setup/js/upload_assets.cjs @@ -7,55 +7,12 @@ const crypto = require("crypto"); const { loadAgentOutput } = require("./load_agent_output.cjs"); const { getErrorMessage } = require("./error_helpers.cjs"); const { ERR_API, ERR_CONFIG, ERR_SYSTEM, ERR_VALIDATION } = require("./error_codes.cjs"); +const { normalizeBranchName } = require("./normalize_branch_name.cjs"); /** * @typedef {{ type: string, fileName: string, sha: string, size: number, targetFileName: string, url?: string }} UploadAssetItem */ -/** - * Normalizes a branch name to be a valid git branch name. - * - * IMPORTANT: Keep this function in sync with the normalizeBranchName function in normalize_branch_name.cjs - * - * Valid characters: alphanumeric (a-z, A-Z, 0-9), dash (-), underscore (_), forward slash (/), dot (.) - * Max length: 128 characters - * - * The normalization process: - * 1. Replaces invalid characters with a single dash - * 2. Collapses multiple consecutive dashes to a single dash - * 3. Removes leading and trailing dashes - * 4. Truncates to 128 characters - * 5. Removes trailing dashes after truncation - * - * @param {string} branchName - The branch name to normalize - * @returns {string} The normalized branch name - */ -function normalizeBranchName(branchName) { - if (!branchName || typeof branchName !== "string" || branchName.trim() === "") { - return branchName; - } - - // Replace any sequence of invalid characters with a single dash - // Valid characters are: a-z, A-Z, 0-9, -, _, /, . - let normalized = branchName.replace(/[^a-zA-Z0-9\-_/.]+/g, "-"); - - // Collapse multiple consecutive dashes to a single dash - normalized = normalized.replace(/-+/g, "-"); - - // Remove leading and trailing dashes - normalized = normalized.replace(/^-+|-+$/g, ""); - - // Truncate to max 128 characters - if (normalized.length > 128) { - normalized = normalized.substring(0, 128); - } - - // Ensure it doesn't end with a dash after truncation - normalized = normalized.replace(/-+$/, ""); - - return normalized; -} - async function main() { // Check if we're in staged mode const isStaged = process.env.GH_AW_SAFE_OUTPUTS_STAGED === "true";