Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/util/pull-request-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ export function generateMatchPattern(pullRequestTitlePattern?: string): RegExp {
logger.warn("pullRequestTitlePattern miss the part of '${version}'");
return new RegExp(
`^${(pullRequestTitlePattern || DEFAULT_PR_TITLE_PATTERN)
.replace('${scope}', '(\\((?<branch>[\\w-.]+)\\))?')
.replace('[', '\\[') // TODO: handle all regex escaping
.replace(']', '\\]')
.replace('${scope}', '(\\((?<branch>[\\w-./]+)\\))?')
.replace('${component}', ' ?(?<component>[\\w-.]*)?')
.replace('${version}', 'v?(?<version>[0-9].*)')
.replace('${branch}', '(?<branch>[\\w-.]+)?')}$`
.replace('${branch}', '(?<branch>[\\w-./]+)?')}$`
);
}

Expand Down Expand Up @@ -80,7 +82,7 @@ export class PullRequestTitle {
: undefined,
component: match.groups['component'],
targetBranch: match.groups['branch'],
pullRequestTitlePattern: pullRequestTitlePattern,
pullRequestTitlePattern,
});
}
return undefined;
Expand Down
42 changes: 42 additions & 0 deletions test/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4532,6 +4532,48 @@ describe('Manifest', () => {
const releases = await manifest.buildReleases();
expect(releases).lengthOf(0);
});

it('should handle complex title and base branch', async () => {
mockPullRequests(
github,
[],
[
{
headBranchName:
'release-please--branches--hotfix/v3.1.0-bug--components--my-package-name',
baseBranchName: 'hotfix/v3.1.0-bug',
number: 1234,
title: '[HOTFIX] - chore(hotfix/v3.1.0-bug): release 3.1.0-hotfix1',
body: pullRequestBody('release-notes/single.txt'),
labels: ['autorelease: pending'],
files: [],
sha: 'abc123',
},
]
);
const manifest = new Manifest(
github,
'hotfix/v3.1.0-bug',
{
'.': {
releaseType: 'simple',
pullRequestTitlePattern:
'[HOTFIX] - chore${scope}: release${component} ${version}',
packageName: 'my-package-name',
includeComponentInTag: false,
},
},
{
'.': Version.parse('3.1.0'),
}
);
const releases = await manifest.buildReleases();
expect(releases).lengthOf(1);
expect(releases[0].tag.toString()).to.eql('v3.1.0-hotfix1');
expect(releases[0].sha).to.eql('abc123');
expect(releases[0].notes).to.be.a('string');
expect(releases[0].path).to.eql('.');
});
});

describe('createReleases', () => {
Expand Down
10 changes: 10 additions & 0 deletions test/util/branch-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ describe('BranchName', () => {
expect(branchName?.toString()).to.eql(name);
});

it('parses a target branch that has a /', () => {
const name = 'release-please--branches--hotfix/3.3.x';
const branchName = BranchName.parse(name);
expect(branchName).to.not.be.undefined;
expect(branchName?.getTargetBranch()).to.eql('hotfix/3.3.x');
expect(branchName?.getComponent()).to.be.undefined;
expect(branchName?.getVersion()).to.be.undefined;
expect(branchName?.toString()).to.eql(name);
});

it('fails to parse', () => {
const branchName = BranchName.parse('release-foo');
expect(branchName).to.be.undefined;
Expand Down
17 changes: 15 additions & 2 deletions test/util/pull-request-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ describe('PullRequestTitle', () => {
it('return matchPattern with default Pattern', () => {
const matchPattern = generateMatchPattern();
expect(matchPattern).to.eql(
/^chore(\((?<branch>[\w-.]+)\))?: release ?(?<component>[\w-.]*)? v?(?<version>[0-9].*)$/
/^chore(\((?<branch>[\w-./]+)\))?: release ?(?<component>[\w-.]*)? v?(?<version>[0-9].*)$/
);
});
});
Expand Down Expand Up @@ -212,6 +212,19 @@ describe('PullRequestTitle with custom pullRequestTitlePattern', () => {
expect(pullRequestTitle?.getComponent()).to.be.undefined;
expect(pullRequestTitle?.getVersion()).to.be.undefined;
});

it('parses a complex title and pattern', () => {
const pullRequestTitle = PullRequestTitle.parse(
'[HOTFIX] - chore(hotfix/v3.1.0-bug): release 3.1.0-hotfix1',
'[HOTFIX] - chore${scope}: release${component} ${version}'
);
expect(pullRequestTitle).to.not.be.undefined;
expect(pullRequestTitle?.getTargetBranch()).to.eql('hotfix/v3.1.0-bug');
expect(pullRequestTitle?.getVersion()?.toString()).to.eql(
'3.1.0-hotfix1'
);
expect(pullRequestTitle?.getComponent()).to.be.undefined;
});
});
describe('ofVersion', () => {
it('builds the autorelease versioned branch name', () => {
Expand Down Expand Up @@ -265,7 +278,7 @@ describe('PullRequestTitle with custom pullRequestTitlePattern', () => {
'chore${scope}: 🔖 release${component} ${version}'
);
expect(matchPattern).to.eql(
/^chore(\((?<branch>[\w-.]+)\))?: 🔖 release ?(?<component>[\w-.]*)? v?(?<version>[0-9].*)$/
/^chore(\((?<branch>[\w-./]+)\))?: 🔖 release ?(?<component>[\w-.]*)? v?(?<version>[0-9].*)$/
);
});

Expand Down