Skip to content

Commit

Permalink
Merge af2d0d4 into c14a9c3
Browse files Browse the repository at this point in the history
  • Loading branch information
JPeer264 authored May 3, 2019
2 parents c14a9c3 + af2d0d4 commit 7177c1d
Show file tree
Hide file tree
Showing 7 changed files with 8,908 additions and 19 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,12 @@ Example:

> Types will define your git commits. If `types` is not set in your own `.sgcrc`, the `types` of the global [.sgcrc](.sgcrc)
> Notice: If the `type` is `false` it will let you to manually add the type. This is usefull especially if you have a `prefix` named `SGC-` to reference these as a ticket number for your ticket tool
**Keys**

- `type` - This will be your commit convention and will be your start of your commit - e.g.: `Feat:`
- `type` (`string` or `false`) - This will be your commit convention and will be your start of your commit - e.g.: `Feat:`
- `prefix` (optional) - This option is just valid, if `type` is `false`
- `description` (optional) - The description to explain what your type is about
- `emoji` (optional) - An emoji which will be appended at the beginning of the commit ([Emoji Cheat Sheet](https://www.webpagefx.com/tools/emoji-cheat-sheet/))
- `argKeys` | Array (optional) - Keys which will be accessed through the `-t` [parameter](#usage-with-parameters)
Expand Down
3 changes: 2 additions & 1 deletion lib/helpers/formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export const formatMessage = (answers, argv) => {
...argv,
};

const type = combineTypeScope(combinedAnswers.type, combinedAnswers.scope);
const correctType = combinedAnswers.customType || combinedAnswers.type;
const type = combineTypeScope(correctType, combinedAnswers.scope);
const formattedMessage = `${type} ${(combinedAnswers.message || '').trim()}`;
let result = formattedMessage;

Expand Down
45 changes: 44 additions & 1 deletion lib/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@ import chalk from 'chalk';
import ruleWarningMessages from './rules/ruleWarningMessages';
import { formatMessage } from './helpers/formatters';

const customName = 'Custom';

const choices = (config) => {
const choicesList = [];

let customCount = 1;

config.types.forEach((type) => {
const emoji = config.emoji && type.emoji ? `${type.emoji} ` : '';
const configType = config.lowercaseTypes ? type.type.toLowerCase() : type.type;
let changedType = type.type;

// type = false === it is a custom type
if (!changedType) {
changedType = `${customName} ${customCount}`;
customCount += 1;
}

const configType = config.lowercaseTypes ? changedType.toLowerCase() : changedType;
const description = type.description || '';
const argKeys = type.argKeys || [];
const isArray = Array.isArray(argKeys);
Expand Down Expand Up @@ -75,6 +87,36 @@ const questions = (config, argv = {}) => {
message: 'Select the type of your commit:',
choices: choicesList,
},
{
type: 'input',
name: 'customType',
when: answers => (answers.type.includes(customName) && !modifiedArgv.c),
filter: (answer, answers) => {
let customCount = 1;

const typeChoice = config.types.find((type) => {
// if there is no type it is a custom type
if (!type.type) {
if (answers.type === `${customName} ${customCount}`) {
return true;
}

customCount += 1;
}

return false;
});


if (!typeChoice) {
return answer;
}

return `${typeChoice.prefix || ''}${answer}`;
},
message: 'Choose your custom commit:',
choices: choicesList,
},
{
type: 'input',
name: 'scope',
Expand Down Expand Up @@ -124,6 +166,7 @@ const questions = (config, argv = {}) => {
export default questions;
export {
choices,
customName,
initMessage,
initQuestion,
};
Loading

0 comments on commit 7177c1d

Please sign in to comment.