Skip to content

Commit

Permalink
refactor: new checkExistingBranch function in doAutoReplace (#17500)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-kulmburg committed Aug 30, 2022
1 parent 92f6a9c commit 7f4185b
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions lib/workers/repository/update/branch/auto-replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,29 @@ export async function checkBranchDepsMatchBaseDeps(
}
}

async function checkExistingBranch(
upgrade: BranchUpgradeConfig,
existingContent: string
): Promise<string | null> {
const { packageFile, depName } = upgrade;
if (!(await checkBranchDepsMatchBaseDeps(upgrade, existingContent))) {
logger.debug(
{ packageFile, depName },
'Rebasing branch after deps list has changed'
);
return null;
}
if (!(await confirmIfDepUpdated(upgrade, existingContent))) {
logger.debug(
{ packageFile, depName },
'Rebasing after outdated branch dep found'
);
return null;
}
logger.debug({ packageFile, depName }, 'Branch dep is already updated');
return existingContent;
}

export async function doAutoReplace(
upgrade: BranchUpgradeConfig,
existingContent: string,
Expand All @@ -120,22 +143,7 @@ export async function doAutoReplace(
autoReplaceStringTemplate,
} = upgrade;
if (reuseExistingBranch) {
if (!(await checkBranchDepsMatchBaseDeps(upgrade, existingContent))) {
logger.debug(
{ packageFile, depName },
'Rebasing branch after deps list has changed'
);
return null;
}
if (!(await confirmIfDepUpdated(upgrade, existingContent))) {
logger.debug(
{ packageFile, depName },
'Rebasing after outdated branch dep found'
);
return null;
}
logger.debug({ packageFile, depName }, 'Branch dep is already updated');
return existingContent;
return await checkExistingBranch(upgrade, existingContent);
}
const replaceString = upgrade.replaceString ?? currentValue;
logger.trace({ depName, replaceString }, 'autoReplace replaceString');
Expand Down

0 comments on commit 7f4185b

Please sign in to comment.