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 2 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
14 changes: 10 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,13 @@ module.exports = async function validatePrTitle(
);
}

if (scopes && result.scope && !scopes.includes(result.scope)) {
const givenScopes = result.scope ? result.scope.split(',') : undefined;
amromusharaf marked this conversation as resolved.
Show resolved Hide resolved
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 scope(s) "${unknownScopes.join(
amromusharaf marked this conversation as resolved.
Show resolved Hide resolved
','
)}" found in pull request title "${prTitle}". Use one of the available scopes: ${scopes.join(
', '
)}.`
);
Expand Down
16 changes: 15 additions & 1 deletion src/validatePrTitle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,25 @@ 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 scope(s) "e2e,bar" found in pull request title "fix(core,e2e,foo,bar): Bar". Use one of the available scopes: foo, core.'
amromusharaf marked this conversation as resolved.
Show resolved Hide resolved
);
});

it('throws when an unknown scope is detected', async () => {
await expect(
validatePrTitle('fix(core): Bar', {scopes: ['foo']})
).rejects.toThrow(
'Unknown scope "core" found in pull request title "fix(core): Bar". Use one of the available scopes: foo.'
'Unknown scope(s) "core" found in pull request title "fix(core): Bar". Use one of the available scopes: foo.'
);
});

Expand Down