From 19a8e8263500dedd32f3b555a9f00f8627f27a6d Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 30 Jun 2022 11:56:29 -0700 Subject: [PATCH] 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 '/' --- src/util/pull-request-title.ts | 2 +- test/util/pull-request-title.ts | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/util/pull-request-title.ts b/src/util/pull-request-title.ts index a75d74b79..8ff9ba50d 100644 --- a/src/util/pull-request-title.ts +++ b/src/util/pull-request-title.ts @@ -42,7 +42,7 @@ export function generateMatchPattern(pullRequestTitlePattern?: string): RegExp { .replace('[', '\\[') // TODO: handle all regex escaping .replace(']', '\\]') .replace('${scope}', '(\\((?[\\w-./]+)\\))?') - .replace('${component}', ' ?(?[\\w-.]*)?') + .replace('${component}', ' ?(?[\\w-./]*)?') .replace('${version}', 'v?(?[0-9].*)') .replace('${branch}', '(?[\\w-./]+)?')}$` ); diff --git a/test/util/pull-request-title.ts b/test/util/pull-request-title.ts index 561018329..e7f1b51fb 100644 --- a/test/util/pull-request-title.ts +++ b/test/util/pull-request-title.ts @@ -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; @@ -124,7 +133,7 @@ describe('PullRequestTitle', () => { it('return matchPattern with default Pattern', () => { const matchPattern = generateMatchPattern(); expect(matchPattern).to.eql( - /^chore(\((?[\w-./]+)\))?: release ?(?[\w-.]*)? v?(?[0-9].*)$/ + /^chore(\((?[\w-./]+)\))?: release ?(?[\w-./]*)? v?(?[0-9].*)$/ ); }); }); @@ -278,7 +287,7 @@ describe('PullRequestTitle with custom pullRequestTitlePattern', () => { 'chore${scope}: 🔖 release${component} ${version}' ); expect(matchPattern).to.eql( - /^chore(\((?[\w-./]+)\))?: 🔖 release ?(?[\w-.]*)? v?(?[0-9].*)$/ + /^chore(\((?[\w-./]+)\))?: 🔖 release ?(?[\w-./]*)? v?(?[0-9].*)$/ ); });