Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: convert sourceDirectory to a template eligible config #32701

Merged
merged 7 commits into from
Nov 26, 2024
Merged
1 change: 1 addition & 0 deletions lib/util/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export const exposedConfigOptions = [
'semanticCommitType',
'separateMajorMinor',
'separateMinorPatch',
'sourceDirectory',
];

export const allowedFields = {
Expand Down
39 changes: 34 additions & 5 deletions lib/workers/repository/updates/flatten.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ describe('workers/repository/updates/flatten', () => {
enabled: false,
},
},
{
matchPackageNames: ['@monorepo/package'],
sourceUrl: 'https://github.com/some/monorepo',
sourceDirectory: "subfolder/{{ lookup (split packageName '/') 1 }}",
},
];
config.remediations = {
'package-lock.json': [
Expand Down Expand Up @@ -65,6 +70,17 @@ describe('workers/repository/updates/flatten', () => {
},
],
},
{
depName: '@monorepo/package',
updates: [
{
newValue: '2.0.0',
sourceUrl: 'https://github.com/some/monorepo',
sourceDirectory:
"subfolder/{{ lookup (split depName '/') 1 }}",
},
],
},
{
updateTypes: ['pin'],
updates: [{ newValue: '2.0.0' }],
Expand Down Expand Up @@ -144,7 +160,7 @@ describe('workers/repository/updates/flatten', () => {
],
};
const res = await flattenUpdates(config, packageFiles);
expect(res).toHaveLength(14);
expect(res).toHaveLength(15);
expect(
res.every(
(upgrade) =>
Expand Down Expand Up @@ -178,16 +194,29 @@ describe('workers/repository/updates/flatten', () => {
res.filter((update) => update.sourceRepoName)[1].sourceRepoName,
).toBe('repo');
expect(
res.filter((update) => update.sourceRepoSlug)[2].sourceRepoSlug,
res.filter((update) => update.depName === '@monorepo/package')[0],
).toEqual(
expect.objectContaining({
depName: '@monorepo/package',
sourceRepoOrg: 'some',
sourceRepoName: 'monorepo',
sourceRepo: 'some/monorepo',
sourceRepoSlug: 'some-monorepo',
sourceUrl: 'https://github.com/some/monorepo',
sourceDirectory: 'subfolder/package',
}),
);
expect(
res.filter((update) => update.sourceRepoSlug)[3].sourceRepoSlug,
).toBe('nodejs-node');
expect(res.filter((update) => update.sourceRepo)[2].sourceRepo).toBe(
expect(res.filter((update) => update.sourceRepo)[3].sourceRepo).toBe(
'nodejs/node',
);
expect(
res.filter((update) => update.sourceRepoOrg)[2].sourceRepoOrg,
res.filter((update) => update.sourceRepoOrg)[3].sourceRepoOrg,
).toBe('nodejs');
expect(
res.filter((update) => update.sourceRepoName)[2].sourceRepoName,
res.filter((update) => update.sourceRepoName)[3].sourceRepoName,
).toBe('node');
expect(
res.filter(
Expand Down
7 changes: 7 additions & 0 deletions lib/workers/repository/updates/flatten.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { get } from '../../../modules/manager';
import { detectSemanticCommits } from '../../../util/git/semantic';
import { applyPackageRules } from '../../../util/package-rules';
import { regEx } from '../../../util/regex';
import * as template from '../../../util/template';
import { parseUrl } from '../../../util/url';
import type { BranchUpgradeConfig } from '../../types';
import { generateBranchName } from './branch-name';
Expand Down Expand Up @@ -57,6 +58,12 @@ export function applyUpdateConfig(input: BranchUpgradeConfig): any {
); // remove everything up to the last slash
}
}
if (updateConfig.sourceDirectory) {
updateConfig.sourceDirectory = template.compile(
updateConfig.sourceDirectory,
updateConfig,
);
}
generateBranchName(updateConfig);
return updateConfig;
}
Expand Down