all-contributors-cli
Advanced tools
Comparing version 6.23.1 to 6.24.0
@@ -7,12 +7,9 @@ "use strict"; | ||
// These Node API's are intended to be network and side effect free, everything should be in memory with no io to network/disk | ||
var chalk = require('chalk'); | ||
var addContributorWithDetails = require('./contributors/addWithDetails'); | ||
var generate = require('./generate'); | ||
var _require = require('./init/init-content'), | ||
addContributorsList = _require.addContributorsList, | ||
addBadge = _require.addBadge; | ||
addContributorsList = _require.addContributorsList, | ||
addBadge = _require.addBadge; | ||
process.stdout.write(chalk.yellow(`${chalk.bold('WARNING')} :: Using the all-contributors node-api comes with zero guarantees of stability and may contain breaking changes without warning\n`)); | ||
@@ -19,0 +16,0 @@ module.exports = { |
#!/usr/bin/env node | ||
/* eslint-disable no-console */ | ||
@@ -7,19 +6,10 @@ "use strict"; | ||
var path = require('path'); | ||
var yargs = require('yargs'); | ||
var chalk = require('chalk'); | ||
var inquirer = require('inquirer'); | ||
var init = require('./init'); | ||
var generate = require('./generate'); | ||
var util = require('./util'); | ||
var repo = require('./repo'); | ||
var updateContributors = require('./contributors'); | ||
var cwd = process.cwd(); | ||
@@ -40,3 +30,2 @@ var defaultRCFile = path.join(cwd, '.all-contributorsrc'); | ||
}).argv; | ||
function startGeneration(argv) { | ||
@@ -51,9 +40,7 @@ return Promise.all(argv.files.map(function (file) { | ||
} | ||
function addContribution(argv) { | ||
util.configFile.readConfig(argv.config); // ensure the config file exists | ||
var username = argv._[1] === undefined ? undefined : String(argv._[1]); | ||
var contributions = argv._[2]; // Add or update contributor in the config file | ||
var contributions = argv._[2]; | ||
// Add or update contributor in the config file | ||
return updateContributors(argv, username, contributions).then(function (data) { | ||
@@ -68,3 +55,2 @@ argv.contributors = data.contributors; | ||
} | ||
function checkContributors(argv) { | ||
@@ -87,3 +73,2 @@ var configData = util.configFile.readConfig(argv.config); | ||
}); | ||
if (missingInConfig.length) { | ||
@@ -93,3 +78,2 @@ process.stdout.write(chalk.bold('Missing contributors in .all-contributorsrc:\n')); | ||
} | ||
if (missingFromRepo.length) { | ||
@@ -101,3 +85,2 @@ process.stdout.write(chalk.bold('Unknown contributors found in .all-contributorsrc:\n')); | ||
} | ||
function onError(error) { | ||
@@ -108,6 +91,4 @@ if (error) { | ||
} | ||
process.exit(0); | ||
} | ||
function promptForCommand(argv) { | ||
@@ -135,3 +116,2 @@ var questions = [{ | ||
} | ||
promptForCommand(yargv).then(function (command) { | ||
@@ -141,12 +121,8 @@ switch (command) { | ||
return init(); | ||
case 'generate': | ||
return startGeneration(yargv); | ||
case 'add': | ||
return addContribution(yargv); | ||
case 'check': | ||
return checkContributors(yargv); | ||
default: | ||
@@ -153,0 +129,0 @@ throw new Error(`Unknown command ${command}`); |
"use strict"; | ||
var _ = require('lodash/fp'); | ||
function uniqueTypes(contribution) { | ||
return contribution.type || contribution; | ||
} | ||
function formatContributions(options, existing, types) { | ||
@@ -13,7 +11,4 @@ if (existing === void 0) { | ||
} | ||
var same = _.intersectionBy(uniqueTypes, existing, types); | ||
var remove = types.length < existing.length && same.length; | ||
if (options.url) { | ||
@@ -27,10 +22,7 @@ return existing.concat(types.map(function (type) { | ||
} | ||
if (remove) { | ||
return same; | ||
} | ||
return _.uniqBy(uniqueTypes, existing.concat(types)); | ||
} | ||
function updateContributor(options, contributor, contributions) { | ||
@@ -41,3 +33,2 @@ return _.assign(contributor, { | ||
} | ||
function updateExistingContributor(options, username, contributions) { | ||
@@ -48,7 +39,5 @@ return options.contributors.map(function (contributor) { | ||
} | ||
return updateContributor(options, contributor, contributions); | ||
}); | ||
} | ||
function addNewContributor(options, username, contributions, infoFetcher) { | ||
@@ -59,7 +48,5 @@ return infoFetcher(username, options.repoType, options.repoHost).then(function (userData) { | ||
}); | ||
return options.contributors.concat(contributor); | ||
}); | ||
} | ||
module.exports = function (options, username, contributions, infoFetcher) { | ||
@@ -70,8 +57,6 @@ // case insensitive find | ||
}, options.contributors); | ||
if (exists) { | ||
return Promise.resolve(updateExistingContributor(options, username, contributions)); | ||
} | ||
return addNewContributor(options, username, contributions, infoFetcher); | ||
}; |
"use strict"; | ||
var addContributor = require('./add'); // Adds a contributor without going to the network (you supply the additional fields) | ||
var addContributor = require('./add'); | ||
// Adds a contributor without going to the network (you supply the additional fields) | ||
module.exports = function (_ref) { | ||
var options = _ref.options, | ||
login = _ref.login, | ||
contributions = _ref.contributions, | ||
name = _ref.name, | ||
avatar_url = _ref.avatar_url, | ||
profile = _ref.profile; | ||
login = _ref.login, | ||
contributions = _ref.contributions, | ||
name = _ref.name, | ||
avatar_url = _ref.avatar_url, | ||
profile = _ref.profile; | ||
return addContributor(options, login, contributions, function infoFetcherNoNetwork() { | ||
@@ -14,0 +14,0 @@ return Promise.resolve({ |
"use strict"; | ||
var _ = require('lodash/fp'); | ||
var util = require('../util'); | ||
var repo = require('../repo'); | ||
var add = require('./add'); | ||
var prompt = require('./prompt'); | ||
function isNewContributor(contributorList, username) { | ||
@@ -18,3 +13,2 @@ return !_.find({ | ||
} | ||
module.exports = function (options, username, contributions) { | ||
@@ -21,0 +15,0 @@ var answersP = prompt(options, username, contributions); |
"use strict"; | ||
var _ = require('lodash/fp'); | ||
var inquirer = require('inquirer'); | ||
var util = require('../util'); | ||
var repo = require('../repo'); | ||
var contributionChoices = _.flow(util.contributionTypes, _.toPairs, _.sortBy(function (pair) { | ||
@@ -19,3 +15,2 @@ return pair[1].description; | ||
})); | ||
function getQuestions(options, username, contributions) { | ||
@@ -31,3 +26,2 @@ return [{ | ||
} | ||
return true; | ||
@@ -57,3 +51,2 @@ } | ||
}, []); | ||
if (!input.length) { | ||
@@ -64,3 +57,2 @@ return 'Use space to select at least one contribution type.'; | ||
} | ||
return true; | ||
@@ -70,22 +62,16 @@ } | ||
} | ||
function getValidUserContributions(options, contributions) { | ||
var validContributionTypes = util.contributionTypes(options); | ||
var userContributions = contributions && contributions.split(','); | ||
var validUserContributions = _.filter(function (userContribution) { | ||
return validContributionTypes[userContribution] !== undefined; | ||
})(userContributions); | ||
var invalidUserContributions = _.filter(function (userContribution) { | ||
return validContributionTypes[userContribution] === undefined; | ||
})(userContributions); | ||
if (_.isEmpty(validUserContributions)) { | ||
throw new Error(`${invalidUserContributions.toString()} is/are invalid contribution type(s)`); | ||
} | ||
return validUserContributions; | ||
} | ||
module.exports = function (options, username, contributions) { | ||
@@ -92,0 +78,0 @@ var defaults = { |
"use strict"; | ||
var _ = require('lodash/fp'); | ||
var defaultTemplate = '[![All Contributors](https://img.shields.io/badge/all_contributors-<%= contributors.length %>-orange.svg?style=flat-square)](#contributors-)'; | ||
module.exports = function (options, contributors) { | ||
@@ -8,0 +6,0 @@ return _.template(options.badgeTemplate || defaultTemplate)({ |
"use strict"; | ||
var _ = require('lodash/fp'); | ||
var util = require('../util'); | ||
var linkTemplate = _.template('<a href="<%= url %>" title="<%= description %>"><%= symbol %></a>'); | ||
function getType(options, contribution) { | ||
@@ -13,10 +10,7 @@ var types = util.contributionTypes(options); | ||
} | ||
module.exports = function (options, contributor, contribution) { | ||
var type = getType(options, contribution); | ||
if (!type) { | ||
throw new Error(`Unknown contribution type ${contribution} for contributor ${contributor.login || contributor.name}`); | ||
} | ||
var templateData = { | ||
@@ -29,3 +23,2 @@ symbol: type.symbol, | ||
var url = getUrl(contribution, contributor); | ||
if (contribution.url) { | ||
@@ -36,3 +29,2 @@ url = contribution.url; | ||
} | ||
return linkTemplate(_.assign({ | ||
@@ -42,3 +34,2 @@ url | ||
}; | ||
function getUrl(contribution, contributor) { | ||
@@ -45,0 +36,0 @@ if (contributor.login) { |
"use strict"; | ||
var _ = require('lodash/fp'); | ||
var formatContributionType = require('./format-contribution-type'); | ||
var avatarTemplate = _.template('<img src="<%= contributor.avatar_url %>?s=<%= options.imageSize %>" width="<%= options.imageSize %>px;" alt="<%= name %>"/>'); | ||
var avatarBlockTemplate = _.template('<a href="<%= contributor.profile %>"><%= avatar %><br /><sub><b><%= name %></b></sub></a>'); | ||
var avatarBlockTemplateNoProfile = _.template('<%= avatar %><br /><sub><b><%= name %></b></sub>'); | ||
var contributorTemplate = _.template('<%= avatarBlock %><br /><%= contributions %>'); | ||
var defaultImageSize = 100; | ||
function defaultTemplate(templateData) { | ||
@@ -23,3 +16,2 @@ var rawName = templateData.contributor.name || templateData.contributor.login; | ||
})); | ||
var avatarBlockTemplateData = _.assign({ | ||
@@ -29,5 +21,3 @@ name, | ||
}, templateData); | ||
var avatarBlock = null; | ||
if (templateData.contributor.profile) { | ||
@@ -38,3 +28,2 @@ avatarBlock = avatarBlockTemplate(avatarBlockTemplateData); | ||
} | ||
return contributorTemplate(_.assign({ | ||
@@ -44,10 +33,7 @@ avatarBlock | ||
} | ||
function escapeName(name) { | ||
return name.replace(new RegExp('\\|', 'g'), '|'); | ||
} | ||
module.exports = function (options, contributor) { | ||
var formatter = _.partial(formatContributionType, [options, contributor]); | ||
var contributions = contributor.contributions.map(formatter).join(' '); | ||
@@ -61,6 +47,4 @@ var templateData = { | ||
}; | ||
var customTemplate = options.contributorTemplate && _.template(options.contributorTemplate); | ||
return (customTemplate || defaultTemplate)(templateData); | ||
}; |
"use strict"; | ||
var _ = require('lodash/fp'); | ||
var floor = require('lodash/floor'); | ||
var formatBadge = require('./format-badge'); | ||
var formatContributor = require('./format-contributor'); | ||
function injectListBetweenTags(newContent) { | ||
@@ -16,7 +14,5 @@ return function (previousContent) { | ||
var startOfClosingTagIndex = previousContent.indexOf(`${tagToLookFor}END`, endOfOpeningTagIndex); | ||
if (startOfOpeningTagIndex === -1 || endOfOpeningTagIndex === -1 || startOfClosingTagIndex === -1) { | ||
return previousContent; | ||
} | ||
var startIndent = Math.max(0, previousContent.lastIndexOf('\n', startOfOpeningTagIndex)); | ||
@@ -27,7 +23,7 @@ var nbSpaces = startOfOpeningTagIndex - Math.min(startOfOpeningTagIndex, startIndent); | ||
} | ||
function formatLine(contributors) { | ||
return `<td align="center">${contributors.join('</td>\n <td align="center">')}</td>`; | ||
function formatLine(options, contributors) { | ||
var width = floor(_.divide(100)(options.contributorsPerLine), 2); | ||
var attributes = `align="center" valign="top" width="${width}%"`; | ||
return `<td ${attributes}>${contributors.join(`</td>\n <td ${attributes}>`)}</td>`; | ||
} | ||
function formatFooter(options) { | ||
@@ -37,6 +33,4 @@ if (!options.linkToUsage) { | ||
} | ||
return `<tr>\n <td align="center" size="13px" colspan="${options.contributorsPerLine}">\n <img src="${'https://raw.githubusercontent.com/all-contributors/all-contributors-cli/1b8533af435da9854653492b1327a23a4dbd0a10/assets/logo-small.svg'}">\n <a href="${'https://all-contributors.js.org/docs/en/bot/usage'}">Add your contributions</a>\n </img>\n </td>\n </tr>`; | ||
} | ||
function generateContributorsList(options, contributors) { | ||
@@ -51,11 +45,11 @@ var tableFooter = formatFooter(options); | ||
return formatContributor(options, contributor); | ||
}), _.chunk(options.contributorsPerLine), _.map(formatLine), _.join('\n </tr>\n <tr>\n '), function (newContent) { | ||
}), _.chunk(options.contributorsPerLine), _.map(function (currentLineContributors) { | ||
return formatLine(options, currentLineContributors); | ||
}), _.join('\n </tr>\n <tr>\n '), function (newContent) { | ||
if (options.linkToUsage) { | ||
tableFooterContent = ` <tfoot>\n ${tableFooter}\n </tfoot>\n`; | ||
} | ||
return `\n<table>\n <tbody>\n <tr>\n ${newContent}\n </tr>\n </tbody>\n${tableFooterContent}</table>\n\n`; | ||
})(contributors); | ||
} | ||
function replaceBadge(newContent) { | ||
@@ -68,7 +62,5 @@ return function (previousContent) { | ||
var startOfClosingTagIndex = previousContent.indexOf(`${tagToLookFor}END`, endOfOpeningTagIndex); | ||
if (startOfOpeningTagIndex === -1 || endOfOpeningTagIndex === -1 || startOfClosingTagIndex === -1) { | ||
return previousContent; | ||
} | ||
var startIndent = Math.max(0, previousContent.lastIndexOf('\n', startOfOpeningTagIndex)); | ||
@@ -79,3 +71,2 @@ var nbSpaces = startOfOpeningTagIndex - Math.min(startOfOpeningTagIndex, startIndent); | ||
} | ||
module.exports = function (options, contributors, fileContent) { | ||
@@ -82,0 +73,0 @@ var contributorsList = contributors.length === 0 ? '\n' : generateContributorsList(options, contributors); |
@@ -8,3 +8,2 @@ "use strict"; | ||
lowercase: true, | ||
transform(msg) { | ||
@@ -15,7 +14,5 @@ return msg.replace(/(^.*?) ([A-Z][a-z]+) \w*/, function () { | ||
} | ||
return `${words[0]} ${words[1].toLowerCase()} `; | ||
}); | ||
} | ||
}, | ||
@@ -22,0 +19,0 @@ atom: { |
"use strict"; | ||
var fs = require('fs'); | ||
module.exports = function (file) { | ||
@@ -6,0 +5,0 @@ return new Promise(function (resolve, reject) { |
"use strict"; | ||
var util = require('../util'); | ||
var prompt = require('./prompt'); | ||
var initContent = require('./init-content'); | ||
var ensureFileExists = require('./file-exist'); | ||
var configFile = util.configFile; | ||
var markdown = util.markdown; | ||
function injectInFile(file, fn) { | ||
@@ -19,3 +14,2 @@ return markdown.read(file).then(function (content) { | ||
} | ||
module.exports = function () { | ||
@@ -22,0 +16,0 @@ return prompt().then(function (result) { |
"use strict"; | ||
var _ = require('lodash/fp'); | ||
var injectContentBetween = require('../util').markdown.injectContentBetween; | ||
var badgeContent = ['<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->', '[![All Contributors](https://img.shields.io/badge/all_contributors-0-orange.svg?style=flat-square)](#contributors-)', '<!-- ALL-CONTRIBUTORS-BADGE:END -->'].join('\n'); | ||
@@ -11,25 +9,18 @@ var headerContent = 'Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):'; | ||
var footerContent = 'This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!'; | ||
function addBadge(lines) { | ||
return injectContentBetween(lines, badgeContent, 1, 1); | ||
} | ||
function splitAndRejoin(fn) { | ||
return _.flow(_.split('\n'), fn, _.join('\n')); | ||
} | ||
var findContributorsSection = _.findIndex(function (str) { | ||
return str.toLowerCase().indexOf('# contributors') === 1; | ||
}); | ||
function addContributorsList(lines) { | ||
var insertionLine = findContributorsSection(lines); | ||
if (insertionLine === -1) { | ||
return lines.concat(['## Contributors ✨', '', headerContent, '', listContent, '', footerContent]); | ||
} | ||
return injectContentBetween(lines, listContent, insertionLine + 3, insertionLine + 3); | ||
} | ||
module.exports = { | ||
@@ -36,0 +27,0 @@ addBadge: splitAndRejoin(addBadge), |
"use strict"; | ||
var _ = require('lodash/fp'); | ||
var inquirer = require('inquirer'); | ||
var git = require('../util').git; | ||
var conventions = require('./commit-conventions'); | ||
var questions = [{ | ||
@@ -84,5 +80,3 @@ type: 'input', | ||
}]; | ||
var uniqueFiles = _.flow(_.compact, _.uniq); | ||
module.exports = function () { | ||
@@ -94,3 +88,2 @@ return git.getRepoInfo().then(function (repoInfo) { | ||
} | ||
return inquirer.prompt(questions); | ||
@@ -97,0 +90,0 @@ }).then(function (answers) { |
"use strict"; | ||
var url = require('url'); | ||
var fetch = require('node-fetch'); | ||
var _require = require('../util/url'), | ||
parseHttpUrl = _require.parseHttpUrl, | ||
isValidHttpUrl = _require.isValidHttpUrl; | ||
var _require = require('../util/url'), | ||
parseHttpUrl = _require.parseHttpUrl, | ||
isValidHttpUrl = _require.isValidHttpUrl; | ||
/** | ||
@@ -17,4 +16,2 @@ * Get the host based on public or enterprise GitHub. | ||
*/ | ||
function getApiHost(hostname) { | ||
@@ -24,3 +21,2 @@ if (!hostname) { | ||
} | ||
if (hostname !== 'https://github.com') { | ||
@@ -30,6 +26,4 @@ // Assume Github Enterprise | ||
} | ||
return hostname.replace(/:\/\//, '://api.'); | ||
} | ||
function getFetchHeaders(optionalPrivateToken) { | ||
@@ -39,14 +33,10 @@ if (optionalPrivateToken === void 0) { | ||
} | ||
var fetchHeaders = { | ||
'User-Agent': 'node-fetch' | ||
}; | ||
if (optionalPrivateToken && optionalPrivateToken.length > 0) { | ||
fetchHeaders.Authorization = `token ${optionalPrivateToken}`; | ||
} | ||
return fetchHeaders; | ||
} | ||
function getNextLink(link) { | ||
@@ -56,14 +46,10 @@ if (!link) { | ||
} | ||
var nextLink = link.split(',').find(function (s) { | ||
return s.includes('rel="next"'); | ||
}); | ||
if (!nextLink) { | ||
return null; | ||
} | ||
return nextLink.split(';')[0].trim().slice(1, -1); | ||
} | ||
function getContributorsPage(githubUrl, optionalPrivateToken) { | ||
@@ -76,3 +62,2 @@ return fetch(githubUrl, { | ||
} | ||
return res.json().then(function (body) { | ||
@@ -82,3 +67,2 @@ if (res.status >= 400 || !res.ok) { | ||
} | ||
var contributorsIds = body.map(function (contributor) { | ||
@@ -88,3 +72,2 @@ return contributor.login; | ||
var nextLink = getNextLink(res.headers.get('link')); | ||
if (nextLink) { | ||
@@ -95,3 +78,2 @@ return getContributorsPage(nextLink, optionalPrivateToken).then(function (nextContributors) { | ||
} | ||
return contributorsIds; | ||
@@ -101,3 +83,2 @@ }); | ||
} | ||
var getUserInfo = function (username, hostname, optionalPrivateToken) { | ||
@@ -107,3 +88,2 @@ if (!username) { | ||
} | ||
var root = getApiHost(hostname); | ||
@@ -114,9 +94,10 @@ return fetch(`${root}/users/${username}`, { | ||
return res.json().then(function (body) { | ||
var profile = isValidHttpUrl(body.blog) ? body.blog : body.html_url; // Check for authentication required | ||
var profile = isValidHttpUrl(body.blog) ? body.blog : body.html_url; | ||
// Check for authentication required | ||
if (!profile && body.message.includes('Must authenticate') || res.status === 401) { | ||
throw new Error(`Missing authentication for GitHub API. Did you set PRIVATE_TOKEN?`); | ||
} // Github throwing specific errors as 200... | ||
} | ||
// Github throwing specific errors as 200... | ||
if (!profile && body.message) { | ||
@@ -129,3 +110,2 @@ if (body.message.toLowerCase().includes('api rate limit exceeded')) { | ||
} | ||
profile = parseHttpUrl(profile); | ||
@@ -141,3 +121,2 @@ return { | ||
}; | ||
var getContributors = function (owner, name, hostname, optionalPrivateToken) { | ||
@@ -147,3 +126,2 @@ var root = getApiHost(hostname); | ||
}; | ||
module.exports = { | ||
@@ -150,0 +128,0 @@ getUserInfo, |
"use strict"; | ||
var fetch = require('node-fetch'); | ||
var addPrivateToken = function (url, privateToken) { | ||
@@ -9,7 +8,5 @@ if (privateToken === void 0) { | ||
} | ||
if (privateToken === '') return url; | ||
return `${url}&private_token=${privateToken}`.replace(/\?/g, '&').replace('&', '?'); | ||
}; | ||
var getUserInfo = function (username, hostname, privateToken) { | ||
@@ -20,3 +17,2 @@ /* eslint-disable complexity */ | ||
} | ||
return fetch(addPrivateToken(`${hostname}/api/v4/users?username=${username}`, privateToken), { | ||
@@ -31,9 +27,8 @@ headers: { | ||
throw new Error(`User ${username} not found`); | ||
} // no private token present | ||
} | ||
// no private token present | ||
if (body.message) { | ||
throw new Error(body.message); | ||
} | ||
var user = body[0]; | ||
@@ -49,3 +44,2 @@ return { | ||
}; | ||
var getContributors = function (owner, name, hostname, privateToken) { | ||
@@ -55,3 +49,2 @@ if (!hostname) { | ||
} | ||
return fetch(addPrivateToken(`${hostname}/api/v4/projects?search=${name}`, privateToken), { | ||
@@ -67,5 +60,3 @@ headers: { | ||
} | ||
var project = null; | ||
for (var i = 0; i < projects.length; i++) { | ||
@@ -77,7 +68,5 @@ if (projects[i].path_with_namespace === `${owner}/${name}`) { | ||
} | ||
if (!project) { | ||
throw new Error(`Project ${owner}/${name} not found`); | ||
} | ||
return fetch(addPrivateToken(`${hostname}/api/v4/projects/${project.id}/repository/contributors`, privateToken), { | ||
@@ -91,3 +80,2 @@ headers: { | ||
} | ||
return newRes.json().then(function (contributors) { | ||
@@ -97,3 +85,2 @@ if (newRes.status >= 400 || !newRes.ok) { | ||
} | ||
return contributors.map(function (item) { | ||
@@ -107,3 +94,2 @@ return item.name; | ||
}; | ||
module.exports = { | ||
@@ -110,0 +96,0 @@ getUserInfo, |
"use strict"; | ||
var githubAPI = require('./github'); | ||
var gitlabAPI = require('./gitlab'); | ||
var privateToken = process.env && (process.env.ALL_CONTRIBUTORS_PRIVATE_TOKEN || process.env.PRIVATE_TOKEN) || ''; | ||
@@ -32,3 +30,2 @@ var SUPPORTED_REPO_TYPES = { | ||
}; | ||
var getChoices = function () { | ||
@@ -44,3 +41,2 @@ return Object.keys(SUPPORTED_REPO_TYPES).map(function (key) { | ||
}; | ||
var getHostname = function (repoType, repoHost) { | ||
@@ -52,6 +48,4 @@ if (repoHost) { | ||
} | ||
return null; | ||
}; | ||
var getCheckKey = function (repoType) { | ||
@@ -61,6 +55,4 @@ if (repoType in SUPPORTED_REPO_TYPES) { | ||
} | ||
return null; | ||
}; | ||
var getTypeName = function (repoType) { | ||
@@ -70,6 +62,4 @@ if (repoType in SUPPORTED_REPO_TYPES) { | ||
} | ||
return null; | ||
}; | ||
var getLinkToCommits = function (repoType) { | ||
@@ -79,6 +69,4 @@ if (repoType in SUPPORTED_REPO_TYPES) { | ||
} | ||
return null; | ||
}; | ||
var getLinkToIssues = function (repoType) { | ||
@@ -88,6 +76,4 @@ if (repoType in SUPPORTED_REPO_TYPES) { | ||
} | ||
return null; | ||
}; | ||
var getLinkToReviews = function (repoType) { | ||
@@ -97,6 +83,4 @@ if (repoType in SUPPORTED_REPO_TYPES) { | ||
} | ||
return null; | ||
}; | ||
var getUserInfo = function (username, repoType, repoHost) { | ||
@@ -106,6 +90,4 @@ if (repoType in SUPPORTED_REPO_TYPES) { | ||
} | ||
return null; | ||
}; | ||
var getContributors = function (owner, name, repoType, repoHost) { | ||
@@ -115,6 +97,4 @@ if (repoType in SUPPORTED_REPO_TYPES) { | ||
} | ||
return null; | ||
}; | ||
module.exports = { | ||
@@ -121,0 +101,0 @@ getChoices, |
"use strict"; | ||
var fs = require('fs'); | ||
var pify = require('pify'); | ||
var _ = require('lodash/fp'); | ||
var jf = require('json-fixer'); | ||
function readConfig(configPath) { | ||
try { | ||
var _jf = jf(fs.readFileSync(configPath, 'utf-8')), | ||
config = _jf.data, | ||
changed = _jf.changed; | ||
config = _jf.data, | ||
changed = _jf.changed; | ||
if (!('repoType' in config)) { | ||
config.repoType = 'github'; | ||
} | ||
if (!('commitConvention' in config)) { | ||
config.commitConvention = 'angular'; | ||
} | ||
if (changed) { | ||
@@ -29,3 +22,2 @@ //Updates the file with fixes | ||
} | ||
return config; | ||
@@ -36,11 +28,8 @@ } catch (error) { | ||
} | ||
if (error.code === 'ENOENT') { | ||
throw new Error(`Configuration file not found: ${configPath}`); | ||
} | ||
throw error; | ||
} | ||
} | ||
function writeConfig(configPath, content) { | ||
@@ -50,17 +39,12 @@ if (!content.projectOwner) { | ||
} | ||
if (!content.projectName) { | ||
throw new Error(`Error! Project name is not set in ${configPath}`); | ||
} | ||
if (content.files && !content.files.length) { | ||
throw new Error(`Error! Project files was overridden and is empty in ${configPath}`); | ||
} | ||
return pify(fs.writeFile)(configPath, `${JSON.stringify(content, null, 2)}\n`); | ||
} | ||
function writeContributors(configPath, contributors) { | ||
var config; | ||
try { | ||
@@ -71,10 +55,7 @@ config = readConfig(configPath); | ||
} | ||
var content = _.assign(config, { | ||
contributors | ||
}); | ||
return writeConfig(configPath, content); | ||
} | ||
module.exports = { | ||
@@ -81,0 +62,0 @@ readConfig, |
"use strict"; | ||
var _ = require('lodash/fp'); | ||
var repo = require('../repo'); | ||
var defaultTypes = function (repoType) { | ||
@@ -148,5 +146,4 @@ return { | ||
}; | ||
module.exports = function (options) { | ||
return _.assign(defaultTypes(options.repoType), options.types); | ||
}; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var path = require('path'); | ||
var spawn = require('child_process').spawn; | ||
var _ = require('lodash/fp'); | ||
var pify = require('pify'); | ||
var conventions = require('../init/commit-conventions'); | ||
var _require = require('./config-file'), | ||
readConfig = _require.readConfig; | ||
readConfig = _require.readConfig; | ||
var commitTemplate = '<%= prefix %> <%= (newContributor ? "Add" : "Update") %> @<%= username %> as a contributor'; | ||
@@ -32,10 +24,7 @@ var getRemoteOriginData = pify(function (cb) { | ||
}); | ||
function parse(originUrl) { | ||
var result = /:(\w+)\/([A-Za-z0-9-_]+)/.exec(originUrl); | ||
if (!result) { | ||
return null; | ||
} | ||
return { | ||
@@ -46,7 +35,5 @@ projectOwner: result[1], | ||
} | ||
function getRepoInfo() { | ||
return getRemoteOriginData().then(parse); | ||
} | ||
var spawnGitCommand = pify(function (args, cb) { | ||
@@ -67,3 +54,2 @@ var git = spawn('git', args); | ||
}); | ||
function commit(options, data) { | ||
@@ -80,3 +66,2 @@ var files = options.files.concat(options.config); | ||
})); | ||
if (commitConvention.lowercase) commitMessage = commitConvention.transform(commitMessage); | ||
@@ -86,3 +71,2 @@ return spawnGitCommand(['commit', '-m', commitMessage]); | ||
} | ||
module.exports = { | ||
@@ -89,0 +73,0 @@ commit, |
"use strict"; | ||
var fs = require('fs'); | ||
var pify = require('pify'); | ||
function read(filePath) { | ||
return pify(fs.readFile)(filePath, 'utf8'); | ||
} | ||
function write(filePath, content) { | ||
return pify(fs.writeFile)(filePath, content); | ||
} | ||
function injectContentBetween(lines, content, startIndex, endIndex) { | ||
return [].concat(lines.slice(0, startIndex), content, lines.slice(endIndex)); | ||
} | ||
module.exports = { | ||
@@ -20,0 +15,0 @@ read, |
@@ -6,3 +6,2 @@ "use strict"; | ||
} | ||
function isValidHttpUrl(input) { | ||
@@ -16,3 +15,2 @@ try { | ||
} | ||
function parseHttpUrl(input) { | ||
@@ -22,12 +20,8 @@ if (typeof input !== 'string') { | ||
} | ||
var url = new URL(new RegExp('^\\w+\\:\\/\\/').test(input) ? input : `http://${input}`); | ||
if (!isHttpProtocol(url.protocol)) { | ||
throw new TypeError('Provided URL has an invalid protocol'); | ||
} | ||
return url.toString(); | ||
} | ||
module.exports = { | ||
@@ -34,0 +28,0 @@ isHttpProtocol, |
{ | ||
"name": "all-contributors-cli", | ||
"version": "6.23.1", | ||
"version": "6.24.0", | ||
"description": "Tool to easily add recognition for new contributors", | ||
@@ -5,0 +5,0 @@ "bin": { |
@@ -169,4 +169,15 @@ <!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<td align="center"><a href="https://12rambau.github.io/web-resume/"><img src="https://avatars.githubusercontent.com/u/12596392?v=4?s=100" width="100px;" alt="Rambaud Pierrick"/><br /><sub><b>Rambaud Pierrick</b></sub></a><br /><a href="https://github.com/all-contributors/cli/commits?author=12rambau" title="Code">💻</a></td> | ||
<td align="center"><a href="https://www.lieret.net"><img src="https://avatars.githubusercontent.com/u/13602468?v=4?s=100" width="100px;" alt="Kilian Lieret"/><br /><sub><b>Kilian Lieret</b></sub></a><br /><a href="https://github.com/all-contributors/cli/issues?q=author%3Aklieret" title="Bug reports">🐛</a></td> | ||
<td align="center"><a href="https://github.com/KnorpelSenf"><img src="https://avatars.githubusercontent.com/u/12952387?v=4?s=100" width="100px;" alt="KnorpelSenf"/><br /><sub><b>KnorpelSenf</b></sub></a><br /><a href="https://github.com/all-contributors/cli/issues?q=author%3AKnorpelSenf" title="Bug reports">🐛</a></td> | ||
</tr> | ||
</tbody> | ||
<tfoot> | ||
<tr> | ||
<td align="center" size="13px" colspan="6"> | ||
<img src="https://raw.githubusercontent.com/all-contributors/all-contributors-cli/1b8533af435da9854653492b1327a23a4dbd0a10/assets/logo-small.svg"> | ||
<a href="https://all-contributors.js.org/docs/en/bot/usage">Add your contributions</a> | ||
</img> | ||
</td> | ||
</tr> | ||
</tfoot> | ||
</table> | ||
@@ -173,0 +184,0 @@ |
77326
1294
196