2016-03-02 22:45:23 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-03-29 20:59:21 +00:00
|
|
|
var _ = require('lodash/fp');
|
2016-03-27 15:19:13 +00:00
|
|
|
var util = require('../util');
|
2016-03-02 22:45:23 +00:00
|
|
|
var add = require('./add');
|
|
|
|
var github = require('./github');
|
2016-03-27 15:19:13 +00:00
|
|
|
var prompt = require('./prompt');
|
2016-03-02 22:45:23 +00:00
|
|
|
|
2016-03-29 20:59:21 +00:00
|
|
|
function isNewContributor(contributorList, username) {
|
|
|
|
return !_.find({login: username}, contributorList);
|
|
|
|
}
|
|
|
|
|
2017-02-15 21:25:32 +00:00
|
|
|
module.exports = function addContributor(options, username, contributions) {
|
|
|
|
const answersP = prompt(options, username, contributions);
|
|
|
|
const contributorsP = answersP
|
|
|
|
.then(answers => add(options, answers.username, answers.contributions, github));
|
|
|
|
|
|
|
|
const writeContributorsP = contributorsP.then(
|
|
|
|
contributors => util.configFile.writeContributors(options.config, contributors)
|
|
|
|
);
|
|
|
|
|
|
|
|
return Promise.all([answersP, contributorsP, writeContributorsP])
|
|
|
|
.then(res => {
|
|
|
|
const answers = res[0];
|
|
|
|
const contributors = res[1];
|
|
|
|
return {
|
|
|
|
username: answers.username,
|
|
|
|
contributions: answers.contributions,
|
|
|
|
contributors: contributors,
|
|
|
|
newContributor: isNewContributor(options.contributors, answers.username)
|
|
|
|
};
|
2016-03-02 22:45:23 +00:00
|
|
|
});
|
|
|
|
};
|