All files / src prompts.js

85.71% Statements 12/14
75% Branches 3/4
66.67% Functions 4/6
85.71% Lines 12/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 781x 1x 1x 1x   1x                                                     1x 4x           2x   2x 2x   2x                                                         1x        
const constants = require('./constants')
const configVault = require('./config')
const guard = require('./guard')
const utils = require('./utils')
 
const config = [
  {
    name: constants.AUTO_ADD,
    message: 'Enable automatic "git add ."',
    type: 'confirm'
  },
  {
    name: constants.ISSUE_FORMAT,
    message: 'Choose Issue Format',
    type: 'list',
    choices: ['github', 'jira']
  },
  {
    name: constants.EMOJI_FORMAT,
    message: 'Select how emojis should be used in commits',
    type: 'list',
    choices: [
      { name: ':smile:', value: 'code' }, { name: '😄', value: 'emoji' }
    ]
  },
  {
    name: constants.SIGNED_COMMIT,
    message: 'Enable signed commits',
    type: 'confirm'
  }
]
 
const gitmoji = (gitmojis) => {
  return [
    {
      name: 'gitmoji',
      message: 'Choose a gitmoji:',
      type: 'autocomplete',
      source: (answersSoFor, input) => {
        return Promise.resolve(
          gitmojis.filter((gitmoji) => {
            const emoji = gitmoji.name.concat(gitmoji.description).toLowerCase()
            return (!input || emoji.indexOf(input.toLowerCase()) !== -1)
          })
            .map((gitmoji) => ({
              name: `${gitmoji.emoji}  - ${gitmoji.description}`,
              value: gitmoji[configVault.getEmojiFormat() || constants.CODE]
            }))
        )
      }
    },
    {
      name: 'title',
      message: 'Enter the commit title',
      validate: guard.title,
      transformer: (input) => utils.inputCountTransformer(
        input,
        constants.TITLE_MAX_LENGTH_COUNT
      )
    },
    {
      name: 'message',
      message: 'Enter the commit message:',
      validate: guard.message
    },
    {
      name: 'reference',
      message: 'Issue / PR reference:',
      validate: (value) => guard.reference(value, configVault.getIssueFormat())
    }
  ]
}
 
module.exports = {
  config,
  gitmoji
}