From f697c73c48eb7736942ec98fb5383c57a7f18bf4 Mon Sep 17 00:00:00 2001 From: z Date: Sat, 23 Dec 2017 14:10:40 +0530 Subject: [PATCH] initial issue fix --- src/contributors/prompt.js | 17 ++++++++++++++++- src/generate/format-contribution-type.js | 6 ++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/contributors/prompt.js b/src/contributors/prompt.js index 232cc35..c0e1489 100644 --- a/src/contributors/prompt.js +++ b/src/contributors/prompt.js @@ -68,10 +68,25 @@ function getQuestions(options, username, contributions) { ] } +function getValidUserContributions(options, contributions) { + const validContributionTypes = util.contributionTypes(options) + const userContributions = contributions && contributions.split(',') + + const validUserContributions = _.filter( + userContribution => validContributionTypes[userContribution] !== undefined, + )(userContributions) + + if (_.isEmpty(validUserContributions)) { + throw new Error('Please specify valid contribution types') + } + + return validUserContributions +} + module.exports = function prompt(options, username, contributions) { const defaults = { username, - contributions: contributions && contributions.split(','), + contributions: getValidUserContributions(options, contributions), } const questions = getQuestions(options, username, contributions) return inquirer.prompt(questions).then(_.assign(defaults)) diff --git a/src/generate/format-contribution-type.js b/src/generate/format-contribution-type.js index 78843ea..3666ed5 100644 --- a/src/generate/format-contribution-type.js +++ b/src/generate/format-contribution-type.js @@ -1,4 +1,5 @@ const _ = require('lodash/fp') + const util = require('../util') const linkTemplate = _.template( @@ -19,8 +20,9 @@ module.exports = function formatContribution( if (!type) { throw new Error( - `Unknown contribution type ${contribution} for contributor ${contributor.login || - contributor.name}`, + `Unknown contribution type ${ + contribution + } for contributor ${contributor.login || contributor.name}`, ) }