Skip to content

Commit

Permalink
fix(parse): empty summary, message (#115)
Browse files Browse the repository at this point in the history
* parse, fallback to full hash if desc empty
* testing, non-conforming checks
  • Loading branch information
cdcabrera committed Jan 29, 2024
1 parent e4365d7 commit aab697e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
38 changes: 38 additions & 0 deletions src/__tests__/__snapshots__/parse.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ exports[`Parse should format a changelog commit message: formatChangelogMessages
}
`;

exports[`Parse should format a non-conforming changelog commit message: formatChangelogMessagesNonConformingCommitMessages 1`] = `
{
"empty": "* 1f1x345b597123453031234555b6d25574ccacee (1f1x345)",
"emptyPR": "* 1f1x345b597123453031234555b6d25574ccacee (#9) (1f1x345)",
"madeUpType": "* ref: lorem updates (#8) (1f1x345)",
"misplacedScope": "* missing fix: semicolon (1f12p45)",
"noScopeNoSemicolon": "* refactor lorem updates (#8) (1f1x345)",
"noTypeWithScope": "* (dolor): issues/20 sit enhancements (1f72345)",
}
`;

exports[`Parse should get the first, last commits: first and last, no release commit 1`] = `
{
"first": null,
Expand Down Expand Up @@ -300,6 +311,33 @@ exports[`Parse should parse a commit message: parseCommitMessages 1`] = `

exports[`Parse should parse a non-conforming commit message: parseNonConformingCommitMessages 1`] = `
{
"empty": {
"description": "",
"hash": "1f1x345b597123453031234555b6d25574ccacee",
"isBreaking": false,
"prNumber": "",
"scope": undefined,
"type": "general",
"typeScope": undefined,
},
"emptyPR": {
"description": "",
"hash": "1f1x345b597123453031234555b6d25574ccacee",
"isBreaking": false,
"prNumber": "9",
"scope": undefined,
"type": "general",
"typeScope": undefined,
},
"madeUpType": {
"description": "ref: lorem updates",
"hash": "1f1x345b597123453031234555b6d25574ccacee",
"isBreaking": false,
"prNumber": "8",
"scope": undefined,
"type": "general",
"typeScope": undefined,
},
"misplacedScope": {
"description": "missing fix: semicolon",
"hash": "1f12p45b597123453031234555b6dl2401ccacee",
Expand Down
24 changes: 24 additions & 0 deletions src/__tests__/parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,17 @@ describe('Parse', () => {
});

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

expect({
empty: parseCommitMessage({ message: commitMessageEmpty }),
emptyPR: parseCommitMessage({ message: commitMessageEmptyPR }),
madeUpType: parseCommitMessage({ message: commitMessageMadeUpType }),
noScopeNoSemicolon: parseCommitMessage({ message: commitMessageNoScopeNoSemicolon }),
noTypeWithScope: parseCommitMessage({ message: commitMessageNoTypeWithScope }),
misplacedScope: parseCommitMessage({ message: commitMessageMisplacedScope })
Expand Down Expand Up @@ -89,6 +95,24 @@ describe('Parse', () => {
}).toMatchSnapshot('formatChangelogMessages');
});

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

expect({
empty: formatChangelogMessage(parseCommitMessage({ message: commitMessageEmpty })),
emptyPR: formatChangelogMessage(parseCommitMessage({ message: commitMessageEmptyPR })),
madeUpType: formatChangelogMessage(parseCommitMessage({ message: commitMessageMadeUpType })),
noScopeNoSemicolon: formatChangelogMessage(parseCommitMessage({ message: commitMessageNoScopeNoSemicolon })),
noTypeWithScope: formatChangelogMessage(parseCommitMessage({ message: commitMessageNoTypeWithScope })),
misplacedScope: formatChangelogMessage(parseCommitMessage({ message: commitMessageMisplacedScope }))
}).toMatchSnapshot('formatChangelogMessagesNonConformingCommitMessages');
});

it('should parse a commit listing using conventional commit types', () => {
const commitLog = [
{ commit: '1f12345b597123453031234555b6d25574ccacee refactor(file): lorem updates (#8)' },
Expand Down
2 changes: 1 addition & 1 deletion src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const formatChangelogMessage = (
updatedHash = `([${hash.substring(0, 7)}](${new URL(hash, commitUrl).href}))`;
}

output = `* ${updatedBreaking}${updatedScope} ${description} ${updatedPr} ${updatedHash}`;
output = `* ${updatedBreaking}${updatedScope} ${description || hash} ${updatedPr} ${updatedHash}`;

return output;
};
Expand Down

0 comments on commit aab697e

Please sign in to comment.