Skip to content

Commit

Permalink
refactor(autoreplace): set depIndex during flatten (#20665)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins authored Feb 28, 2023
1 parent 14e2c7d commit 2f8aa56
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
1 change: 0 additions & 1 deletion lib/modules/manager/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ export interface PackageDependency<T = Record<string, any>>
updates?: LookupUpdate[];
replaceString?: string;
autoReplaceStringTemplate?: string;
depIndex?: number;
editFile?: string;
separateMinorPatch?: boolean;
extractVersion?: string;
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/repository/extract/manager-files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('workers/repository/extract/manager-files', () => {
expect(res).toEqual([
{
packageFile: 'Dockerfile',
deps: [{ depIndex: 0 }, { depIndex: 1, replaceString: 'abc' }],
deps: [{}, { replaceString: 'abc' }],
},
]);
});
Expand Down
10 changes: 0 additions & 10 deletions lib/workers/repository/extract/manager-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ export async function getManagerPackageFiles(
config,
fileList
);
if (allPackageFiles) {
for (const packageFile of allPackageFiles) {
for (let index = 0; index < packageFile.deps.length; index += 1) {
packageFile.deps[index].depIndex = index;
}
}
}
return allPackageFiles;
}
const packageFiles: PackageFile[] = [];
Expand All @@ -56,9 +49,6 @@ export async function getManagerPackageFiles(
config
);
if (res) {
for (let index = 0; index < res.deps.length; index += 1) {
res.deps[index].depIndex = index;
}
packageFiles.push({
...res,
packageFile,
Expand Down
9 changes: 9 additions & 0 deletions lib/workers/repository/updates/flatten.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import is from '@sindresorhus/is';
import { RenovateConfig, getConfig } from '../../../../test/util';
import { flattenUpdates } from './flatten';

Expand Down Expand Up @@ -144,6 +145,14 @@ describe('workers/repository/updates/flatten', () => {
};
const res = await flattenUpdates(config, packageFiles);
expect(res).toHaveLength(14);
expect(
res.every(
(upgrade) =>
upgrade.isLockFileMaintenance ||
upgrade.isRemediation ||
is.number(upgrade.depIndex)
)
).toBeTrue();
expect(
res.filter((update) => update.sourceRepoSlug)[0].sourceRepoSlug
).toBe('org-repo');
Expand Down
3 changes: 3 additions & 0 deletions lib/workers/repository/updates/flatten.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ export async function flattenUpdates(
packageFileConfig.parentDir = '';
packageFileConfig.packageFileDir = '';
}
let depIndex = 0;
for (const dep of packageFile.deps) {
if (dep.updates.length) {
const depConfig = mergeChildConfig(packageFileConfig, dep);
delete depConfig.deps;
depConfig.depIndex = depIndex; // used for autoreplace
for (const update of dep.updates) {
let updateConfig = mergeChildConfig(depConfig, update);
delete updateConfig.updates;
Expand Down Expand Up @@ -128,6 +130,7 @@ export async function flattenUpdates(
updates.push(updateConfig);
}
}
depIndex += 1;
}
if (
get(manager, 'supportsLockFileMaintenance') &&
Expand Down
1 change: 1 addition & 0 deletions lib/workers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface BranchUpgradeConfig
currentDigest?: string;
currentDigestShort?: string;
currentValue?: string;
depIndex?: number;
excludeCommitPaths?: string[];
githubName?: string;
group?: GroupConfig;
Expand Down

0 comments on commit 2f8aa56

Please sign in to comment.