-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update this module to work with latest commitizen v2.8.1
BREAKING CHANGE: you need to update commitizen to v2.8.1, which uses inquireJs v1.0.2. From now on commitizen uses promise for the commit callback. As a user of this adapter, all you have to do is update commitizen. ISSUES CLOSED: 30
- Loading branch information
Leonardo Correa
committed
May 11, 2016
1 parent
cf6f8e8
commit 35ab0b7
Showing
7 changed files
with
389 additions
and
358 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
'use strict'; | ||
|
||
|
||
var wrap = require('word-wrap'); | ||
|
||
|
||
module.exports = function buildCommit(answers) { | ||
|
||
var maxLineWidth = 100; | ||
|
||
var wrapOptions = { | ||
trim: true, | ||
newline: '\n', | ||
indent:'', | ||
width: maxLineWidth | ||
}; | ||
|
||
function addScope(scope) { | ||
if (!scope) return ': '; //it could be type === WIP. So there is no scope | ||
|
||
return '(' + scope.trim() + '): '; | ||
} | ||
|
||
function addSubject(subject) { | ||
return subject.trim(); | ||
} | ||
|
||
function escapeSpecialChars(result) { | ||
var specialChars = ['\`']; | ||
|
||
specialChars.map(function (item) { | ||
// For some strange reason, we have to pass additional '\' slash to commitizen. Total slashes are 4. | ||
// If user types "feat: `string`", the commit preview should show "feat: `\\string\\`". | ||
// Don't worry. The git log will be "feat: `string`" | ||
result = result.replace(new RegExp(item, 'g'), '\\\\`'); | ||
}); | ||
return result; | ||
} | ||
|
||
// Hard limit this line | ||
var head = (answers.type + addScope(answers.scope) + addSubject(answers.subject)).slice(0, maxLineWidth); | ||
|
||
// Wrap these lines at 100 characters | ||
var body = wrap(answers.body, wrapOptions) || ''; | ||
body = body.split('|').join('\n'); | ||
|
||
var breaking = wrap(answers.breaking, wrapOptions); | ||
var footer = wrap(answers.footer, wrapOptions); | ||
|
||
var result = head; | ||
if (body) { | ||
result += '\n\n' + body; | ||
} | ||
if (breaking) { | ||
result += '\n\n' + 'BREAKING CHANGE:\n' + breaking; | ||
} | ||
if (footer) { | ||
result += '\n\nISSUES CLOSED: ' + footer; | ||
} | ||
|
||
return escapeSpecialChars(result); | ||
}; |
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
Oops, something went wrong.