Skip to content

Commit

Permalink
fix: pull request title component can include '/' (#1499)
Browse files Browse the repository at this point in the history
* test: failing test for parsing pull request title with slash in component

* fix: pull request title component can include '/'
  • Loading branch information
chingor13 authored Jun 30, 2022
1 parent 168578c commit 19a8e82
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/util/pull-request-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function generateMatchPattern(pullRequestTitlePattern?: string): RegExp {
.replace('[', '\\[') // TODO: handle all regex escaping
.replace(']', '\\]')
.replace('${scope}', '(\\((?<branch>[\\w-./]+)\\))?')
.replace('${component}', ' ?(?<component>[\\w-.]*)?')
.replace('${component}', ' ?(?<component>[\\w-./]*)?')
.replace('${version}', 'v?(?<version>[0-9].*)')
.replace('${branch}', '(?<branch>[\\w-./]+)?')}$`
);
Expand Down
13 changes: 11 additions & 2 deletions test/util/pull-request-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ describe('PullRequestTitle', () => {
expect(pullRequestTitle?.getVersion()?.toString()).to.eql('1.2.3');
});

it('parses a target branch and component with a slash', () => {
const name = 'chore(main): release some/title-test 0.0.1';
const pullRequestTitle = PullRequestTitle.parse(name);
expect(pullRequestTitle).to.not.be.undefined;
expect(pullRequestTitle?.getTargetBranch()).to.eql('main');
expect(pullRequestTitle?.getComponent()).to.eql('some/title-test');
expect(pullRequestTitle?.getVersion()?.toString()).to.eql('0.0.1');
});

it('fails to parse', () => {
const pullRequestTitle = PullRequestTitle.parse('release-foo');
expect(pullRequestTitle).to.be.undefined;
Expand Down Expand Up @@ -124,7 +133,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 @@ -278,7 +287,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

0 comments on commit 19a8e82

Please sign in to comment.