Skip to content
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ feat(ui): Add `Button` component
```yml
with:
# Configure which types are allowed (newline-delimited).
# These are regex patterns auto-wrapped in `^ $`.
# Default: https://github.com/commitizen/conventional-commit-types
types: |
fix
feat
JIRA-\d+
# Configure which scopes are allowed (newline-delimited).
# These are regex patterns auto-wrapped in `^ $`.
scopes: |
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ branding:
color: 'green'
inputs:
types:
description: "Provide custom types (newline delimited) if you don't want the default ones from https://www.conventionalcommits.org."
description: "Provide custom types (newline delimited) if you don't want the default ones from https://www.conventionalcommits.org. These are regex patterns auto-wrapped in `^ $`."
required: false
scopes:
description: 'Configure which scopes are allowed (newline delimited). These are regex patterns auto-wrapped in `^ $`.'
Expand Down
2 changes: 1 addition & 1 deletion src/validatePrTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default async function validatePrTitle(
raiseError(`No subject found in pull request title "${prTitle}".`);
}

if (!types.includes(result.type)) {
if (!types.some((type) => new RegExp(`^${type}$`).test(result.type))) {
raiseError(
`Unknown release type "${
result.type
Expand Down
80 changes: 80 additions & 0 deletions src/validatePrTitle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,86 @@ it('throws for PR titles with an unknown type', async () => {
);
});

describe('regex types', () => {
const headerPattern = /^([\w-]*)(?:\(([\w$.\-*/ ]*)\))?: (.*)$/;

it('allows a regex matching type', async () => {
await validatePrTitle('JIRA-123: Bar', {
types: ['JIRA-\\d+'],
headerPattern
});
});

it('can be used for dynamic Jira keys', async () => {
const inputs = ['JIRA-123', 'P-123', 'INT-31', 'CONF-0'];

for (let index = 0; index < inputs.length; index++) {
await validatePrTitle(`${inputs[index]}: did the thing`, {
types: ['[A-Z]+-\\d+'],
headerPattern
});
}
});

it('throws for PR titles without a type', async () => {
await expect(
validatePrTitle('Fix JIRA-123 bug', {
types: ['JIRA-\\d+'],
headerPattern
})
).rejects.toThrow(
'No release type found in pull request title "Fix JIRA-123 bug".'
);
});

it('throws for PR titles with only a type', async () => {
await expect(
validatePrTitle('JIRA-123:', {
types: ['JIRA-\\d+'],
headerPattern
})
).rejects.toThrow(
'No release type found in pull request title "JIRA-123:".'
);
});

it('throws for PR titles without a subject', async () => {
await expect(
validatePrTitle('JIRA-123: ', {
types: ['JIRA-\\d+'],
headerPattern
})
).rejects.toThrow('No subject found in pull request title "JIRA-123: ".');
});

it('throws for PR titles that do not match the regex', async () => {
await expect(
validatePrTitle('CONF-123: ', {
types: ['JIRA-\\d+'],
headerPattern
})
).rejects.toThrow('No subject found in pull request title "CONF-123: ".');
});

it('throws when an unknown type is detected for auto-wrapping regex', async () => {
await expect(
validatePrTitle('JIRA-123A: Bar', {
types: ['JIRA-\\d+'],
headerPattern
})
).rejects.toThrow(
'Unknown release type "JIRA-123A" found in pull request title "JIRA-123A: Bar". \n\nAvailable types:\n - JIRA-\\d+'
);
});

it('allows scopes when using a regex for the type', async () => {
await validatePrTitle('JIRA-123(core): Bar', {
types: ['JIRA-\\d+'],
headerPattern
});
});
});

describe('defined scopes', () => {
it('allows a missing scope by default', async () => {
await validatePrTitle('fix: Bar');
Expand Down