Skip to content

[code-simplifier] refactor: extract shared sanitizeForFilename helper in generate_git_patch.cjs - #19980

Merged
pelikhan merged 1 commit into
mainfrom
code-simplifier/2026-03-07-8821f9c9ec826462
Mar 7, 2026
Merged

[code-simplifier] refactor: extract shared sanitizeForFilename helper in generate_git_patch.cjs#19980
pelikhan merged 1 commit into
mainfrom
code-simplifier/2026-03-07-8821f9c9ec826462

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

Simplification of recently modified generate_git_patch.cjs (changed in #19963 which merged 2026-03-07).

Files Simplified

  • actions/setup/js/generate_git_patch.cjs — extracted duplicate sanitization logic and fixed string concatenation

Improvements Made

1. Eliminated Duplicate Sanitization Logic

sanitizeBranchNameForPatch and sanitizeRepoSlugForPatch shared an identical four-step .replace() chain, differing only in their fallback value for empty/null input. Extracted into a private sanitizeForFilename(value, fallback) helper:

// Before: two functions with identical replace chainsfunctionsanitizeBranchNameForPatch(branchName){if(!branchName)return"unknown";returnbranchName.replace(...).replace(...).replace(...).toLowerCase();}functionsanitizeRepoSlugForPatch(repoSlug){if(!repoSlug)return"";returnrepoSlug.replace(...).replace(...).replace(...).toLowerCase();}// After: single shared implementationfunctionsanitizeForFilename(value,fallback){if(!value)returnfallback;returnvalue.replace(...).replace(...).replace(...).toLowerCase();}functionsanitizeBranchNameForPatch(branchName){returnsanitizeForFilename(branchName,"unknown");}functionsanitizeRepoSlugForPatch(repoSlug){returnsanitizeForFilename(repoSlug,"");}

2. Fixed String Concatenation

Replaced a three-fragment string concatenation with a single template literal:

// BeforeerrorMessage=`Cannot generate incremental patch: failed to fetch origin/\$\{branchName}. `+`This typically happens when...`+`Error: \$\{getErrorMessage(fetchError)}`;// AftererrorMessage=`Cannot generate incremental patch: failed to fetch origin/\$\{branchName}. This typically happens when... Error: \$\{getErrorMessage(fetchError)}`;

Changes Based On

Recent changes from #19963 - fix: pass git auth via environment variables instead of writing to .git/config

Testing

  • ✅ Manual smoke test — all sanitizeBranchNameForPatch / sanitizeRepoSlugForPatch assertions pass
  • ✅ Linting passes (make lint-cjs)
  • ✅ Formatting passes (make fmt-cjs)
  • ✅ No functional changes — exported API and behavior are identical

Review Focus

Please verify:

  • Exported function signatures and behavior remain unchanged
  • sanitizeForFilename is not exported (it's a private implementation detail)
  • No unintended side effects

References:§22805044981

Generated by Code Simplifier ·

  • expires on Mar 8, 2026, 6:56 PM UTC

…ncatenation
- Extract duplicate sanitization logic from sanitizeBranchNameForPatch
and sanitizeRepoSlugForPatch into a shared private sanitizeForFilename
helper that accepts a fallback parameter
- Fix multi-part string concatenation on error message to use a single
template literal instead of three concatenated fragments
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@pelikhan