Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #71 -Wrong contribution type being added to .all-contributorsrc #78

Merged
merged 19 commits into from
Jun 8, 2018
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@
"profile": "https://in.linkedin.com/in/mzubairahmed",
"contributions": [
"doc",
"bug"
"bug",
"code",
"test"
]
}
]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,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://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") |
<!-- 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(
'Invalid contribution type(s) entered',
)
})

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'])
})
})
20 changes: 19 additions & 1 deletion src/contributors/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,28 @@ 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('Invalid contribution type(s) entered')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make the error include a comma-separated list of the invalid contribution types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean to say, have a list of valid contribution types?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want them to be able to see which contribution type they entered which was invalid so they know not to enter that again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added please take a look 👍

}

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