diff --git a/lib/util/template/index.ts b/lib/util/template/index.ts index a57d8fd43e48d9a5e939c2edcf977802d1f9e7ad..833198b90484ea16402555ad48714876a73eb7d6 100644 --- a/lib/util/template/index.ts +++ b/lib/util/template/index.ts @@ -116,6 +116,9 @@ export const allowedFields = { releaseNotes: 'A ChangeLogNotes object for the release', repository: 'The current repository', semanticPrefix: 'The fully generated semantic prefix for commit messages', + sourceRepo: 'The repository in the sourceUrl, if present', + sourceRepoName: 'The repository name in the sourceUrl, if present', + sourceRepoOrg: 'The repository organization in the sourceUrl, if present', sourceRepoSlug: 'The slugified pathname of the sourceUrl, if present', sourceUrl: 'The source URL for the package', updateType: 'One of digest, pin, rollback, patch, minor, major, replacement', diff --git a/lib/workers/repository/updates/flatten.spec.ts b/lib/workers/repository/updates/flatten.spec.ts index 84c3a997eb74caa0fade356b8a483ba1b54e7ac1..c6868350aea6dccde72d606adc9360a95e0df07b 100644 --- a/lib/workers/repository/updates/flatten.spec.ts +++ b/lib/workers/repository/updates/flatten.spec.ts @@ -142,7 +142,42 @@ describe('workers/repository/updates/flatten', () => { }; const res = await flattenUpdates(config, packageFiles); expect(res).toHaveLength(14); - expect(res.filter((update) => update.sourceRepoSlug)).toHaveLength(3); + expect( + res.filter((update) => update.sourceRepoSlug)[0].sourceRepoSlug + ).toBe('org-repo'); + expect(res.filter((update) => update.sourceRepo)[0].sourceRepo).toBe( + 'org/repo' + ); + expect( + res.filter((update) => update.sourceRepoOrg)[0].sourceRepoOrg + ).toBe('org'); + expect( + res.filter((update) => update.sourceRepoName)[0].sourceRepoName + ).toBe('repo'); + expect( + res.filter((update) => update.sourceRepoSlug)[1].sourceRepoSlug + ).toBe('org-repo'); + expect(res.filter((update) => update.sourceRepo)[1].sourceRepo).toBe( + 'org/repo' + ); + expect( + res.filter((update) => update.sourceRepoOrg)[1].sourceRepoOrg + ).toBe('org'); + expect( + res.filter((update) => update.sourceRepoName)[1].sourceRepoName + ).toBe('repo'); + expect( + res.filter((update) => update.sourceRepoSlug)[2].sourceRepoSlug + ).toBe('nodejs-node'); + expect(res.filter((update) => update.sourceRepo)[2].sourceRepo).toBe( + 'nodejs/node' + ); + expect( + res.filter((update) => update.sourceRepoOrg)[2].sourceRepoOrg + ).toBe('nodejs'); + expect( + res.filter((update) => update.sourceRepoName)[2].sourceRepoName + ).toBe('node'); expect( res.filter((r) => r.updateType === 'lockFileMaintenance') ).toHaveLength(2); diff --git a/lib/workers/repository/updates/flatten.ts b/lib/workers/repository/updates/flatten.ts index 36cd1411407ae62b1ffc29c6a1c96fc49578106f..36ddcc1c76afd5efd0608c4072feb6dffd9dad0d 100644 --- a/lib/workers/repository/updates/flatten.ts +++ b/lib/workers/repository/updates/flatten.ts @@ -42,6 +42,18 @@ export function applyUpdateConfig(input: BranchUpgradeConfig): any { .replace(regEx(/^\//), '') // remove leading slash .replace(regEx(/\//g), '-') // change slashes to hyphens .replace(regEx(/-+/g), '-'); // remove multiple hyphens + updateConfig.sourceRepo = parsedSourceUrl.pathname.replace( + regEx(/^\//), + '' + ); // remove leading slash + updateConfig.sourceRepoOrg = updateConfig.sourceRepo.replace( + regEx(/\/.*/g), + '' + ); // remove everything after first slash + updateConfig.sourceRepoName = updateConfig.sourceRepo.replace( + regEx(/.*\//g), + '' + ); // remove everything up to the last slash } } generateBranchName(updateConfig); diff --git a/lib/workers/types.ts b/lib/workers/types.ts index d311d0c18a785279f1c791c56dce080225cd9041..a914885830b047261e943556e970598787cf4d7b 100644 --- a/lib/workers/types.ts +++ b/lib/workers/types.ts @@ -69,6 +69,9 @@ export interface BranchUpgradeConfig changelogUrl?: string; dependencyUrl?: string; sourceUrl?: string; + sourceRepo?: string; + sourceRepoOrg?: string; + sourceRepoName?: string; } export type PrBlockedBy =