From 2e84c14327d8d98e8a05623867907be41d38c933 Mon Sep 17 00:00:00 2001 From: Koen van Zuijlen <8818390+kvanzuijlen@users.noreply.github.com> Date: Mon, 8 Jan 2024 17:45:16 +0100 Subject: [PATCH] refactor: Pass packageFile to bumpPackageVersion (#26538) Co-authored-by: Michael Kriese <michael.kriese@visualon.de> --- lib/modules/manager/types.ts | 1 + .../repository/update/branch/get-updated.ts | 41 ++++++++++++------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/lib/modules/manager/types.ts b/lib/modules/manager/types.ts index 8435b4e9b9..f3743f241a 100644 --- a/lib/modules/manager/types.ts +++ b/lib/modules/manager/types.ts @@ -235,6 +235,7 @@ export interface ManagerApi extends ModuleApi { content: string, currentValue: string, bumpVersion: ReleaseType, + packageFile: string, ): Result<BumpPackageVersionResult>; detectGlobalConfig?(): Result<GlobalManagerConfig>; diff --git a/lib/workers/repository/update/branch/get-updated.ts b/lib/workers/repository/update/branch/get-updated.ts index 648f107c25..1adfb25bd3 100644 --- a/lib/workers/repository/update/branch/get-updated.ts +++ b/lib/workers/repository/update/branch/get-updated.ts @@ -20,6 +20,21 @@ export interface PackageFilesResult { updatedArtifacts: FileChange[]; } +async function getFileContent( + updatedFileContents: Record<string, string>, + filePath: string, + config: BranchConfig, +): Promise<string | null> { + let fileContent: string | null = updatedFileContents[filePath]; + if (!fileContent) { + fileContent = await getFile( + filePath, + config.reuseExistingBranch ? config.branchName : config.baseBranch, + ); + } + return fileContent; +} + export async function getUpdatedPackageFiles( config: BranchConfig, ): Promise<PackageFilesResult> { @@ -46,23 +61,19 @@ export async function getUpdatedPackageFiles( packageFileUpdatedDeps[packageFile] = packageFileUpdatedDeps[packageFile] || []; packageFileUpdatedDeps[packageFile].push({ ...upgrade }); - let packageFileContent: string | null = updatedFileContents[packageFile]; - if (!packageFileContent) { - packageFileContent = await getFile( - packageFile, - reuseExistingBranch ? config.branchName : config.baseBranch, - ); - } + const packageFileContent = await getFileContent( + updatedFileContents, + packageFile, + config, + ); let lockFileContent: string | null = null; const lockFile = upgrade.lockFile ?? upgrade.lockFiles?.[0] ?? ''; if (lockFile) { - lockFileContent = updatedFileContents[lockFile]; - if (!lockFileContent) { - lockFileContent = await getFile( - lockFile, - reuseExistingBranch ? config.branchName : config.baseBranch, - ); - } + lockFileContent = await getFileContent( + updatedFileContents, + lockFile, + config, + ); } // istanbul ignore if if ( @@ -183,6 +194,7 @@ export async function getUpdatedPackageFiles( res, upgrade.packageFileVersion, upgrade.bumpVersion, + packageFile, ); res = bumpedContent; } @@ -217,6 +229,7 @@ export async function getUpdatedPackageFiles( newContent, upgrade.packageFileVersion, upgrade.bumpVersion, + packageFile, ); newContent = bumpedContent; } -- GitLab