Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add possibility to set empty footerPrefix #74

Merged
merged 1 commit into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Here are the options you can set in your `.cz-config.js`:
* **appendBranchNameToCommitMessage**: If you use `cz-customizable` with `cz-customizable-ghooks`, you can get the branch name automatically appended to the commit message. This is done by a commit hook on `cz-customizable-ghooks`. This option has been added on `cz-customizable-ghooks`, v1.3.0. Default value is `true`.
* **ticketNumberPrefix**: {string, default 'ISSUES CLOSED:'}: Set custom prefix for footer ticker number.
* **breakingPrefix**: {string, default 'BREAKING CHANGE:'}: Set a custom prefix for the breaking change block in commit messages.
* **footerPrefix**: {string, default 'ISSUES CLOSED:'}: Set a custom prefix for the footer block in commit messages.
* **footerPrefix**: {string, default 'ISSUES CLOSED:'}: Set a custom prefix for the footer block in commit messages. Set to empty string to remove prefix.

## Related tools
- (https://github.com/commitizen/cz-cli)
Expand Down
10 changes: 8 additions & 2 deletions buildCommit.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ function addType(type, config) {
return _.trim(`${prefix}${type}${suffix}`);
}

function addFooter(footer, config) {
if (config && config.footerPrefix === '') return `\n\n${footer}`;

const footerPrefix = config && config.footerPrefix ? config.footerPrefix : 'ISSUES CLOSED:';
return `\n\n${footerPrefix} ${footer}`;
}

module.exports = function buildCommit(answers, config) {
const wrapOptions = {
trim: true,
Expand Down Expand Up @@ -80,8 +87,7 @@ module.exports = function buildCommit(answers, config) {
result += `\n\n${breakingPrefix}\n${breaking}`;
}
if (footer) {
const footerPrefix = config && config.footerPrefix ? config.footerPrefix : 'ISSUES CLOSED:';
result += `\n\n${footerPrefix} ${footer}`;
result += addFooter(footer, config);
}

return escapeSpecialChars(result);
Expand Down
38 changes: 38 additions & 0 deletions spec/czCustomizableSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,44 @@ describe('cz-customizable', () => {
);
});

it('should call commit() function with custom footer prefix set to empty string', () => {
const answers = {
confirmCommit: 'yes',
type: 'feat',
scope: 'myScope',
subject: 'create a new cool feature',
breaking: 'breaking',
footer: 'my footer',
};

// eslint-disable-next-line no-underscore-dangle
module.__set__({
log: {
info() {},
},

readConfigFile() {
return {
types: [{ value: 'feat', name: 'feat: my feat' }],
scopes: [{ name: 'myScope' }],
scopeOverrides: {
fix: [{ name: 'fixOverride' }],
},
allowCustomScopes: true,
allowBreakingChanges: ['feat'],
footerPrefix: '',
};
},
});

const mockCz = getMockedCz(answers);
module.prompter(mockCz, commit);

expect(commit).toHaveBeenCalledWith(
'feat(myScope): create a new cool feature\n\nBREAKING CHANGE:\nbreaking\n\nmy footer'
);
});

it('should call commit() function with ticket number', () => {
const answers = {
confirmCommit: 'yes',
Expand Down