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']);
|
const packageLock = JSON.parse(res.files['package-lock.json']);
|
||||||
expect(packageLock.dependencies.express.version).toBe('4.1.0');
|
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 () => {
|
it('remediates mime', async () => {
|
||||||
config.depName = 'mime';
|
config.depName = 'mime';
|
||||||
config.currentVersion = '1.2.11';
|
config.currentVersion = '1.2.11';
|
||||||
|
|
|
@ -47,18 +47,32 @@ export async function updateLockedDependency(
|
||||||
currentVersion
|
currentVersion
|
||||||
);
|
);
|
||||||
if (!lockedDeps.length) {
|
if (!lockedDeps.length) {
|
||||||
logger.debug(
|
const newLockedDeps = getLockedDependencies(
|
||||||
`${depName}@${currentVersion} not found in ${lockFile} - no work to do`
|
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
|
// Don't return {} if we're a parent update or else the whole update will fail
|
||||||
// istanbul ignore if: too hard to replicate
|
// istanbul ignore if: too hard to replicate
|
||||||
if (isParentUpdate) {
|
if (isParentUpdate) {
|
||||||
const res: UpdateLockedResult = { status: 'update-failed', files: {} };
|
const res: UpdateLockedResult = { status, files: {} };
|
||||||
res.files[packageFile] = packageFileContent;
|
res.files[packageFile] = packageFileContent;
|
||||||
res.files[lockFile] = lockFileContent;
|
res.files[lockFile] = lockFileContent;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
return { status: 'update-failed' };
|
return { status };
|
||||||
}
|
}
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`Found matching dependencies with length ${lockedDeps.length}`
|
`Found matching dependencies with length ${lockedDeps.length}`
|
||||||
|
|
|
@ -231,7 +231,7 @@ export interface UpdateLockedConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateLockedResult {
|
export interface UpdateLockedResult {
|
||||||
status: 'updated' | 'update-failed';
|
status: 'updated' | 'already-updated' | 'update-failed';
|
||||||
files?: Record<string, string>;
|
files?: Record<string, string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,23 +74,22 @@ export async function getUpdatedPackageFiles(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const updateLockedDependency = get(manager, 'updateLockedDependency');
|
const updateLockedDependency = get(manager, 'updateLockedDependency');
|
||||||
const { files } = await updateLockedDependency({
|
const { status, files } = await updateLockedDependency({
|
||||||
...upgrade,
|
...upgrade,
|
||||||
packageFileContent,
|
packageFileContent,
|
||||||
lockFileContent,
|
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 (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 };
|
updatedFileContents = { ...updatedFileContents, ...files };
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue