Skip to content
Snippets Groups Projects
Commit 4f97dd43 authored by Rhys Arkins's avatar Rhys Arkins
Browse files

refactor: get-updated packageFileContent

parent ecceadd2
No related merge requests found
...@@ -34,33 +34,33 @@ export async function getUpdatedPackageFiles( ...@@ -34,33 +34,33 @@ export async function getUpdatedPackageFiles(
packageFileUpdatedDeps[packageFile] = packageFileUpdatedDeps[packageFile] =
packageFileUpdatedDeps[packageFile] || []; packageFileUpdatedDeps[packageFile] || [];
packageFileUpdatedDeps[packageFile].push(depName); packageFileUpdatedDeps[packageFile].push(depName);
let packageFileContent = updatedFileContents[packageFile];
if (!packageFileContent) {
packageFileContent = await getFile(
packageFile,
reuseExistingBranch ? config.branchName : config.baseBranch
);
}
// istanbul ignore if
if (config.reuseExistingBranch && !packageFileContent) {
logger.debug(
{ packageFile, depName },
'Rebasing branch after file not found'
);
return getUpdatedPackageFiles({
...config,
reuseExistingBranch: false,
});
}
if (upgrade.updateType === 'lockFileMaintenance') { if (upgrade.updateType === 'lockFileMaintenance') {
lockFileMaintenanceFiles.push(packageFile); lockFileMaintenanceFiles.push(packageFile);
} else { } else {
let existingContent = updatedFileContents[packageFile];
if (!existingContent) {
existingContent = await getFile(
packageFile,
reuseExistingBranch ? config.branchName : config.baseBranch
);
}
// istanbul ignore if
if (config.reuseExistingBranch && !existingContent) {
logger.debug(
{ packageFile, depName },
'Rebasing branch after file not found'
);
return getUpdatedPackageFiles({
...config,
reuseExistingBranch: false,
});
}
const bumpPackageVersion = get(manager, 'bumpPackageVersion'); const bumpPackageVersion = get(manager, 'bumpPackageVersion');
const updateDependency = get(manager, 'updateDependency'); const updateDependency = get(manager, 'updateDependency');
if (!updateDependency) { if (!updateDependency) {
let res = await doAutoReplace( let res = await doAutoReplace(
upgrade, upgrade,
existingContent, packageFileContent,
reuseExistingBranch reuseExistingBranch
); );
if (res) { if (res) {
...@@ -72,7 +72,7 @@ export async function getUpdatedPackageFiles( ...@@ -72,7 +72,7 @@ export async function getUpdatedPackageFiles(
); );
res = bumpedContent; res = bumpedContent;
} }
if (res === existingContent) { if (res === packageFileContent) {
logger.debug({ packageFile, depName }, 'No content changed'); logger.debug({ packageFile, depName }, 'No content changed');
if (upgrade.rangeStrategy === 'update-lockfile') { if (upgrade.rangeStrategy === 'update-lockfile') {
logger.debug({ packageFile, depName }, 'update-lockfile add'); logger.debug({ packageFile, depName }, 'update-lockfile add');
...@@ -93,7 +93,7 @@ export async function getUpdatedPackageFiles( ...@@ -93,7 +93,7 @@ export async function getUpdatedPackageFiles(
throw new Error(WORKER_FILE_UPDATE_FAILED); throw new Error(WORKER_FILE_UPDATE_FAILED);
} }
let newContent = await updateDependency({ let newContent = await updateDependency({
fileContent: existingContent, fileContent: packageFileContent,
upgrade, upgrade,
}); });
if (bumpPackageVersion && upgrade.bumpVersion) { if (bumpPackageVersion && upgrade.bumpVersion) {
...@@ -116,12 +116,12 @@ export async function getUpdatedPackageFiles( ...@@ -116,12 +116,12 @@ export async function getUpdatedPackageFiles(
}); });
} }
logger.debug( logger.debug(
{ existingContent, config: upgrade }, { existingContent: packageFileContent, config: upgrade },
'Error updating file' 'Error updating file'
); );
throw new Error(WORKER_FILE_UPDATE_FAILED); throw new Error(WORKER_FILE_UPDATE_FAILED);
} }
if (newContent !== existingContent) { if (newContent !== packageFileContent) {
if (config.reuseExistingBranch) { if (config.reuseExistingBranch) {
// This ensure it's always 1 commit from the bot // This ensure it's always 1 commit from the bot
logger.debug( logger.debug(
...@@ -136,7 +136,7 @@ export async function getUpdatedPackageFiles( ...@@ -136,7 +136,7 @@ export async function getUpdatedPackageFiles(
logger.debug(`Updating ${depName} in ${packageFile}`); logger.debug(`Updating ${depName} in ${packageFile}`);
updatedFileContents[packageFile] = newContent; updatedFileContents[packageFile] = newContent;
} }
if (newContent === existingContent) { if (newContent === packageFileContent) {
// istanbul ignore else // istanbul ignore else
if (upgrade.datasource === datasourceGitSubmodules.id) { if (upgrade.datasource === datasourceGitSubmodules.id) {
updatedFileContents[packageFile] = newContent; updatedFileContents[packageFile] = newContent;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment