Skip to content

Commit 7d214ff

Browse files
committed
feat: make linked-versions configurable
1 parent 6a9ddb7 commit 7d214ff

File tree

4 files changed

+162
-1
lines changed

4 files changed

+162
-1
lines changed

src/factories/plugin-factory.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export interface PluginFactoryOptions {
4848
updateAllPackages?: boolean;
4949
considerAllArtifacts?: boolean;
5050

51+
// linked-versions options
52+
groupPullRequestTitlePattern?: string;
53+
5154
logger?: Logger;
5255
}
5356

src/manifest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ export class Manifest {
401401
repositoryConfig: this.repositoryConfig,
402402
manifestPath: this.manifestPath,
403403
separatePullRequests: this.separatePullRequests,
404+
groupPullRequestTitlePattern: this.groupPullRequestTitlePattern,
404405
})
405406
);
406407
this.pullRequestOverflowHandler = new FilePullRequestOverflowHandler(

src/plugins/linked-versions.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {BranchName} from '../util/branch-name';
2626

2727
interface LinkedVersionsPluginOptions {
2828
merge?: boolean;
29+
groupPullRequestTitlePattern?: string;
2930
logger?: Logger;
3031
}
3132

@@ -39,6 +40,7 @@ export class LinkedVersions extends ManifestPlugin {
3940
readonly groupName: string;
4041
readonly components: Set<string>;
4142
readonly merge: boolean;
43+
private groupPullRequestTitlePattern?: string;
4244

4345
constructor(
4446
github: GitHub,
@@ -52,6 +54,7 @@ export class LinkedVersions extends ManifestPlugin {
5254
this.groupName = groupName;
5355
this.components = new Set(components);
5456
this.merge = options.merge ?? true;
57+
this.groupPullRequestTitlePattern = options.groupPullRequestTitlePattern;
5558
}
5659

5760
/**
@@ -173,12 +176,23 @@ export class LinkedVersions extends ManifestPlugin {
173176

174177
// delegate to the merge plugin and add merged pull request
175178
if (inScopeCandidates.length > 0) {
179+
// Use configured pattern if available, otherwise default to "libraries" for backward compatibility
180+
let pullRequestTitlePattern = this.groupPullRequestTitlePattern
181+
? this.groupPullRequestTitlePattern
182+
: `chore\${scope}: release ${this.groupName} libraries`;
183+
184+
// Replace ${component} placeholder with the actual group name
185+
pullRequestTitlePattern = pullRequestTitlePattern.replace(
186+
'${component}',
187+
this.groupName
188+
);
189+
176190
const merge = new Merge(
177191
this.github,
178192
this.targetBranch,
179193
this.repositoryConfig,
180194
{
181-
pullRequestTitlePattern: `chore\${scope}: release ${this.groupName} libraries`,
195+
pullRequestTitlePattern,
182196
forceMerge: true,
183197
headBranchName: BranchName.ofGroupTargetBranch(
184198
this.groupName,

test/plugins/linked-versions.ts

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,4 +346,147 @@ describe('LinkedVersions plugin', () => {
346346
expect(groupPullRequest1.headRefName).to.not.include(' ');
347347
expect(groupPullRequest2.headRefName).to.not.include(' ');
348348
});
349+
350+
it('should use "libraries" in title by default for backward compatibility', async () => {
351+
const manifest = new Manifest(
352+
github,
353+
'target-branch',
354+
{
355+
'path/a': {
356+
releaseType: 'simple',
357+
component: 'pkg1',
358+
},
359+
'path/b': {
360+
releaseType: 'simple',
361+
component: 'pkg2',
362+
},
363+
'path/c': {
364+
releaseType: 'simple',
365+
component: 'pkg3',
366+
},
367+
},
368+
{
369+
'path/a': Version.parse('1.0.0'),
370+
'path/b': Version.parse('0.2.3'),
371+
'path/c': Version.parse('0.2.3'),
372+
},
373+
{
374+
separatePullRequests: true,
375+
plugins: [
376+
{
377+
type: 'linked-versions',
378+
groupName: 'my-group',
379+
components: ['pkg2', 'pkg3'],
380+
},
381+
],
382+
}
383+
);
384+
const pullRequests = await manifest.buildPullRequests();
385+
expect(pullRequests).lengthOf(2);
386+
const groupedPullRequest = pullRequests.find(pr =>
387+
pr.title.toString().includes('my-group')
388+
);
389+
expect(groupedPullRequest).to.not.be.undefined;
390+
expect(groupedPullRequest!.title.toString()).to.include('libraries');
391+
expect(groupedPullRequest!.title.toString()).to.equal(
392+
'chore(target-branch): release my-group libraries'
393+
);
394+
});
395+
396+
it('should respect groupPullRequestTitlePattern with version', async () => {
397+
const manifest = new Manifest(
398+
github,
399+
'target-branch',
400+
{
401+
'path/a': {
402+
releaseType: 'simple',
403+
component: 'pkg1',
404+
},
405+
'path/b': {
406+
releaseType: 'simple',
407+
component: 'pkg2',
408+
},
409+
'path/c': {
410+
releaseType: 'simple',
411+
component: 'pkg3',
412+
},
413+
},
414+
{
415+
'path/a': Version.parse('1.0.0'),
416+
'path/b': Version.parse('0.2.3'),
417+
'path/c': Version.parse('0.2.3'),
418+
},
419+
{
420+
separatePullRequests: true,
421+
groupPullRequestTitlePattern:
422+
'chore${scope}: release ${component} ${version}',
423+
plugins: [
424+
{
425+
type: 'linked-versions',
426+
groupName: 'my-sdk',
427+
components: ['pkg2', 'pkg3'],
428+
},
429+
],
430+
}
431+
);
432+
const pullRequests = await manifest.buildPullRequests();
433+
expect(pullRequests).lengthOf(2);
434+
// Find the grouped PR (pkg2+pkg3) - it should have multiple release data entries
435+
const groupedPullRequest = pullRequests.find(
436+
pr => pr.body.releaseData.length > 1
437+
);
438+
expect(groupedPullRequest).to.not.be.undefined;
439+
expect(groupedPullRequest!.title.toString()).to.not.include('libraries');
440+
expect(groupedPullRequest!.title.toString()).to.include('0.2.4');
441+
expect(groupedPullRequest!.title.toString()).to.equal(
442+
'chore(target-branch): release my-sdk 0.2.4'
443+
);
444+
});
445+
446+
it('should respect custom groupPullRequestTitlePattern', async () => {
447+
const manifest = new Manifest(
448+
github,
449+
'target-branch',
450+
{
451+
'path/a': {
452+
releaseType: 'simple',
453+
component: 'pkg1',
454+
},
455+
'path/b': {
456+
releaseType: 'simple',
457+
component: 'pkg2',
458+
},
459+
'path/c': {
460+
releaseType: 'simple',
461+
component: 'pkg3',
462+
},
463+
},
464+
{
465+
'path/a': Version.parse('1.0.0'),
466+
'path/b': Version.parse('0.2.3'),
467+
'path/c': Version.parse('0.2.3'),
468+
},
469+
{
470+
separatePullRequests: true,
471+
groupPullRequestTitlePattern: 'feat${scope}: ${component} v${version}',
472+
plugins: [
473+
{
474+
type: 'linked-versions',
475+
groupName: 'core-libs',
476+
components: ['pkg2', 'pkg3'],
477+
},
478+
],
479+
}
480+
);
481+
const pullRequests = await manifest.buildPullRequests();
482+
expect(pullRequests).lengthOf(2);
483+
// Find the grouped PR (pkg2+pkg3) - it should have multiple release data entries
484+
const groupedPullRequest = pullRequests.find(
485+
pr => pr.body.releaseData.length > 1
486+
);
487+
expect(groupedPullRequest).to.not.be.undefined;
488+
expect(groupedPullRequest!.title.toString()).to.equal(
489+
'feat(target-branch): core-libs v0.2.4'
490+
);
491+
});
349492
});

0 commit comments

Comments
 (0)