fix: Wrong contribution type being added to .all-contributorsrc (#78)

* initial issue fix

* tests added

* revert unneisary lint change to untouched file

* added myself

* no contribution types when adding a contributor error handled

* revert commit 1bdb51eadf

* reverted readme back to commit# f697c73c48

* further reverted Readme to master

* removed generated index from rm

* removed generated index from rm

* breaking change to cli fixed:

* Update prompt.js

* Update prompt.js

* added code and test in my contribution

* list of invalid contributions added in error message

Closes #71
This commit is contained in:
Md Zubair Ahmed 2018-06-09 00:41:29 +05:30 committed by Kent C. Dodds
parent c4a0484759
commit 526d4dbba2
4 changed files with 89 additions and 3 deletions

View file

@ -178,7 +178,7 @@ Thanks goes to these wonderful people
| :---: | :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars3.githubusercontent.com/u/8212?v=3" width="100px;"/><br /><sub><b>Jerod Santo</b></sub>](https://jerodsanto.net)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=jerodsanto "Code") | [<img src="https://avatars1.githubusercontent.com/u/574871?v=3" width="100px;"/><br /><sub><b>Kevin Jalbert</b></sub>](https://github.com/kevinjalbert)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=kevinjalbert "Code") | [<img src="https://avatars3.githubusercontent.com/u/5038030?v=4" width="100px;"/><br /><sub><b>tunnckoCore</b></sub>](https://i.am.charlike.online)<br />[🔧](#tool-charlike "Tools") | [<img src="https://avatars2.githubusercontent.com/u/304450?v=4" width="100px;"/><br /><sub><b>Mehdi Achour</b></sub>](https://machour.idk.tn/)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=machour "Code") | [<img src="https://avatars1.githubusercontent.com/u/8344688?v=4" width="100px;"/><br /><sub><b>Roy Revelt</b></sub>](https://codsen.com)<br />[🐛](https://github.com/jfmengels/all-contributors-cli/issues?q=author%3Arevelt "Bug reports") | [<img src="https://avatars1.githubusercontent.com/u/422331?v=4" width="100px;"/><br /><sub><b>Chris Vickery</b></sub>](https://github.com/chrisinajar)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=chrisinajar "Code") |
| [<img src="https://avatars2.githubusercontent.com/u/1026002?v=4" width="100px;"/><br /><sub><b>Bryce Reynolds</b></sub>](https://github.com/brycereynolds)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=brycereynolds "Code") | [<img src="https://avatars3.githubusercontent.com/u/2322305?v=4" width="100px;"/><br /><sub><b>James, please</b></sub>](http://www.jmeas.com)<br />[🤔](#ideas-jmeas "Ideas, Planning, & Feedback") [💻](https://github.com/jfmengels/all-contributors-cli/commits?author=jmeas "Code") | [<img src="https://avatars3.githubusercontent.com/u/1057324?v=4" width="100px;"/><br /><sub><b>Spyros Ioakeimidis</b></sub>](http://www.spyros.io)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=spirosikmd "Code") | [<img src="https://avatars3.githubusercontent.com/u/12335761?v=4" width="100px;"/><br /><sub><b>Fernando Costa</b></sub>](https://github.com/fadc80)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=fadc80 "Code") | [<img src="https://avatars0.githubusercontent.com/u/197404?v=4" width="100px;"/><br /><sub><b>snipe</b></sub>](https://snipe.net)<br />[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=snipe "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/997157?v=4" width="100px;"/><br /><sub><b>Gant Laborde</b></sub>](http://gantlaborde.com/)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=GantMan "Code") |
| [<img src="https://avatars2.githubusercontent.com/u/17708702?v=4" width="100px;"/><br /><sub><b>Md Zubair Ahmed</b></sub>](https://in.linkedin.com/in/mzubairahmed)<br />[📖](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") | [<img src="https://avatars3.githubusercontent.com/u/6177621?v=4" width="100px;"/><br /><sub><b>Divjot Singh</b></sub>](http://bogas04.github.io)<br />[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=bogas04 "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/15315098?v=4" width="100px;"/><br /><sub><b>João Marques</b></sub>](https://github.com/tigermarques)<br />[💻](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") |
| [<img src="https://avatars2.githubusercontent.com/u/17708702?v=4" width="100px;"/><br /><sub><b>Md Zubair Ahmed</b></sub>](https://in.linkedin.com/in/mzubairahmed)<br />[📖](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") | [<img src="https://avatars3.githubusercontent.com/u/6177621?v=4" width="100px;"/><br /><sub><b>Divjot Singh</b></sub>](http://bogas04.github.io)<br />[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=bogas04 "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/15315098?v=4" width="100px;"/><br /><sub><b>João Marques</b></sub>](https://github.com/tigermarques)<br />[💻](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") |
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the

View file

@ -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'])
})
})

View file

@ -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))

View file

@ -1,4 +1,5 @@
const _ = require('lodash/fp')
const util = require('../util')
const linkTemplate = _.template(