diff --git a/README.md b/README.md
index a0357fc..c7d282b 100644
--- a/README.md
+++ b/README.md
@@ -178,7 +178,7 @@ Thanks goes to these wonderful people
| :---: | :---: | :---: | :---: | :---: | :---: |
| [
Jerod Santo](https://jerodsanto.net)
[π»](https://github.com/jfmengels/all-contributors-cli/commits?author=jerodsanto "Code") | [
Kevin Jalbert](https://github.com/kevinjalbert)
[π»](https://github.com/jfmengels/all-contributors-cli/commits?author=kevinjalbert "Code") | [
tunnckoCore](https://i.am.charlike.online)
[π§](#tool-charlike "Tools") | [
Mehdi Achour](https://machour.idk.tn/)
[π»](https://github.com/jfmengels/all-contributors-cli/commits?author=machour "Code") | [
Roy Revelt](https://codsen.com)
[π](https://github.com/jfmengels/all-contributors-cli/issues?q=author%3Arevelt "Bug reports") | [
Chris Vickery](https://github.com/chrisinajar)
[π»](https://github.com/jfmengels/all-contributors-cli/commits?author=chrisinajar "Code") |
| [
Bryce Reynolds](https://github.com/brycereynolds)
[π»](https://github.com/jfmengels/all-contributors-cli/commits?author=brycereynolds "Code") | [
James, please](http://www.jmeas.com)
[π€](#ideas-jmeas "Ideas, Planning, & Feedback") [π»](https://github.com/jfmengels/all-contributors-cli/commits?author=jmeas "Code") | [
Spyros Ioakeimidis](http://www.spyros.io)
[π»](https://github.com/jfmengels/all-contributors-cli/commits?author=spirosikmd "Code") | [
Fernando Costa](https://github.com/fadc80)
[π»](https://github.com/jfmengels/all-contributors-cli/commits?author=fadc80 "Code") | [
snipe](https://snipe.net)
[π](https://github.com/jfmengels/all-contributors-cli/commits?author=snipe "Documentation") | [
Gant Laborde](http://gantlaborde.com/)
[π»](https://github.com/jfmengels/all-contributors-cli/commits?author=GantMan "Code") |
-| [
Md Zubair Ahmed](https://in.linkedin.com/in/mzubairahmed)
[π](https://github.com/jfmengels/all-contributors-cli/commits?author=M-ZubairAhmed "Documentation") [π](https://github.com/jfmengels/all-contributors-cli/issues?q=author%3AM-ZubairAhmed "Bug reports") | [
Divjot Singh](http://bogas04.github.io)
[π](https://github.com/jfmengels/all-contributors-cli/commits?author=bogas04 "Documentation") | [
JoΓ£o Marques](https://github.com/tigermarques)
[π»](https://github.com/jfmengels/all-contributors-cli/commits?author=tigermarques "Code") [π](https://github.com/jfmengels/all-contributors-cli/commits?author=tigermarques "Documentation") [π€](#ideas-tigermarques "Ideas, Planning, & Feedback") |
+| [
Md Zubair Ahmed](https://in.linkedin.com/in/mzubairahmed)
[π](https://github.com/jfmengels/all-contributors-cli/commits?author=M-ZubairAhmed "Documentation") [π](https://github.com/jfmengels/all-contributors-cli/issues?q=author%3AM-ZubairAhmed "Bug reports") [π»](https://github.com/jfmengels/all-contributors-cli/commits?author=M-ZubairAhmed "Code") [β οΈ](https://github.com/jfmengels/all-contributors-cli/commits?author=M-ZubairAhmed "Tests") | [
Divjot Singh](http://bogas04.github.io)
[π](https://github.com/jfmengels/all-contributors-cli/commits?author=bogas04 "Documentation") | [
JoΓ£o Marques](https://github.com/tigermarques)
[π»](https://github.com/jfmengels/all-contributors-cli/commits?author=tigermarques "Code") [π](https://github.com/jfmengels/all-contributors-cli/commits?author=tigermarques "Documentation") [π€](#ideas-tigermarques "Ideas, Planning, & Feedback") |
This project follows the
diff --git a/src/contributors/__tests__/prompt.js b/src/contributors/__tests__/prompt.js
new file mode 100644
index 0000000..559526d
--- /dev/null
+++ b/src/contributors/__tests__/prompt.js
@@ -0,0 +1,59 @@
+import prompt from '../prompt'
+
+function fixtures() {
+ const options = {
+ contributors: [
+ {
+ login: 'jfmengels',
+ name: 'Jeroen Engels',
+ avatar_url: 'https://avatars.githubusercontent.com/u/3869412?v=3',
+ profile: 'https://github.com/jfmengels',
+ contributions: [],
+ },
+ {
+ login: 'kentcdodds',
+ name: 'Kent C. Dodds',
+ avatar_url: 'https://avatars.githubusercontent.com/u/1500684?v=3',
+ profile: 'http://kentcdodds.com/',
+ contributions: [],
+ },
+ {
+ login: 'jccguimaraes',
+ name: 'JoΓ£o GuimarΓ£es',
+ avatar_url: 'https://avatars.githubusercontent.com/u/14871650?v=3',
+ profile: 'https://github.com/jccguimaraes',
+ contributions: [],
+ },
+ ],
+ }
+ return options
+}
+
+test(`should throw error if all contribution types are invalid`, () => {
+ const options = fixtures()
+ const username = 'userName'
+ const contributions = 'invalidContributionType1,invalidContributionType2'
+ expect(() => prompt(options, username, contributions)).toThrow(
+ 'invalidContributionType1,invalidContributionType2 is/are invalid contribution type(s)',
+ )
+})
+
+test(`should not throw error if atleast one of the contribution types is valid`, () => {
+ const options = fixtures()
+ const username = 'userName'
+ const contributions = 'wrongContributionType,code'
+ return prompt(options, username, contributions).then(answers => {
+ expect(answers).toEqual({username: 'userName', contributions: ['code']})
+ })
+})
+
+test(`should filter valid contribution types from user inserted types`, () => {
+ const options = fixtures()
+ const username = 'userName'
+ const contributions =
+ 'invalidContributionType1,code,invalidContributionType2,bug'
+ return prompt(options, username, contributions).then(answers => {
+ expect(answers.contributions.length).toBe(2)
+ expect(answers.contributions).toEqual(['code', 'bug'])
+ })
+})
diff --git a/src/contributors/prompt.js b/src/contributors/prompt.js
index 50dfc5c..89555b8 100644
--- a/src/contributors/prompt.js
+++ b/src/contributors/prompt.js
@@ -22,7 +22,9 @@ function getQuestions(options, username, contributions) {
{
type: 'input',
name: 'username',
- message: `What is the contributor's ${repo.getTypeName(options.repoType)} username?`,
+ message: `What is the contributor's ${repo.getTypeName(
+ options.repoType,
+ )} username?`,
when: !username,
},
{
@@ -69,10 +71,34 @@ 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)
+
+ const invalidUserContributions = _.filter(
+ userContribution => validContributionTypes[userContribution] === undefined,
+ )(userContributions)
+
+ if (_.isEmpty(validUserContributions)) {
+ throw new Error(
+ `${invalidUserContributions.toString()} is/are invalid contribution type(s)`,
+ )
+ }
+
+ return validUserContributions
+}
+
module.exports = function prompt(options, username, contributions) {
const defaults = {
username,
- contributions: contributions && contributions.split(','),
+ contributions:
+ username === undefined && contributions === undefined
+ ? []
+ : 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..4512439 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(