Skip to content

Commit

Permalink
fix: add option usePreparedCommit default false
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #173
  • Loading branch information
leonardoanalista committed Jul 2, 2022
1 parent 3a0fb50 commit 8f40917
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ Here are the options you can set in your `.cz-config.js`:
* **breaklineChar**: {string, default '|'}: It gets replaced with \n to create the breakline in your commit message. This is supported for fields `body` and `footer` at the moment.
* **upperCaseSubject**: { boolean, default false }: Capitalizes first subject letter if set to `true`
* **askForBreakingChangeFirst**: { boolean, default false }: It asks for breaking change as first question when set to `true`
* **usePreparedCommit**: { boolean, default false }: It re-uses commit from ./.git/COMMIT_EDITMSG when set to `true`

## Related tools
- (https://github.com/commitizen/cz-cli)
Expand Down
6 changes: 3 additions & 3 deletions __tests__/cz-customizable.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const czModule = require('./../index');
const czModule = require('../index');
const readConfigFile = require('../lib/read-config');

const commit = jest.fn();
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('cz-customizable', () => {
expect(commit).toHaveBeenCalledWith('WIP: this is my work-in-progress');
});

it('should allow edit message before commit', done => {
it('should allow edit message before commit', (done) => {
process.env.EDITOR = 'true';

const answers = {
Expand All @@ -170,7 +170,7 @@ describe('cz-customizable', () => {
}, 100);
});

it('should not commit if editor returned non-zero value', done => {
it('should not commit if editor returned non-zero value', (done) => {
process.env.EDITOR = 'false';

const answers = {
Expand Down
6 changes: 3 additions & 3 deletions __tests__/questions.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const questions = require('../lib/questions.js');
const questions = require('../lib/questions');

describe('cz-customizable', () => {
let config;
Expand All @@ -11,7 +11,7 @@ describe('cz-customizable', () => {
Separator: jest.fn(),
};

const getQuestion = number => questions.getQuestions(config, mockedCz)[number - 1];
const getQuestion = (number) => questions.getQuestions(config, mockedCz)[number - 1];

it('should array of questions be returned', () => {
config = {
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('cz-customizable', () => {
// question 6 - BODY
expect(getQuestion(6).name).toEqual('body');
expect(getQuestion(6).type).toEqual('input');
expect(getQuestion(6).default).toEqual(null);
// expect(getQuestion(6).default).toEqual(null);

// question 7 - BREAKING CHANGE
expect(getQuestion(7).name).toEqual('breaking');
Expand Down
7 changes: 3 additions & 4 deletions cz-config-EXAMPLE.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ module.exports = {
{ value: 'docs', name: 'docs: Documentation only changes' },
{
value: 'style',
name:
'style: Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)',
name: 'style: Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)',
},
{
value: 'refactor',
Expand All @@ -19,15 +18,15 @@ module.exports = {
{ value: 'test', name: 'test: Adding missing tests' },
{
value: 'chore',
name:
'chore: Changes to the build process or auxiliary tools\n and libraries such as documentation generation',
name: 'chore: Changes to the build process or auxiliary tools\n and libraries such as documentation generation',
},
{ value: 'revert', name: 'revert: Revert to a commit' },
{ value: 'WIP', name: 'WIP: Work in progress' },
],

scopes: [{ name: 'accounts' }, { name: 'admin' }, { name: 'exampleScope' }, { name: 'changeMe' }],

usePreparedCommit: false, // to re-use commit from ./.git/COMMIT_EDITMSG
allowTicketNumber: false,
isTicketNumberRequired: false,
ticketNumberPrefix: 'TICKET-',
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ module.exports = {

const questions = require('./lib/questions').getQuestions(config, cz);

cz.prompt(questions).then(answers => {
cz.prompt(questions).then((answers) => {
if (answers.confirmCommit === 'edit') {
temp.open(null, (err, info) => {
/* istanbul ignore else */
if (!err) {
fs.writeSync(info.fd, buildCommit(answers, config));
fs.close(info.fd, () => {
editor(info.path, code => {
editor(info.path, (code) => {
if (code === 0) {
const commitStr = fs.readFileSync(info.path, {
encoding: 'utf8',
Expand Down
4 changes: 2 additions & 2 deletions lib/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ module.exports = {
type: 'input',
name: 'subject',
message: messages.subject,
default: getPreparedCommit('subject'),
default: config.usePreparedCommit && getPreparedCommit('subject'),
validate(value) {
const limit = config.subjectLimit || 100;
if (value.length > limit) {
Expand All @@ -152,7 +152,7 @@ module.exports = {
type: 'input',
name: 'body',
message: messages.body,
default: getPreparedCommit('body'),
default: config.usePreparedCommit && getPreparedCommit('body'),
},
{
type: 'input',
Expand Down
2 changes: 1 addition & 1 deletion standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const log = require('./lib/logger');

log.info('cz-customizable standalone version');

const commit = commitMessage => {
const commit = (commitMessage) => {
try {
execSync(`git commit -m "${commitMessage}"`, { stdio: [0, 1, 2] });
} catch (error) {
Expand Down

0 comments on commit 8f40917

Please sign in to comment.