mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-10 05:56:29 +00:00
feat: Reselect existing contributions when updating a user
This commit is contained in:
commit
5b6358425f
1 changed files with 20 additions and 1 deletions
|
@ -29,8 +29,27 @@ function getQuestions(options, username, contributions) {
|
||||||
name: 'contributions',
|
name: 'contributions',
|
||||||
message: 'What are the contribution types?',
|
message: 'What are the contribution types?',
|
||||||
when: !contributions,
|
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),
|
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;
|
||||||
|
}
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue