Skip to content

Commit

Permalink
refactor(parse): explicit undefined instead of empty string (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera committed Jan 29, 2024
1 parent aab6323 commit e4365d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/__snapshots__/parse.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ exports[`Parse should parse a commit message: parseCommitMessages 1`] = `
"description": "issues/20 sit enhancements",
"hash": "1f72345b597123453031234555b6d25574ccacee",
"isBreaking": false,
"prNumber": "",
"prNumber": undefined,
"scope": "dolor",
"type": "feat",
"typeScope": "feat(dolor)",
Expand All @@ -272,7 +272,7 @@ exports[`Parse should parse a commit message: parseCommitMessages 1`] = `
"description": "missing semicolon",
"hash": "1f12p45b597123453031234555b6dl2401ccacee",
"isBreaking": false,
"prNumber": "",
"prNumber": undefined,
"scope": undefined,
"type": "fix",
"typeScope": "fix",
Expand Down
12 changes: 6 additions & 6 deletions src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ const parseCommitMessage = (

const [hashTypeScope, ...descriptionEtAll] = message.trim().split(/:/);
const [description, ...partialPr] = descriptionEtAll.join(' ').trim().split(/\(#/);
const [hash, typeScope = ''] = hashTypeScope.replace(/!$/, '').trim().split(/\s/);
const [type, scope = ''] = typeScope.split('(');
const [hash, ...typeScope] = hashTypeScope.replace(/!$/, '').trim().split(/\s/);
const [type, scope = ''] = typeScope.join(' ').trim().split('(');

output = {
hash,
typeScope,
type: commitType?.[type]?.value,
typeScope: typeScope.join(' ').trim() || undefined,
type: commitType?.[type]?.value || undefined,
scope: scope.split(')')[0] || undefined,
description: description.trim(),
prNumber: (partialPr.join('(#').trim() || '').replace(/\D/g, ''),
description: description.trim() || undefined,
prNumber: (partialPr.join('(#').trim() || '').replace(/\D/g, '') || undefined,
isBreaking
};

Expand Down

0 comments on commit e4365d7

Please sign in to comment.