mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
feat(npm): check if branch already updated (#13185)
This commit is contained in:
parent
b84ce2ad55
commit
1f1c86a4f7
4 changed files with 37 additions and 17 deletions
|
@ -109,6 +109,13 @@ describe('manager/npm/update/locked-dependency/index', () => {
|
|||
const packageLock = JSON.parse(res.files['package-lock.json']);
|
||||
expect(packageLock.dependencies.express.version).toBe('4.1.0');
|
||||
});
|
||||
it('returns if already remediated', async () => {
|
||||
config.depName = 'mime';
|
||||
config.currentVersion = '1.2.10';
|
||||
config.newVersion = '1.2.11';
|
||||
const res = await updateLockedDependency(config);
|
||||
expect(res.status).toBe('already-updated');
|
||||
});
|
||||
it('remediates mime', async () => {
|
||||
config.depName = 'mime';
|
||||
config.currentVersion = '1.2.11';
|
||||
|
|
|
@ -47,18 +47,32 @@ export async function updateLockedDependency(
|
|||
currentVersion
|
||||
);
|
||||
if (!lockedDeps.length) {
|
||||
logger.debug(
|
||||
`${depName}@${currentVersion} not found in ${lockFile} - no work to do`
|
||||
const newLockedDeps = getLockedDependencies(
|
||||
packageLockJson,
|
||||
depName,
|
||||
newVersion
|
||||
);
|
||||
let status: 'update-failed' | 'already-updated';
|
||||
if (newLockedDeps.length) {
|
||||
logger.debug(
|
||||
`${depName}@${currentVersion} not found in ${lockFile} but ${depName}@${newVersion} was - looks like it's already updated`
|
||||
);
|
||||
status = 'already-updated';
|
||||
} else {
|
||||
logger.debug(
|
||||
`${depName}@${currentVersion} not found in ${lockFile} - cannot update`
|
||||
);
|
||||
status = 'update-failed';
|
||||
}
|
||||
// Don't return {} if we're a parent update or else the whole update will fail
|
||||
// istanbul ignore if: too hard to replicate
|
||||
if (isParentUpdate) {
|
||||
const res: UpdateLockedResult = { status: 'update-failed', files: {} };
|
||||
const res: UpdateLockedResult = { status, files: {} };
|
||||
res.files[packageFile] = packageFileContent;
|
||||
res.files[lockFile] = lockFileContent;
|
||||
return res;
|
||||
}
|
||||
return { status: 'update-failed' };
|
||||
return { status };
|
||||
}
|
||||
logger.debug(
|
||||
`Found matching dependencies with length ${lockedDeps.length}`
|
||||
|
|
|
@ -231,7 +231,7 @@ export interface UpdateLockedConfig {
|
|||
}
|
||||
|
||||
export interface UpdateLockedResult {
|
||||
status: 'updated' | 'update-failed';
|
||||
status: 'updated' | 'already-updated' | 'update-failed';
|
||||
files?: Record<string, string>;
|
||||
}
|
||||
|
||||
|
|
|
@ -74,23 +74,22 @@ export async function getUpdatedPackageFiles(
|
|||
});
|
||||
}
|
||||
const updateLockedDependency = get(manager, 'updateLockedDependency');
|
||||
const { files } = await updateLockedDependency({
|
||||
const { status, files } = await updateLockedDependency({
|
||||
...upgrade,
|
||||
packageFileContent,
|
||||
lockFileContent,
|
||||
});
|
||||
if (reuseExistingBranch && status !== 'already-updated') {
|
||||
logger.debug(
|
||||
{ lockFile, depName, status },
|
||||
'Need to retry branch as it is not already up-to-date'
|
||||
);
|
||||
return getUpdatedPackageFiles({
|
||||
...config,
|
||||
reuseExistingBranch: false,
|
||||
});
|
||||
}
|
||||
if (files) {
|
||||
if (reuseExistingBranch) {
|
||||
// This ensure it's always 1 commit from the bot
|
||||
logger.debug(
|
||||
{ lockFile, depName },
|
||||
'Need to update file(s) so will rebase first'
|
||||
);
|
||||
return getUpdatedPackageFiles({
|
||||
...config,
|
||||
reuseExistingBranch: false,
|
||||
});
|
||||
}
|
||||
updatedFileContents = { ...updatedFileContents, ...files };
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue