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 5 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
11 changes: 11 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@
"contributions": [
"code"
]
},
{
"login": "M-ZubairAhmed",
"name": "Md Zubair Ahmed",
"avatar_url": "https://avatars2.githubusercontent.com/u/17708702?v=4",
"profile": "https://in.linkedin.com/in/mzubairahmed",
"contributions": [
"code",
"test",
"bug"
]
}
]
}
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[![version][version-badge]][package] [![downloads][downloads-badge]][downloads]
[![MIT License][license-badge]][license]

[![All Contributors](https://img.shields.io/badge/all_contributors-18-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-19-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome][prs-badge]][prs] [![Code of Conduct][coc-badge]][coc]
[![Watch on GitHub][github-watch-badge]][github-watch]
[![Star on GitHub][github-star-badge]][github-star]
Expand All @@ -35,9 +35,10 @@ specification.

- [Installation](#installation)
- [Usage](#usage)
- [Generating the contributors list](#generating-the-contributors-list)
- [Add/update contributors](#addupdate-contributors)
- [Check for missing contributors](#check-for-missing-contributors)
- [Configuration](#configuration)
- [Inspiration](#inspiration)
- [Other Solutions](#other-solutions)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be dealt with in another PR.

- [Contributors](#contributors)
- [LICENSE](#license)

Expand Down Expand Up @@ -167,13 +168,11 @@ Thanks goes to these wonderful people
([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->

Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you remove that space by hand, or did the command output change? 🤔

<!-- prettier-ignore -->
| [<img src="https://avatars.githubusercontent.com/u/3869412?v=3" width="100px;"/><br /><sub><b>Jeroen Engels</b></sub>](https://github.com/jfmengels)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=jfmengels "Code") [📖](https://github.com/jfmengels/all-contributors-cli/commits?author=jfmengels "Documentation") [⚠️](https://github.com/jfmengels/all-contributors-cli/commits?author=jfmengels "Tests") | [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub><b>Kent C. Dodds</b></sub>](http://kentcdodds.com/)<br />[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=kentcdodds "Documentation") [💻](https://github.com/jfmengels/all-contributors-cli/commits?author=kentcdodds "Code") | [<img src="https://avatars.githubusercontent.com/u/14871650?v=3" width="100px;"/><br /><sub><b>João Guimarães</b></sub>](https://github.com/jccguimaraes)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=jccguimaraes "Code") | [<img src="https://avatars.githubusercontent.com/u/1282980?v=3" width="100px;"/><br /><sub><b>Ben Briggs</b></sub>](http://beneb.info)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=ben-eb "Code") | [<img src="https://avatars.githubusercontent.com/u/22768990?v=3" width="100px;"/><br /><sub><b>Itai Steinherz</b></sub>](https://github.com/itaisteinherz)<br />[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=itaisteinherz "Documentation") [💻](https://github.com/jfmengels/all-contributors-cli/commits?author=itaisteinherz "Code") | [<img src="https://avatars.githubusercontent.com/u/5701162?v=3" width="100px;"/><br /><sub><b>Alex Jover</b></sub>](https://github.com/alexjoverm)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=alexjoverm "Code") [📖](https://github.com/jfmengels/all-contributors-cli/commits?author=alexjoverm "Documentation") | [<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://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 "Code") [⚠️](https://github.com/jfmengels/all-contributors-cli/commits?author=M-ZubairAhmed "Tests") [🐛](https://github.com/jfmengels/all-contributors-cli/issues?q=author%3AM-ZubairAhmed "Bug reports") |
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the
Expand Down
68 changes: 68 additions & 0 deletions src/contributors/__tests__/prompt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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: [Array],
},
{
login: 'kentcdodds',
name: 'Kent C. Dodds',
avatar_url: 'https://avatars.githubusercontent.com/u/1500684?v=3',
profile: 'http://kentcdodds.com/',
contributions: [Array],
},
{
login: 'jccguimaraes',
name: 'João Guimarães',
avatar_url: 'https://avatars.githubusercontent.com/u/14871650?v=3',
profile: 'https://github.com/jccguimaraes',
contributions: [Array],
},
],
}
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'])
})
})

test(`should throw error if no contribution types were included in add command`, () => {
const options = fixtures()
const username = 'userName'
const contributions = ''
expect(() => prompt(options, username, contributions)).toThrow(
`No contribution type found in the input. Did you forget to include them in the add command?`,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If no contribution types are found in the add command, the user should be prompted for them.

I should be able to just run the cli without any argument, be prompted for the operation I want to do (add/generate), then be prompted for the rest of the arguments.

Currently your patch breaks that:

screen shot 2017-12-25 at 12 20 13 pm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok let us handle this in another pr then

})
23 changes: 22 additions & 1 deletion src/contributors/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,31 @@ function getQuestions(options, username, contributions) {
]
}

function getValidUserContributions(options, contributions) {
const validContributionTypes = util.contributionTypes(options)
const userContributions = contributions && contributions.split(',')

if (_.isEmpty(userContributions)) {
throw new Error(
`No contribution type found in the input. Did you forget to include them in the add command?`,
)
}

const validUserContributions = _.filter(
userContribution => validContributionTypes[userContribution] !== undefined,
)(userContributions)

if (_.isEmpty(validUserContributions)) {
throw new Error(`Invalid contribution type/s entered`)
}

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