feat: convert sourceDirectory to a template eligible config (#32701)

Signed-off-by: Adam Setch <adam.setch@outlook.com>
This commit is contained in:
Adam Setch 2024-11-26 00:43:20 -05:00 committed by GitHub
parent ca3d35d3b2
commit 74c87b41e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 42 additions and 5 deletions

View file

@ -147,6 +147,7 @@ export const exposedConfigOptions = [
'semanticCommitType', 'semanticCommitType',
'separateMajorMinor', 'separateMajorMinor',
'separateMinorPatch', 'separateMinorPatch',
'sourceDirectory',
]; ];
export const allowedFields = { export const allowedFields = {

View file

@ -29,6 +29,11 @@ describe('workers/repository/updates/flatten', () => {
enabled: false, enabled: false,
}, },
}, },
{
matchPackageNames: ['@monorepo/package'],
sourceUrl: 'https://github.com/some/monorepo',
sourceDirectory: "subfolder/{{ lookup (split packageName '/') 1 }}",
},
]; ];
config.remediations = { config.remediations = {
'package-lock.json': [ 'package-lock.json': [
@ -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'], updateTypes: ['pin'],
updates: [{ newValue: '2.0.0' }], updates: [{ newValue: '2.0.0' }],
@ -144,7 +160,7 @@ describe('workers/repository/updates/flatten', () => {
], ],
}; };
const res = await flattenUpdates(config, packageFiles); const res = await flattenUpdates(config, packageFiles);
expect(res).toHaveLength(14); expect(res).toHaveLength(15);
expect( expect(
res.every( res.every(
(upgrade) => (upgrade) =>
@ -178,16 +194,29 @@ describe('workers/repository/updates/flatten', () => {
res.filter((update) => update.sourceRepoName)[1].sourceRepoName, res.filter((update) => update.sourceRepoName)[1].sourceRepoName,
).toBe('repo'); ).toBe('repo');
expect( 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'); ).toBe('nodejs-node');
expect(res.filter((update) => update.sourceRepo)[2].sourceRepo).toBe( expect(res.filter((update) => update.sourceRepo)[3].sourceRepo).toBe(
'nodejs/node', 'nodejs/node',
); );
expect( expect(
res.filter((update) => update.sourceRepoOrg)[2].sourceRepoOrg, res.filter((update) => update.sourceRepoOrg)[3].sourceRepoOrg,
).toBe('nodejs'); ).toBe('nodejs');
expect( expect(
res.filter((update) => update.sourceRepoName)[2].sourceRepoName, res.filter((update) => update.sourceRepoName)[3].sourceRepoName,
).toBe('node'); ).toBe('node');
expect( expect(
res.filter( res.filter(

View file

@ -9,6 +9,7 @@ import { get } from '../../../modules/manager';
import { detectSemanticCommits } from '../../../util/git/semantic'; import { detectSemanticCommits } from '../../../util/git/semantic';
import { applyPackageRules } from '../../../util/package-rules'; import { applyPackageRules } from '../../../util/package-rules';
import { regEx } from '../../../util/regex'; import { regEx } from '../../../util/regex';
import * as template from '../../../util/template';
import { parseUrl } from '../../../util/url'; import { parseUrl } from '../../../util/url';
import type { BranchUpgradeConfig } from '../../types'; import type { BranchUpgradeConfig } from '../../types';
import { generateBranchName } from './branch-name'; import { generateBranchName } from './branch-name';
@ -57,6 +58,12 @@ export function applyUpdateConfig(input: BranchUpgradeConfig): any {
); // remove everything up to the last slash ); // remove everything up to the last slash
} }
} }
if (updateConfig.sourceDirectory) {
updateConfig.sourceDirectory = template.compile(
updateConfig.sourceDirectory,
updateConfig,
);
}
generateBranchName(updateConfig); generateBranchName(updateConfig);
return updateConfig; return updateConfig;
} }