diff --git a/lib/config/validation.ts b/lib/config/validation.ts index a53e37b0cceac2992097992bb843c77fa5c38f7f..3739936f5c54ad00d2561a73ba7f25dcbc167753 100644 --- a/lib/config/validation.ts +++ b/lib/config/validation.ts @@ -10,32 +10,6 @@ const options = getOptions(); let optionTypes: Record<string, RenovateOptions['type']>; -// istanbul ignore next -async function validateBaseBranches( - config: RenovateConfig -): Promise<ValidationMessage[]> { - if (!is.nonEmptyArray(config.baseBranches)) { - return []; - } - const missingBranches: string[] = []; - for (const baseBranch of config.baseBranches) { - if (!(await platform.branchExists(baseBranch))) { - missingBranches.push(baseBranch); - } - } - if (missingBranches.length) { - return [ - { - depName: 'Missing baseBranches', - message: - 'One or more configured baseBranches are missing from this repo: ' + - missingBranches.join(', '), - }, - ]; - } - return []; -} - export interface ValidationResult { errors: ValidationMessage[]; warnings: ValidationMessage[]; @@ -55,8 +29,6 @@ export async function validateConfig( let errors: ValidationMessage[] = []; let warnings: ValidationMessage[] = []; - errors = errors.concat(await validateBaseBranches(config)); - function getDeprecationMessage(option: string): string { const deprecatedOptions = { branchName: `Direct editing of branchName is now deprecated. Please edit branchPrefix, managerBranchPrefix, or branchTopic instead`, diff --git a/lib/platform/git/storage.ts b/lib/platform/git/storage.ts index f4bfc524b292b2b16ec57a49c1d1fc006a565281..07b9cda6f04162653156c008f364e2cc0347432f 100644 --- a/lib/platform/git/storage.ts +++ b/lib/platform/git/storage.ts @@ -190,10 +190,7 @@ export class Storage { async setBaseBranch(branchName: string) { if (branchName) { if (!(await this.branchExists(branchName))) { - throw new Error( - 'Cannot set baseBranch to something that does not exist: ' + - branchName - ); + throwBaseBranchValidationError(branchName); } logger.debug(`Setting baseBranch to ${branchName}`); this._config.baseBranch = branchName; @@ -215,12 +212,7 @@ export class Storage { 'unknown revision or path not in the working tree' ) ) { - const error = new Error('config-validation'); - error.validationError = 'baseBranch not found'; - error.validationMessage = - 'The following configured baseBranch could not be found: ' + - branchName; - throw error; + throwBaseBranchValidationError(branchName); } throw err; } @@ -491,4 +483,12 @@ function checkForPlatformFailure(err: Error) { } } +function throwBaseBranchValidationError(branchName) { + const error = new Error('config-validation'); + error.validationError = 'baseBranch not found'; + error.validationMessage = + 'The following configured baseBranch could not be found: ' + branchName; + throw error; +} + export default Storage; diff --git a/test/platform/git/__snapshots__/storage.spec.ts.snap b/test/platform/git/__snapshots__/storage.spec.ts.snap index 1f6cdc925e36c40d48acfe5b286d8b0d165bb7e8..0e86ff4242ddaa10d449124d77a5781db1723893 100644 --- a/test/platform/git/__snapshots__/storage.spec.ts.snap +++ b/test/platform/git/__snapshots__/storage.spec.ts.snap @@ -44,4 +44,4 @@ Array [ exports[`platform/git/storage isBranchStale() should throw if branch does not exist 1`] = `[Error: Cannot check staleness for branch that does not exist: not_found]`; -exports[`platform/git/storage setBaseBranch(branchName) should throw if branch does not exist 1`] = `[Error: Cannot set baseBranch to something that does not exist: not_found]`; +exports[`platform/git/storage setBaseBranch(branchName) should throw if branch does not exist 1`] = `[Error: config-validation]`;