Skip to content

Commit

Permalink
馃敡 fix: updated messageJiraPrefixRegex to not match without ':' (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecarlo committed Jan 2, 2024
1 parent 249ef9b commit 12b9893
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@humankode/git-inject-jira-ticket",
"version": "0.0.5",
"version": "0.0.6",
"private": false,
"description": "A script for the prepare-commit-msg git hook that automatically injects a Jira ticket based off the jira ticket in the branch name",
"repository": "github:thecarlo/git-inject-jira-ticket",
Expand Down
2 changes: 1 addition & 1 deletion src/configuration/createDefaultConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const createDefaultConfiguration = (
},
messageConfiguration: {
capitalizeMessage: true,
messageJiraPrefixRegex: `^${jiraRegex}\\s*[:]?\\s*`,
messageJiraPrefixRegex: `^${jiraRegex}(?=\\s*:\\s*)\\s*:\\s*`,
messageJiraRegex: `${jiraRegex}`,
messageExtractRegex: `(?<=${jiraIssuePrefix}-[0-9]{${jiraTicketLength}}\\s*:\\s*)\\S.*`,
messageExample: `${jiraIssuePrefix}-1234`,
Expand Down
23 changes: 23 additions & 0 deletions src/functions/message/getTicketFromMessage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@ describe('getTicketFromMessage', () => {
});
});

it(`should return isTicketPrefixed=false for a Jira ticket without ':'`, () => {
const message = 'JIRA-1234';

const result = getTicketFromMessage(message, defaultConfig);

expect(result).toEqual({
isTicketInMessage: true,
isTicketPrefixed: false,
});
});

it(`should return isTicketPrefixed=true for a Jira ticket with spacing around ' : '`, () => {
const message = 'JIRA-1234 : foo';

const result = getTicketFromMessage(message, defaultConfig);

expect(result).toEqual({
isTicketInMessage: true,
isTicketPrefixed: true,
ticket: 'JIRA-1234',
});
});

it('should detect a valid Jira ticket in the message but not prefixed', () => {
const message = 'Implement caching JIRA-1234';

Expand Down

0 comments on commit 12b9893

Please sign in to comment.