Skip to content

Commit 19a8e82

Browse files
authored
fix: pull request title component can include '/' (#1499)
* test: failing test for parsing pull request title with slash in component * fix: pull request title component can include '/'
1 parent 168578c commit 19a8e82

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/util/pull-request-title.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function generateMatchPattern(pullRequestTitlePattern?: string): RegExp {
4242
.replace('[', '\\[') // TODO: handle all regex escaping
4343
.replace(']', '\\]')
4444
.replace('${scope}', '(\\((?<branch>[\\w-./]+)\\))?')
45-
.replace('${component}', ' ?(?<component>[\\w-.]*)?')
45+
.replace('${component}', ' ?(?<component>[\\w-./]*)?')
4646
.replace('${version}', 'v?(?<version>[0-9].*)')
4747
.replace('${branch}', '(?<branch>[\\w-./]+)?')}$`
4848
);

test/util/pull-request-title.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ describe('PullRequestTitle', () => {
6969
expect(pullRequestTitle?.getVersion()?.toString()).to.eql('1.2.3');
7070
});
7171

72+
it('parses a target branch and component with a slash', () => {
73+
const name = 'chore(main): release some/title-test 0.0.1';
74+
const pullRequestTitle = PullRequestTitle.parse(name);
75+
expect(pullRequestTitle).to.not.be.undefined;
76+
expect(pullRequestTitle?.getTargetBranch()).to.eql('main');
77+
expect(pullRequestTitle?.getComponent()).to.eql('some/title-test');
78+
expect(pullRequestTitle?.getVersion()?.toString()).to.eql('0.0.1');
79+
});
80+
7281
it('fails to parse', () => {
7382
const pullRequestTitle = PullRequestTitle.parse('release-foo');
7483
expect(pullRequestTitle).to.be.undefined;
@@ -124,7 +133,7 @@ describe('PullRequestTitle', () => {
124133
it('return matchPattern with default Pattern', () => {
125134
const matchPattern = generateMatchPattern();
126135
expect(matchPattern).to.eql(
127-
/^chore(\((?<branch>[\w-./]+)\))?: release ?(?<component>[\w-.]*)? v?(?<version>[0-9].*)$/
136+
/^chore(\((?<branch>[\w-./]+)\))?: release ?(?<component>[\w-./]*)? v?(?<version>[0-9].*)$/
128137
);
129138
});
130139
});
@@ -278,7 +287,7 @@ describe('PullRequestTitle with custom pullRequestTitlePattern', () => {
278287
'chore${scope}: 🔖 release${component} ${version}'
279288
);
280289
expect(matchPattern).to.eql(
281-
/^chore(\((?<branch>[\w-./]+)\))?: 🔖 release ?(?<component>[\w-.]*)? v?(?<version>[0-9].*)$/
290+
/^chore(\((?<branch>[\w-./]+)\))?: 🔖 release ?(?<component>[\w-./]*)? v?(?<version>[0-9].*)$/
282291
);
283292
});
284293

0 commit comments

Comments
 (0)