Skip to content

Commit

Permalink
fix: Wrong contribution type being added to .all-contributorsrc (#78)
Browse files Browse the repository at this point in the history
* 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 1bdb51e

* reverted readme back to commit# f697c73

* 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
  • Loading branch information
M-ZubairAhmed authored and Kent C. Dodds committed Jun 8, 2018
1 parent c4a0484 commit 526d4db
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 59 additions & 0 deletions src/contributors/__tests__/prompt.js
Original file line number Diff line number Diff line change
@@ -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'])
})
})
30 changes: 28 additions & 2 deletions src/contributors/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
{
Expand Down Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions src/generate/format-contribution-type.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const _ = require('lodash/fp')

const util = require('../util')

const linkTemplate = _.template(
Expand Down

0 comments on commit 526d4db

Please sign in to comment.