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(cz-customizable): added footer ticket number suffix #237

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
1 change: 1 addition & 0 deletions .cz-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = {
allowTicketNumber: false,
isTicketNumberRequired: false,
ticketNumberPrefix: 'TICKET-',
ticketNumberSuffix:'',
ticketNumberRegExp: '\\d{1,5}',

// it needs to match the value for field type. Eg.: 'fix'
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ Here are the options you can set in your `.cz-config.js`:
* **skipEmptyScopes**: {boolean, default false}: If a chosen type has no scopes declared, skip the scope question
* **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 suffix 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. 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
27 changes: 27 additions & 0 deletions __tests__/cz-customizable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,31 @@ describe('cz-customizable', () => {
czModule.prompter(mockCz, commit);
expect(commit).toHaveBeenCalledWith('feat: create a new cool feature');
});

it('should call commit() function with ticket number and prefix and suffix', () => {
readConfigFile.mockReturnValue({
types: [{ value: 'feat', name: 'feat: my feat' }],
scopes: [{ name: 'myScope' }],
scopeOverrides: {
fix: [{ name: 'fixOverride' }],
},
allowCustomScopes: true,
allowBreakingChanges: ['feat'],
breakingPrefix: 'WARNING:',
ticketNumberPrefix: '[TICKET-',
ticketNumberSuffix: ']',
});

const answers = {
confirmCommit: 'yes',
type: 'feat',
scope: 'myScope',
subject: 'create a new cool feature',
ticketNumber: '1234',
};

const mockCz = getMockedCz(answers);
czModule.prompter(mockCz, commit);
expect(commit).toHaveBeenCalledWith('feat(myScope): [TICKET-1234] create a new cool feature');
});
});
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ declare module "cz-customizable" {
skipQuestions?: string[];
appendBranchNameToCommitMessage?: boolean;
ticketNumberPrefix?: string;
ticketNumberSuffix?:string;
breakingPrefix?: string;
footerPrefix?: string;
subjectLimit?: number;
Expand Down
10 changes: 8 additions & 2 deletions lib/build-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ const addTicketNumber = (ticketNumber, config) => {
return '';
}

let trimmedTicketNumber = ticketNumber.trim();

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

if (config.ticketNumberSuffix) {
trimmedTicketNumber = `${trimmedTicketNumber}${config.ticketNumberSuffix}`;
}

return `${ticketNumber.trim()} `;
return `${trimmedTicketNumber} `;
};

const addScope = (scope, config) => {
Expand Down
Loading