Skip to content

Commit

Permalink
fix(parse): allow missing scope (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera authored Apr 14, 2023
1 parent c2ad900 commit 0c88c92
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/__tests__/__snapshots__/files.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file.
### Bug Fixes
* **build** eslint, jsdoc updates (#16) (d123453)
* missing semicolon (1f1x345)
"
`;
Expand All @@ -40,6 +41,7 @@ All notable changes to this project will be documented in this file.
### Bug Fixes
* **build** eslint, jsdoc updates (#16) (d123453)
* missing semicolon (1f1x345)
"
`;
Expand All @@ -64,6 +66,7 @@ All notable changes to this project will be documented in this file.
### Bug Fixes
* **build** eslint, jsdoc updates (#16) (d123453)
* missing semicolon (1f1x345)
"
`;
Expand All @@ -86,6 +89,7 @@ All notable changes to this project will be documented in this file.
### Bug Fixes
* **build** eslint, jsdoc updates (#16) (d123453)
* missing semicolon (1f1x345)
"
`;
Expand Down
56 changes: 49 additions & 7 deletions src/__tests__/__snapshots__/parse.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

exports[`Parse should format a changelog commit message: formatChangelogMessages 1`] = `
{
"feat": "* **dolor** issues/20 sit enhancements (1f12345)",
"general": "* Initial commit (1f12345)",
"refactor": "* **file** lorem updates ([#8](https://localhost/lorem/ipsum/prmock/8)) ([1f12345](https://localhost/lorem/ipsum/commitsmock/1f12345b597123453031234555b6d25574ccacee))",
"feat": "* **dolor** issues/20 sit enhancements (1f72345)",
"fix": "* missing semicolon (1f12p45)",
"general": "* Initial commit (1f12s45)",
"refactor": "* **file** lorem updates ([#8](https://localhost/lorem/ipsum/prmock/8)) ([1f1x345](https://localhost/lorem/ipsum/commitsmock/1f1x345b597123453031234555b6d25574ccacee))",
}
`;

Expand Down Expand Up @@ -57,6 +58,7 @@ exports[`Parse should parse a commit listing using conventional commit types and
"fix": {
"commits": [
"* **build** npm packages (#18) (6112345)",
"* missing semicolon (1f1x345)",
"* **build** eslint, jsdoc updates (#16) (d123453)",
],
"description": "A bug fix",
Expand Down Expand Up @@ -105,6 +107,7 @@ exports[`Parse should parse a commit listing using conventional commit types and
"fix": {
"commits": [
"* **build** npm packages (#18) (6112345)",
"* missing semicolon (1f1x345)",
"* **build** eslint, jsdoc updates (#16) (d123453)",
],
"description": "A bug fix",
Expand Down Expand Up @@ -154,6 +157,7 @@ exports[`Parse should parse a commit listing using conventional commit types and
"fix": {
"commits": [
"* **build** npm packages (#18) (6112345)",
"* missing semicolon (1f1x345)",
"* **build** eslint, jsdoc updates (#16) (d123453)",
],
"description": "A bug fix",
Expand Down Expand Up @@ -210,6 +214,7 @@ exports[`Parse should parse a commit listing using conventional commit types and
"fix": {
"commits": [
"* **build** npm packages ([#18](https://localhost/lorem/ipsum/dolor/18)) ([6112345](https://localhost/lorem/ipsum/sit/611234511234543c39c1234536dc01234521549c))",
"* missing semicolon ([1f1x345](https://localhost/lorem/ipsum/sit/1f1x345b597123453031234555b6dl2401ccacee))",
"* **build** eslint, jsdoc updates ([#16](https://localhost/lorem/ipsum/dolor/16)) ([d123453](https://localhost/lorem/ipsum/sit/d1234537b5e94a6512345xeb96503312345x18d2))",
],
"description": "A bug fix",
Expand All @@ -232,7 +237,7 @@ exports[`Parse should parse a commit listing using conventional commit types and
{
"commits": {
"bump": "minor",
"weight": 11.899999999999999,
"weight": 12,
},
"default": {
"bump": "patch",
Expand All @@ -245,23 +250,31 @@ exports[`Parse should parse a commit message: parseCommitMessages 1`] = `
{
"feat": {
"description": "issues/20 sit enhancements",
"hash": "1f12345b597123453031234555b6d25574ccacee",
"hash": "1f72345b597123453031234555b6d25574ccacee",
"prNumber": "",
"scope": "dolor",
"type": "feat",
"typeScope": "feat(dolor)",
},
"fix": {
"description": "missing semicolon",
"hash": "1f12p45b597123453031234555b6dl2401ccacee",
"prNumber": "",
"scope": undefined,
"type": "fix",
"typeScope": "fix",
},
"general": {
"description": "Initial commit",
"hash": "1f12345b597123453031234555b6d25574ccacee",
"hash": "1f12s45b597123453031234555b6d25574ccacee",
"prNumber": "",
"scope": undefined,
"type": "general",
"typeScope": undefined,
},
"refactor": {
"description": "lorem updates ",
"hash": "1f12345b597123453031234555b6d25574ccacee",
"hash": "1f1x345b597123453031234555b6d25574ccacee",
"prNumber": "8",
"scope": "file",
"type": "refactor",
Expand All @@ -270,6 +283,35 @@ exports[`Parse should parse a commit message: parseCommitMessages 1`] = `
}
`;

exports[`Parse should parse a non-conforming commit message: parseNonConformingCommitMessages 1`] = `
{
"misplacedScope": {
"description": "missing fix: semicolon",
"hash": "1f12p45b597123453031234555b6dl2401ccacee",
"prNumber": "",
"scope": undefined,
"type": "general",
"typeScope": undefined,
},
"noScopeNoSemicolon": {
"description": "refactor lorem updates ",
"hash": "1f1x345b597123453031234555b6d25574ccacee",
"prNumber": "8",
"scope": undefined,
"type": "general",
"typeScope": undefined,
},
"noTypeWithScope": {
"description": "(dolor): issues/20 sit enhancements",
"hash": "1f72345b597123453031234555b6d25574ccacee",
"prNumber": "",
"scope": undefined,
"type": "general",
"typeScope": undefined,
},
}
`;

exports[`Parse should return commit types: getCommitType 1`] = `
{
"build": {
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('Files', () => {
1f12345b597123453031234555b6d25574ccacee refactor(file): lorem updates (#8)
53a12345479ef91123456e921234548ac4123450 feat(dolor): issues/20 sit enhancements (#8)
d1234537b5e94a6512345xeb96503312345x18d2 fix(build): eslint, jsdoc updates (#16)
1f1x345b597123453031234555b6dl2401ccacee fix: missing semicolon
e5c456ea12345vv4610fa4aff7812345ss31b1e2 chore(build): npm packages (#15)
12345dd312345d421231231312312345dca11235 Initial commit
`;
Expand All @@ -33,6 +34,7 @@ describe('Files', () => {
LASTg45b597123453031234555b6d25574ccacee refactor(file): lorem updates (#8)
53a12345479ef91123456e921234548ac4123450 feat(dolor): issues/20 sit enhancements (#8)
d1234537b5e94a6512345xeb96503312345x18d2 fix(build): eslint, jsdoc updates (#16)
1f1x345b597123453031234555b6dl2401ccacee fix: missing semicolon
e5c456ea12345vv4610fa4aff7812345ss31b1e2 chore(build): npm packages (#15)
FIRSTdd312345d421231231312312345dca11235 Initial-like commit
`;
Expand Down
33 changes: 25 additions & 8 deletions src/__tests__/parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,36 @@ describe('Parse', () => {
});

it('should parse a commit message', () => {
const commitMessageRefactor = '1f12345b597123453031234555b6d25574ccacee refactor(file): lorem updates (#8)';
const commitMessageFeature = '1f12345b597123453031234555b6d25574ccacee feat(dolor): issues/20 sit enhancements';
const commitMessageNonCC = '1f12345b597123453031234555b6d25574ccacee Initial commit';
const commitMessageRefactor = '1f1x345b597123453031234555b6d25574ccacee refactor(file): lorem updates (#8)';
const commitMessageFeature = '1f72345b597123453031234555b6d25574ccacee feat(dolor): issues/20 sit enhancements';
const commitMessageNoScope = '1f12p45b597123453031234555b6dl2401ccacee fix: missing semicolon';
const commitMessageNonCC = '1f12s45b597123453031234555b6d25574ccacee Initial commit';

expect({
refactor: parseCommitMessage(commitMessageRefactor),
feat: parseCommitMessage(commitMessageFeature),
general: parseCommitMessage(commitMessageNonCC)
general: parseCommitMessage(commitMessageNonCC),
fix: parseCommitMessage(commitMessageNoScope)
}).toMatchSnapshot('parseCommitMessages');
});

it('should parse a non-conforming commit message', () => {
const commitMessageNoScopeNoSemicolon = '1f1x345b597123453031234555b6d25574ccacee refactor lorem updates (#8)';
const commitMessageNoTypeWithScope = '1f72345b597123453031234555b6d25574ccacee (dolor): issues/20 sit enhancements';
const commitMessageMisplacedScope = '1f12p45b597123453031234555b6dl2401ccacee missing fix: semicolon';

expect({
noScopeNoSemicolon: parseCommitMessage(commitMessageNoScopeNoSemicolon),
noTypeWithScope: parseCommitMessage(commitMessageNoTypeWithScope),
misplacedScope: parseCommitMessage(commitMessageMisplacedScope)
}).toMatchSnapshot('parseNonConformingCommitMessages');
});

it('should format a changelog commit message', () => {
const commitMessageRefactor = '1f12345b597123453031234555b6d25574ccacee refactor(file): lorem updates (#8)';
const commitMessageFeature = '1f12345b597123453031234555b6d25574ccacee feat(dolor): issues/20 sit enhancements';
const commitMessageNonCC = '1f12345b597123453031234555b6d25574ccacee Initial commit';
const commitMessageRefactor = '1f1x345b597123453031234555b6d25574ccacee refactor(file): lorem updates (#8)';
const commitMessageFeature = '1f72345b597123453031234555b6d25574ccacee feat(dolor): issues/20 sit enhancements';
const commitMessageNoScope = '1f12p45b597123453031234555b6dl2401ccacee fix: missing semicolon';
const commitMessageNonCC = '1f12s45b597123453031234555b6d25574ccacee Initial commit';

expect({
refactor: formatChangelogMessage(
Expand All @@ -66,7 +81,8 @@ describe('Parse', () => {
}
),
feat: formatChangelogMessage(parseCommitMessage(commitMessageFeature)),
general: formatChangelogMessage(parseCommitMessage(commitMessageNonCC))
general: formatChangelogMessage(parseCommitMessage(commitMessageNonCC)),
fix: formatChangelogMessage(parseCommitMessage(commitMessageNoScope))
}).toMatchSnapshot('formatChangelogMessages');
});

Expand All @@ -75,6 +91,7 @@ describe('Parse', () => {
1f12345b597123453031234555b6d25574ccacee refactor(file): lorem updates (#8)
53a12345479ef91123456e921234548ac4123450 feat(dolor): issues/20 sit enhancements (#8)
611234511234543c39c1234536dc01234521549c fix(build): npm packages (#18)
1f1x345b597123453031234555b6dl2401ccacee fix: missing semicolon
fe7d312345xe604d8328d025612345925123457b build(deps): bump codecov/codecov-action from 1.1.0 to 1.1.1 (#19)
d1234537b5e94a6512345xeb96503312345x18d2 fix(build): eslint, jsdoc updates (#16)
e5c456ea12345vv4610fa4aff7812345ss31b1e2 chore(build): npm packages (#15)
Expand Down
4 changes: 2 additions & 2 deletions src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ const parseCommitMessage = (message, { getCommitType: getAliasCommitType = getCo
hash,
typeScope,
type: commitType?.[type]?.value,
scope: scope.split(')')[0],
scope: scope.split(')')[0] || undefined,
description: description,
prNumber: (partialPr.join('(#').trim() || '').replace(/\D/g, '')
};

if (!output.typeScope || !output.type || !output.scope) {
if (!output.type || (output.type && !descriptionEtAll?.length)) {
const [hash, ...descriptionEtAll] = message.trim().split(/\s/);
const [description, ...partialPr] = descriptionEtAll.join(' ').trim().split(/\(#/);

Expand Down

0 comments on commit 0c88c92

Please sign in to comment.