Skip to content

Commit

Permalink
refactor: applyUpdateConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Feb 22, 2021
1 parent a456c8b commit 2be25c4
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions lib/workers/repository/updates/flatten.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,38 @@ import { LANGUAGE_DOCKER } from '../../../constants/languages';
import { getDefaultConfig } from '../../../datasource';
import { get } from '../../../manager';
import { applyPackageRules } from '../../../util/package-rules';
import { BranchUpgradeConfig } from '../../common';
import { generateBranchName } from './branch-name';

const upper = (str: string): string =>
str.charAt(0).toUpperCase() + str.substr(1);

export function applyUpdateConfig(input: BranchUpgradeConfig): any {
const updateConfig = { ...input };
delete updateConfig.packageRules;
// TODO: Remove next line once #8075 is complete
updateConfig.depNameShort ||= updateConfig.depName;
updateConfig.depNameSanitized = updateConfig.depName
? updateConfig.depName
.replace('@types/', '')
.replace('@', '')
.replace(/\//g, '-')
.replace(/\s+/g, '-')
.replace(/-+/, '-')
.toLowerCase()
: undefined;
if (
updateConfig.language === LANGUAGE_DOCKER &&
/(^|\/)node$/.exec(updateConfig.depName) &&
updateConfig.depName !== 'calico/node'
) {
updateConfig.additionalBranchPrefix = '';
updateConfig.depNameSanitized = 'node';
}
generateBranchName(updateConfig);
return updateConfig;
}

export async function flattenUpdates(
config: RenovateConfig,
packageFiles: Record<string, any[]>
Expand Down Expand Up @@ -75,30 +102,7 @@ export async function flattenUpdates(
}
// Apply again in case any were added by the updateType config
updateConfig = applyPackageRules(updateConfig);
delete updateConfig.packageRules;
// TODO: Remove next line once #8075 is complete
updateConfig.depNameShort ||= updateConfig.depName;
updateConfig.depNameSanitized = updateConfig.depName
? updateConfig.depName
.replace('@types/', '')
.replace('@', '')
.replace(/\//g, '-')
.replace(/\s+/g, '-')
.replace(/-+/, '-')
.toLowerCase()
: undefined;
if (
updateConfig.language === LANGUAGE_DOCKER &&
updateConfig.depName.match(/(^|\/)node$/) &&
updateConfig.depName !== 'calico/node'
) {
updateConfig.additionalBranchPrefix = '';
updateConfig.depNameSanitized = 'node';
}
generateBranchName(updateConfig);
update.branchName = updateConfig.branchName; // for writing to cache
delete updateConfig.repoIsOnboarded;
delete updateConfig.renovateJsonPresent;
updateConfig = applyUpdateConfig(updateConfig);
updateConfig.baseDeps = packageFile.deps;
updates.push(updateConfig);
}
Expand Down

0 comments on commit 2be25c4

Please sign in to comment.