This repository has been archived by the owner on Jun 16, 2021. It is now read-only.
forked from streamich/git-cz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create formatMessage() function
- Loading branch information
Showing
4 changed files
with
62 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const wrap = require('word-wrap'); | ||
|
||
const MAX_LINE_WIDTH = 72; | ||
|
||
const makeAffectsLine = function (answers) { | ||
const selectedPackages = answers.packages; | ||
|
||
if (selectedPackages && selectedPackages.length) { | ||
return `\naffects: ${selectedPackages.join(', ')}`; | ||
} | ||
|
||
return ''; | ||
}; | ||
|
||
const formatCommitMessage = (state) => { | ||
const {config, answers} = state; | ||
const wrapOptions = { | ||
indent: '', | ||
trim: true, | ||
width: MAX_LINE_WIDTH | ||
}; | ||
|
||
const emoji = config.types[answers.type].emoji; | ||
const emojiPrefix = emoji ? emoji + ' ' : ''; | ||
|
||
let scope = ''; | ||
|
||
if (answers.scope && (answers.scope !== 'none')) { | ||
scope = `(${answers.scope})`; | ||
} | ||
|
||
const head = answers.type + scope + ': ' + emojiPrefix + answers.subject; | ||
const affectsLine = makeAffectsLine(answers); | ||
|
||
// Wrap these lines at MAX_LINE_WIDTH character | ||
const body = wrap(answers.body + affectsLine, wrapOptions); | ||
const breaking = wrap(answers.breaking, wrapOptions); | ||
const issues = wrap(answers.issues, wrapOptions); | ||
|
||
let msg = head; | ||
|
||
if (body) { | ||
msg += '\n\n' + body; | ||
} | ||
|
||
if (breaking) { | ||
msg += '\n\nBREAKING CHANGE: ' + breaking; | ||
} | ||
|
||
if (issues) { | ||
msg += '\n\nIssues: ' + issues; | ||
} | ||
|
||
return msg; | ||
}; | ||
|
||
module.exports = formatCommitMessage; |