Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions actions/setup/js/generate_git_patch.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,30 @@ function debugLog(message) {
}

/**
* Sanitize a branch name for use as a patch filename
* Replaces path separators and special characters with dashes
* @param {string} branchName - The branch name to sanitize
* @returns {string} The sanitized branch name safe for use in a filename
* Sanitize a string for use as a patch filename component.
* Replaces path separators and special characters with dashes.
* @param {string} value - The value to sanitize
* @param {string} fallback - Fallback value when input is empty or nullish
* @returns {string} The sanitized string safe for use in a filename
*/
function sanitizeBranchNameForPatch(branchName) {
if (!branchName) return "unknown";
return branchName
function sanitizeForFilename(value, fallback) {
if (!value) return fallback;
return value
.replace(/[/\\:*?"<>|]/g, "-")
.replace(/-{2,}/g, "-")
.replace(/^-|-$/g, "")
.toLowerCase();
}

/**
* Sanitize a branch name for use as a patch filename
* @param {string} branchName - The branch name to sanitize
* @returns {string} The sanitized branch name safe for use in a filename
*/
function sanitizeBranchNameForPatch(branchName) {
return sanitizeForFilename(branchName, "unknown");
}

/**
* Get the patch file path for a given branch name
* @param {string} branchName - The branch name
Expand All @@ -50,12 +60,7 @@ function getPatchPath(branchName) {
* @returns {string} The sanitized slug safe for use in a filename
*/
function sanitizeRepoSlugForPatch(repoSlug) {
if (!repoSlug) return "";
return repoSlug
.replace(/[/\\:*?"<>|]/g, "-")
.replace(/-{2,}/g, "-")
.replace(/^-|-$/g, "")
.toLowerCase();
return sanitizeForFilename(repoSlug, "");
}

/**
Expand Down Expand Up @@ -167,7 +172,7 @@ async function generateGitPatch(branchName, baseBranch, options = {}) {
} catch (fetchError) {
// In incremental mode, we MUST have origin/branchName - no fallback
debugLog(`Strategy 1 (incremental): Fetch failed - ${getErrorMessage(fetchError)}`);
errorMessage = `Cannot generate incremental patch: failed to fetch origin/${branchName}. ` + `This typically happens when the remote branch doesn't exist yet or was force-pushed. ` + `Error: ${getErrorMessage(fetchError)}`;
errorMessage = `Cannot generate incremental patch: failed to fetch origin/${branchName}. This typically happens when the remote branch doesn't exist yet or was force-pushed. Error: ${getErrorMessage(fetchError)}`;
// Don't try other strategies in incremental mode
return {
success: false,
Expand Down