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: adds "ticketNumberSuffix" and "ticketNumberPosition" config options #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ Here are the options you can set in your `.cz-config.js`:
* **skipQuestions**: {Array of Strings: default none}. List of questions you want to skip. Eg.: ['body', 'footer'].
* **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.
* **ticketNumberSuffix**: {string, default ' '}: Set custom prefix for footer ticker number.
* **ticketNumberPosition**: {string <small>[ 'first', 'standard' or 'last' ]</small>, default none}: Set custom placement for footer ticker number.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the difference between none and standard. Maybe default could be standard?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"standard" is default value here, none here means undefined. I saw this wording on lines 124, 125 of this file. And got me confused at first too...

* **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. Set to empty string to remove prefix.
* **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.
Expand Down
57 changes: 46 additions & 11 deletions buildCommit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@ const defaultMaxLineWidth = 100;
const defaultBreaklineChar = '|';

const addTicketNumber = (ticketNumber, config) => {
let result;

if (!ticketNumber) {
return '';
}

result = ticketNumber.trim();

if (config.ticketNumberPrefix) {
return `${config.ticketNumberPrefix + ticketNumber.trim()} `;
result = `${config.ticketNumberPrefix}${result}`;
}

if (config.ticketNumberSuffix || config.ticketNumberSuffix === '') {
result = `${result}${config.ticketNumberSuffix}`;
} else {
result = `${result} `;
}
return `${ticketNumber.trim()} `;

return result;
};

const addScope = (scope, config) => {
Expand Down Expand Up @@ -67,15 +79,38 @@ module.exports = (answers, config) => {
indent: '',
width: defaultMaxLineWidth,
};

// Hard limit this line
// eslint-disable-next-line max-len
const head = (
addType(answers.type, config) +
addScope(answers.scope, config) +
addTicketNumber(answers.ticketNumber, config) +
addSubject(answers.subject)
).slice(0, defaultMaxLineWidth);
let head;

switch (config.ticketNumberPosition) {
case 'first':
// Hard limit this line
head = (
addTicketNumber(answers.ticketNumber, config) +
addType(answers.type, config) +
addScope(answers.scope, config) +
addSubject(answers.subject)
).slice(0, defaultMaxLineWidth);
break;
case 'last':
// Hard limit this line
head = (
addType(answers.type, config) +
addScope(answers.scope, config) +
addSubject(answers.subject) +
addTicketNumber(answers.ticketNumber, config)
).slice(0, defaultMaxLineWidth);
break;
case 'standard':
default:
// Hard limit this line
head = (
addType(answers.type, config) +
addScope(answers.scope, config) +
addTicketNumber(answers.ticketNumber, config) +
addSubject(answers.subject)
).slice(0, defaultMaxLineWidth);
break;
}

// Wrap these lines at 100 characters
let body = wrap(answers.body, wrapOptions) || '';
Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ declare module "cz-customizable" {
skipQuestions?: string[];
appendBranchNameToCommitMessage?: boolean;
ticketNumberPrefix?: string;
ticketNumberSuffix?: string;
ticketNumberPosition?: string;
breakingPrefix?: string;
footerPrefix?: string;
subjectLimit?: number;
Expand Down
58 changes: 58 additions & 0 deletions spec/buildCommitSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,62 @@ line 2`;
expect(buildCommit(answersNoScope, options)).toEqual(expecteMessage);
});
});

describe('with ticketNumberSuffix', () => {
it('should be visible', () => {
const answersTicketNumberSuffix = {
...answers,
ticketNumber: '12345',
};
const options = {
allowTicketNumber: true,
ticketNumberSuffix: '@@@ ',
};

expect(buildCommit(answersTicketNumberSuffix, options)).toEqual('feat(app): 12345@@@ this is a new feature');
});
});

describe('with ticketNumberPosition', () => {
it('should be same', () => {
const answersTicketNumberSuffix = {
...answers,
ticketNumber: '12345',
};
const options = {
allowTicketNumber: true,
ticketNumberPosition: 'standard',
};

expect(buildCommit(answersTicketNumberSuffix, options)).toEqual('feat(app): 12345 this is a new feature');
});

it('should be "first"', () => {
const answersTicketNumberSuffix = {
...answers,
ticketNumber: '12345',
};
const options = {
allowTicketNumber: true,
ticketNumberPosition: 'first',
};

expect(buildCommit(answersTicketNumberSuffix, options)).toEqual('12345 feat(app): this is a new feature');
});

it('should be "last"', () => {
const answersTicketNumberSuffix = {
...answers,
ticketNumber: '12345',
};
const options = {
allowTicketNumber: true,
ticketNumberPrefix: ' ',
ticketNumberSuffix: '',
ticketNumberPosition: 'last',
};

expect(buildCommit(answersTicketNumberSuffix, options)).toEqual('feat(app): this is a new feature 12345');
});
});
});