Skip to content

Commit

Permalink
feat: Reselect existing contributions when updating a user
Browse files Browse the repository at this point in the history
  • Loading branch information
machour committed Nov 7, 2017
2 parents 11833b0 + cf3ca62 commit 5b63584
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/contributors/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,27 @@ function getQuestions(options, username, contributions) {
name: 'contributions',
message: 'What are the contribution types?',
when: !contributions,
default: function (answers) {
// default values for contributions when updating existing users
answers.username = answers.username || username;
return options.contributors
.filter((entry) => entry.login.toLowerCase() === answers.username.toLowerCase())
.reduce((allEntries, entry) => allEntries.concat(entry.contributions), []);
},
choices: contributionChoices(options),
validate: input => input.length ? true : 'Use space to select at least one contribution type.'
validate: function (input, answers) {
answers.username = answers.username || username;
var previousContributions = options.contributors
.filter((entry) => entry.login.toLowerCase() === answers.username.toLowerCase())
.reduce((allEntries, entry) => allEntries.concat(entry.contributions), []);

if (!input.length) {
return 'Use space to select at least one contribution type.';
} else if (_.isEqual(input, previousContributions)) {
return 'Nothing changed, use space to select contribution types.';
}
return true;
}
}];
}

Expand Down

0 comments on commit 5b63584

Please sign in to comment.