Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add ability to use multiple scopes #85

Merged
merged 4 commits into from
Feb 10, 2021
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
18 changes: 14 additions & 4 deletions src/validatePrTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ module.exports = async function validatePrTitle(
.join('\n')}`;
}

function isUnknownScope(s) {
return scopes && !scopes.includes(s);
}

if (!result.type) {
throw new Error(
`No release type found in pull request title "${prTitle}". Add a prefix to indicate what kind of release this pull request corresponds to (see https://www.conventionalcommits.org/).\n\n${printAvailableTypes()}`
Expand All @@ -54,11 +58,17 @@ module.exports = async function validatePrTitle(
);
}

if (scopes && result.scope && !scopes.includes(result.scope)) {
const givenScopes = result.scope
? result.scope.split(',').map((scope) => scope.trim())
: undefined;
const unknownScopes = givenScopes ? givenScopes.filter(isUnknownScope) : [];
if (scopes && unknownScopes.length > 0) {
throw new Error(
`Unknown scope "${
result.scope
}" found in pull request title "${prTitle}". Use one of the available scopes: ${scopes.join(
`Unknown ${
unknownScopes.length > 1 ? 'scopes' : 'scope'
} "${unknownScopes.join(
','
)}" found in pull request title "${prTitle}". Use one of the available scopes: ${scopes.join(
', '
)}.`
);
Expand Down
14 changes: 14 additions & 0 deletions src/validatePrTitle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ describe('defined scopes', () => {
await validatePrTitle('fix(core): Bar', {scopes: ['core']});
});

it('allows multiple matching scopes', async () => {
await validatePrTitle('fix(core,e2e): Bar', {
scopes: ['core', 'e2e', 'web']
});
});

it('throws when an unknown scope is detected within multiple scopes', async () => {
await expect(
validatePrTitle('fix(core,e2e,foo,bar): Bar', {scopes: ['foo', 'core']})
Copy link

@webstoreportal webstoreportal May 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any issue in convention of comma separator symbol , with—or without—a trailing space?


I remember one CLI tool parsed differently to the other (replacing spaces with hyphen), not sure if the push made it implicitly to the "official spec" https://www.conventionalcommits.org/en/v1.0.0-beta.3/


has seen adoption from enough tools


conventional-changelog/conventional-changelog#232
conventional-changelog/commitlint#901

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the official convention, but I think we should support spaces in this action:

? result.scope.split(',').map((scope) => scope.trim())

).rejects.toThrow(
'Unknown scopes "e2e,bar" found in pull request title "fix(core,e2e,foo,bar): Bar". Use one of the available scopes: foo, core.'
);
});

it('throws when an unknown scope is detected', async () => {
await expect(
validatePrTitle('fix(core): Bar', {scopes: ['foo']})
Expand Down