Skip to content

Commit

Permalink
feat: support for "@" sign in component name (#1873)
Browse files Browse the repository at this point in the history
* feat: support for "@" sign in component name

* test: check @ sign prefix for component in PR title
  • Loading branch information
raaymax authored Mar 14, 2023
1 parent 162b645 commit d3b2f2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 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 @@ -47,7 +47,7 @@ export function generateMatchPattern(
.replace('(', '\\(')
.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
18 changes: 14 additions & 4 deletions test/util/pull-request-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,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 @@ -202,6 +202,16 @@ describe('PullRequestTitle with custom pullRequestTitlePattern', () => {
expect(pullRequestTitle?.getVersion()?.toString()).to.eql('1.2.3');
});

it('parses a component with @ sign prefix', () => {
const name = 'chore(main): 🔖 release @example/storage v1.2.3';
const pullRequestTitle = PullRequestTitle.parse(
name,
'chore${scope}: 🔖 release${component} ${version}'
);
expect(pullRequestTitle).to.not.be.undefined;
expect(pullRequestTitle?.getComponent()).to.eql('@example/storage');
});

it('fails to parse', () => {
const pullRequestTitle = PullRequestTitle.parse(
'release-foo',
Expand All @@ -224,15 +234,15 @@ describe('PullRequestTitle with custom pullRequestTitlePattern', () => {

it('parses a complex title and pattern', () => {
const pullRequestTitle = PullRequestTitle.parse(
'[HOTFIX] - chore(hotfix/v3.1.0-bug): release 3.1.0-hotfix1 (storage)',
'[HOTFIX] - chore(hotfix/v3.1.0-bug): release 3.1.0-hotfix1 (@example/storage)',
'[HOTFIX] - chore${scope}: release ${version} (${component})'
);
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.eql('storage');
expect(pullRequestTitle?.getComponent()).to.eql('@example/storage');
});
});
describe('ofVersion', () => {
Expand Down Expand Up @@ -287,7 +297,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 d3b2f2f

Please sign in to comment.