mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-09 13:36:29 +00:00
Add prompt when adding contributor/ion and omitting user or types
This commit is contained in:
parent
192e698dca
commit
8c2642422e
9 changed files with 105 additions and 59 deletions
24
cli.js
24
cli.js
|
@ -55,6 +55,19 @@ function startGeneration(argv, cb) {
|
|||
});
|
||||
}
|
||||
|
||||
function addContribution(argv, cb) {
|
||||
var username = argv._[1];
|
||||
var contributions = argv._[2];
|
||||
// Add or update contributor in the config file
|
||||
updateContributors(argv, username, contributions, function (error, contributors) {
|
||||
if (error) {
|
||||
return onError(error);
|
||||
}
|
||||
argv.contributors = contributors;
|
||||
startGeneration(argv, cb);
|
||||
});
|
||||
}
|
||||
|
||||
function onError(error) {
|
||||
if (error) {
|
||||
return console.error(error);
|
||||
|
@ -68,14 +81,5 @@ if (command === 'init') {
|
|||
} else if (command === 'generate') {
|
||||
startGeneration(argv, onError);
|
||||
} else if (command === 'add') {
|
||||
var username = argv._[1];
|
||||
var contributions = argv._[2];
|
||||
// Add or update contributor in the config file
|
||||
updateContributors(argv, username, contributions, function (error, contributors) {
|
||||
if (error) {
|
||||
return onError(error);
|
||||
}
|
||||
argv.contributors = contributors;
|
||||
startGeneration(argv, onError);
|
||||
});
|
||||
addContribution(argv, onError);
|
||||
}
|
||||
|
|
|
@ -6,8 +6,7 @@ function uniqueTypes(contribution) {
|
|||
return contribution.type || contribution;
|
||||
}
|
||||
|
||||
function formatContributions(options, existing, newTypes) {
|
||||
var types = newTypes.split(',');
|
||||
function formatContributions(options, existing, types) {
|
||||
if (options.url) {
|
||||
return (existing || []).concat(types.map(function (type) {
|
||||
return {type: type, url: options.url};
|
||||
|
|
|
@ -51,7 +51,7 @@ test.cb('should callback with error if infoFetcher fails', t => {
|
|||
test.cb('should add new contributor at the end of the list of contributors', t => {
|
||||
const {options} = fixtures();
|
||||
const username = 'login3';
|
||||
const contributions = 'doc';
|
||||
const contributions = ['doc'];
|
||||
|
||||
return addContributor(options, username, contributions, mockInfoFetcher, function (error, contributors) {
|
||||
t.notOk(error);
|
||||
|
@ -72,7 +72,7 @@ test.cb('should add new contributor at the end of the list of contributors', t =
|
|||
test.cb('should add new contributor at the end of the list of contributors with a url link', t => {
|
||||
const {options} = fixtures();
|
||||
const username = 'login3';
|
||||
const contributions = 'doc';
|
||||
const contributions = ['doc'];
|
||||
options.url = 'www.foo.bar';
|
||||
|
||||
return addContributor(options, username, contributions, mockInfoFetcher, function (error, contributors) {
|
||||
|
@ -94,7 +94,7 @@ test.cb('should add new contributor at the end of the list of contributors with
|
|||
test.cb(`should not update an existing contributor's contributions where nothing has changed`, t => {
|
||||
const {options} = fixtures();
|
||||
const username = 'login2';
|
||||
const contributions = 'blog,code';
|
||||
const contributions = ['blog', 'code'];
|
||||
|
||||
return addContributor(options, username, contributions, mockInfoFetcher, function (error, contributors) {
|
||||
t.notOk(error);
|
||||
|
@ -106,8 +106,7 @@ test.cb(`should not update an existing contributor's contributions where nothing
|
|||
test.cb(`should update an existing contributor's contributions if a new type is added`, t => {
|
||||
const {options} = fixtures();
|
||||
const username = 'login1';
|
||||
const contributions = 'bug';
|
||||
|
||||
const contributions = ['bug'];
|
||||
return addContributor(options, username, contributions, mockInfoFetcher, function (error, contributors) {
|
||||
t.notOk(error);
|
||||
t.is(contributors.length, 2);
|
||||
|
@ -128,7 +127,7 @@ test.cb(`should update an existing contributor's contributions if a new type is
|
|||
test.cb(`should update an existing contributor's contributions if a new type is added with a link`, t => {
|
||||
const {options} = fixtures();
|
||||
const username = 'login1';
|
||||
const contributions = 'bug';
|
||||
const contributions = ['bug'];
|
||||
options.url = 'www.foo.bar';
|
||||
|
||||
return addContributor(options, username, contributions, mockInfoFetcher, function (error, contributors) {
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
var util = require('../util');
|
||||
var add = require('./add');
|
||||
var github = require('./github');
|
||||
var configFile = require('../util').configFile;
|
||||
var prompt = require('./prompt');
|
||||
|
||||
module.exports = function addContributor(options, username, contributions, cb) {
|
||||
add(options, username, contributions, github, function (error, contributors) {
|
||||
if (error) {
|
||||
return cb(error);
|
||||
}
|
||||
configFile.writeContributors(options.config, contributors, function (error) {
|
||||
return cb(error, contributors);
|
||||
prompt(options, username, contributions, function (answers) {
|
||||
add(options, answers.username, answers.contributions, github, function (error, contributors) {
|
||||
if (error) {
|
||||
return cb(error);
|
||||
}
|
||||
util.configFile.writeContributors(options.config, contributors, function (error) {
|
||||
return cb(error, contributors);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
32
lib/contributors/prompt.js
Normal file
32
lib/contributors/prompt.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
'use strict';
|
||||
|
||||
var _ = require('lodash/fp');
|
||||
var inquirer = require('inquirer');
|
||||
var util = require('../util');
|
||||
|
||||
function getQuestions(options, username, contributions) {
|
||||
return [{
|
||||
type: 'input',
|
||||
name: 'username',
|
||||
message: "What is the contributor's GitHub username?",
|
||||
when: !username
|
||||
}, {
|
||||
type: 'checkbox',
|
||||
name: 'contributions',
|
||||
message: "What are the contribution types?",
|
||||
when: !contributions,
|
||||
choices: Object.keys(util.contributionTypes(options))
|
||||
}];
|
||||
}
|
||||
|
||||
module.exports = function prompt(options, username, contributions, cb) {
|
||||
var defaults = {
|
||||
username: username,
|
||||
contributions: contributions && contributions.split(',')
|
||||
};
|
||||
var questions = getQuestions(options, username, contributions);
|
||||
inquirer.prompt(questions, _.flow(
|
||||
_.assign(defaults),
|
||||
cb
|
||||
));
|
||||
};
|
|
@ -1,43 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
var _ = require('lodash/fp');
|
||||
var util = require('../util');
|
||||
|
||||
var linkToCommits = 'https://github.com/<%= options.projectOwner %>/<%= options.projectName %>/commits?author=<%= contributor.login %>';
|
||||
var linkToIssues = 'https://github.com/<%= options.projectOwner %>/<%= options.projectName %>/issues?q=author%3A<%= contributor.login %>';
|
||||
var linkTemplate = _.template('[<%= symbol %>](<%= url %>)');
|
||||
|
||||
var defaultTypes = {
|
||||
blog: {symbol: '📝'},
|
||||
bug: {
|
||||
symbol: '🐛',
|
||||
link: linkToIssues
|
||||
},
|
||||
code: {
|
||||
symbol: '💻',
|
||||
link: linkToCommits
|
||||
},
|
||||
design: {symbol: '🎨'},
|
||||
doc: {
|
||||
symbol: '📖',
|
||||
link: linkToCommits
|
||||
},
|
||||
example: {symbol: '💡'},
|
||||
plugin: {symbol: '🔌'},
|
||||
question: {symbol: '❓'},
|
||||
review: {symbol: '👀'},
|
||||
talk: {symbol: '📢'},
|
||||
test: {
|
||||
symbol: '⚠️',
|
||||
link: linkToCommits
|
||||
},
|
||||
translation: {symbol: '🌍'},
|
||||
tool: {symbol: '🔧'},
|
||||
tutorial: {symbol: '✅'},
|
||||
video: {symbol: '📹'}
|
||||
};
|
||||
|
||||
function getType(options, contribution) {
|
||||
var types = _.assign(defaultTypes, options.types);
|
||||
var types = util.contributionTypes(options);
|
||||
return types[contribution.type || contribution];
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
var _ = require('lodash/fp');
|
||||
var inquirer = require('inquirer');
|
||||
|
||||
var getRepoInfo = require('../util').git;
|
||||
|
||||
var questions = [{
|
||||
|
|
40
lib/util/contributionTypes.js
Normal file
40
lib/util/contributionTypes.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
'use strict';
|
||||
|
||||
var _ = require('lodash/fp');
|
||||
|
||||
var linkToCommits = 'https://github.com/<%= options.projectOwner %>/<%= options.projectName %>/commits?author=<%= contributor.login %>';
|
||||
var linkToIssues = 'https://github.com/<%= options.projectOwner %>/<%= options.projectName %>/issues?q=author%3A<%= contributor.login %>';
|
||||
|
||||
var defaultTypes = {
|
||||
blog: {symbol: '📝'},
|
||||
bug: {
|
||||
symbol: '🐛',
|
||||
link: linkToIssues
|
||||
},
|
||||
code: {
|
||||
symbol: '💻',
|
||||
link: linkToCommits
|
||||
},
|
||||
design: {symbol: '🎨'},
|
||||
doc: {
|
||||
symbol: '📖',
|
||||
link: linkToCommits
|
||||
},
|
||||
example: {symbol: '💡'},
|
||||
plugin: {symbol: '🔌'},
|
||||
question: {symbol: '❓'},
|
||||
review: {symbol: '👀'},
|
||||
talk: {symbol: '📢'},
|
||||
test: {
|
||||
symbol: '⚠️',
|
||||
link: linkToCommits
|
||||
},
|
||||
translation: {symbol: '🌍'},
|
||||
tool: {symbol: '🔧'},
|
||||
tutorial: {symbol: '✅'},
|
||||
video: {symbol: '📹'}
|
||||
};
|
||||
|
||||
module.exports = function (options) {
|
||||
return _.assign(defaultTypes, options.types);
|
||||
};
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
module.exports = {
|
||||
configFile: require('./configFile'),
|
||||
contributionTypes: require('./contributionTypes'),
|
||||
git: require('./git'),
|
||||
markdown: require('./markdown')
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue