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 @@ -61,10 +61,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 @@ -8,7 +8,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
4 changes: 2 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52676,11 +52676,11 @@ 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
}" found in pull request title "${prTitle}". \n\n${printAvailableTypes()}`
}" found in pull request title "${prTitle}".\n\n${printAvailableTypes()}`
);
}

Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
"axios": "^1.8.2",
"conventional-commit-types": "^3.0.0",
"conventional-commits-parser": "^6.2.0",
"typescript": "^5.9.2",
"vitest": "^3.2.4"
"typescript": "^5.9.2"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^28.0.6",
Expand All @@ -40,7 +39,8 @@
"eslint-config-molindo": "8.0.0",
"globals": "^16.3.0",
"prettier": "^3.6.2",
"rollup": "^4.46.2"
"rollup": "^4.46.2",
"vitest": "^3.2.4"
},
"engines": {
"node": "^24.0.0"
Expand Down
4 changes: 2 additions & 2 deletions src/validatePrTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ 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
}" found in pull request title "${prTitle}". \n\n${printAvailableTypes()}`
}" found in pull request title "${prTitle}".\n\n${printAvailableTypes()}`
);
}

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 @@
);
});

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(

Check failure on line 104 in src/validatePrTitle.test.js

View workflow job for this annotation

GitHub Actions / main

src/validatePrTitle.test.js > regex types > throws when an unknown type is detected for auto-wrapping regex

AssertionError: expected [Function] to throw error including 'Unknown release type "JIRA-123A" foun…' but got 'Unknown release type "JIRA-123A" foun…' - Expected + Received - Unknown release type "JIRA-123A" found in pull request title "JIRA-123A: Bar". + Unknown release type "JIRA-123A" found in pull request title "JIRA-123A: Bar". Available types: - JIRA-\d+ ❯ src/validatePrTitle.test.js:104:5
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
Loading