getcontributors
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -1,19 +0,68 @@ | ||
// Generated by CoffeeScript 1.6.2 | ||
var __hasProp = {}.hasOwnProperty; | ||
// Generated by CoffeeScript 1.6.3 | ||
var GetContributors, TaskGroup, eachr, extendr, extractOpts, typeChecker, | ||
__slice = [].slice; | ||
module.exports = function(opts, next) { | ||
var TaskGroup, addContributor, balUtil, contributors, eachr, extendr, feedr, tasks, typeChecker, user, userRepoFeed, userRepoFeeds, _i, _len, _ref, _ref1; | ||
typeChecker = require('typechecker'); | ||
feedr = new (require('feedr').Feedr)(opts); | ||
balUtil = require('bal-util'); | ||
eachr = require('eachr'); | ||
extendr = require('extendr'); | ||
TaskGroup = require('taskgroup').TaskGroup; | ||
typeChecker = require('typechecker'); | ||
_ref = balUtil.extractOptsAndCallback(opts, next), opts = _ref[0], next = _ref[1]; | ||
contributors = {}; | ||
addContributor = function(repo, contributor) { | ||
var contributorData, existingContributorData, usernameMatch, _base, _name, _ref1, _ref2; | ||
extendr = require('extendr'); | ||
contributorData = extendr.extend({ | ||
eachr = require('eachr'); | ||
extractOpts = require('extract-opts').extractOpts; | ||
TaskGroup = require('taskgroup').TaskGroup; | ||
GetContributors = (function() { | ||
GetContributors.prototype.contributorsMap = null; | ||
GetContributors.prototype.config = null; | ||
function GetContributors(opts) { | ||
var _base, _base1; | ||
if (opts == null) { | ||
opts = {}; | ||
} | ||
this.config = {}; | ||
this.contributorsMap = {}; | ||
extendr.extend(this.config, opts); | ||
if ((_base = this.config).githubClientId == null) { | ||
_base.githubClientId = process.env.GITHUB_CLIENT_ID || null; | ||
} | ||
if ((_base1 = this.config).githubClientSecret == null) { | ||
_base1.githubClientSecret = process.env.GITHUB_CLIENT_SECRET || null; | ||
} | ||
this.feedr = new (require('feedr').Feedr)(this.config); | ||
this; | ||
} | ||
GetContributors.prototype.log = function() { | ||
var args, _base; | ||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
if (typeof (_base = this.config).log === "function") { | ||
_base.log.apply(_base, args); | ||
} | ||
return this; | ||
}; | ||
GetContributors.prototype.addContributor = function(contributor) { | ||
var contributorData, existingContributorData, _base, _base1, _name; | ||
this.log('debug', 'Adding the contributor:', contributor); | ||
contributorData = this.prepareContributor(contributor); | ||
if (!contributorData.username) { | ||
return null; | ||
} | ||
contributorData.id = contributorData.username.toLowerCase(); | ||
existingContributorData = (_base = this.contributorsMap)[_name = contributorData.id] != null ? (_base = this.contributorsMap)[_name = contributorData.id] : _base[_name] = {}; | ||
extendr.safeDeepExtendPlainObjects(existingContributorData, contributorData); | ||
this.contributorsMap[contributorData.id] = existingContributorData; | ||
if ((_base1 = this.contributorsMap[contributorData.id]).repos == null) { | ||
_base1.repos = {}; | ||
} | ||
return existingContributorData; | ||
}; | ||
GetContributors.prototype.prepareContributor = function(contributor) { | ||
var contributorData, usernameMatch; | ||
this.log('debug', 'Preparing the contributor:', contributor); | ||
contributorData = extendr.safeDeepExtendPlainObjects({ | ||
name: null, | ||
@@ -32,37 +81,25 @@ email: null, | ||
} | ||
if (!contributorData.username) { | ||
return; | ||
return contributorData; | ||
}; | ||
GetContributors.prototype.prepareContributorFinale = function(contributorData) { | ||
this.log('debug', 'Preparing the contributor for the final time:', contributorData); | ||
contributorData.name || (contributorData.name = contributorData.username); | ||
contributorData.url || (contributorData.url = "https://github.com/" + contributorData.username); | ||
contributorData.text = []; | ||
contributorData.text.push(contributorData.name); | ||
if (contributorData.email) { | ||
contributorData.text.push("<" + contributorData.email + ">"); | ||
} | ||
contributorData.id = contributorData.username.toLowerCase(); | ||
existingContributorData = (_ref1 = contributors[_name = contributorData.id]) != null ? _ref1 : contributors[_name] = {}; | ||
extendr.safeShallowExtendPlainObjects(existingContributorData, contributorData); | ||
contributors[contributorData.id] = existingContributorData; | ||
return ((_ref2 = (_base = contributors[contributorData.id]).repos) != null ? _ref2 : _base.repos = {})[repo.name] = repo.html_url; | ||
contributorData.text.push("(" + contributorData.url + ")"); | ||
contributorData.text = contributorData.text.join(' ') || null; | ||
return contributorData; | ||
}; | ||
if (typeof opts.log === "function") { | ||
opts.log('info', "Fetching Contributors..."); | ||
} | ||
tasks = new TaskGroup().setConfig({ | ||
concurrency: 0 | ||
}).once('complete', function(err) { | ||
var comparator, contributorData, contributorsSortedArray, contributorsSortedObject, ensurer, key; | ||
if (err) { | ||
return next(err); | ||
} | ||
ensurer = function(contributorData) { | ||
contributorData.name || (contributorData.name = contributorData.username); | ||
contributorData.url || (contributorData.url = "https://github.com/" + contributorData.username); | ||
contributorData.text = []; | ||
contributorData.text.push(contributorData.name); | ||
if (contributorData.email) { | ||
contributorData.text.push("<" + contributorData.email + ">"); | ||
} | ||
contributorData.text.push("(" + contributorData.url + ")"); | ||
contributorData.text = contributorData.text.join(' ') || null; | ||
return contributorData; | ||
}; | ||
comparator = function(a, b) { | ||
GetContributors.prototype.getContributors = function() { | ||
var contributors, contributorsComparator, | ||
_this = this; | ||
this.log('debug', 'Get contributors'); | ||
contributorsComparator = function(a, b) { | ||
var A, B; | ||
A = a.name.toLowerCase(); | ||
@@ -78,109 +115,143 @@ B = b.name.toLowerCase(); | ||
}; | ||
contributorsSortedArray = ((function() { | ||
var _results; | ||
contributors = Object.keys(this.contributorsMap).map(function(key) { | ||
return _this.contributorsMap[key]; | ||
}).map(this.prepareContributorFinale.bind(this)).sort(contributorsComparator); | ||
return contributors; | ||
}; | ||
_results = []; | ||
for (key in contributors) { | ||
if (!__hasProp.call(contributors, key)) continue; | ||
contributorData = contributors[key]; | ||
_results.push(contributorData); | ||
GetContributors.prototype.fetchContributorsFromUsers = function(users, next) { | ||
var me, userRepoFeeds, | ||
_this = this; | ||
this.log('debug', 'Get contributors from users:', users); | ||
me = this; | ||
userRepoFeeds = users.map(function(user) { | ||
return "https://api.github.com/users/" + user + "/repos?per_page=100&client_id=" + _this.config.githubClientId + "&client_secret=" + _this.config.githubClientSecret; | ||
}); | ||
this.feedr.readFeeds(userRepoFeeds, function(err, repoFeedResult) { | ||
var repoNames; | ||
if (err) { | ||
return next(err); | ||
} | ||
return _results; | ||
})()).map(ensurer).sort(comparator); | ||
contributorsSortedObject = (function() { | ||
var _i, _len, _results; | ||
_results = []; | ||
for (_i = 0, _len = contributorsSortedArray.length; _i < _len; _i++) { | ||
contributorData = contributorsSortedArray[_i]; | ||
_results.push(contributors[contributorData.id]); | ||
} | ||
return _results; | ||
})(); | ||
if (typeof opts.log === "function") { | ||
opts.log('info', "Fetched Contributors"); | ||
} | ||
return next(null, contributorsSortedObject); | ||
}); | ||
userRepoFeeds = []; | ||
_ref1 = opts.users; | ||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { | ||
user = _ref1[_i]; | ||
userRepoFeed = "https://api.github.com/users/" + user + "/repos?per_page=100&client_id=" + opts.github_client_id + "&client_secret=" + opts.github_client_secret; | ||
userRepoFeeds.push(userRepoFeed); | ||
} | ||
feedr.readFeeds(userRepoFeeds, function(err, repoFeedResult) { | ||
eachr(repoFeedResult, function(repos) { | ||
if (repos.message) { | ||
return typeof opts.log === "function" ? opts.log('warn', repos.message) : void 0; | ||
} else { | ||
return eachr(repos, function(repo) { | ||
var contributorsUrl, packageUrl; | ||
if (repo.fork === true) { | ||
repoNames = []; | ||
eachr(repoFeedResult, function(repos) { | ||
if (repos.message) { | ||
return next(new Error(repos.message)); | ||
} | ||
return eachr(repos, function(repoData) { | ||
if (repoData.fork === true) { | ||
return; | ||
} | ||
contributorsUrl = "https://api.github.com/repos/" + repo.full_name + "/contributors?per_page=100&client_id=" + opts.github_client_id + "&client_secret=" + opts.github_client_secret; | ||
tasks.addTask(function(complete) { | ||
return feedr.readFeed(contributorsUrl, function(err, contributors) { | ||
var contributor, contributorData, _j, _len1, _ref2; | ||
return repoNames.push(repoData.full_name); | ||
}); | ||
}); | ||
return me.fetchContributorsFromRepos(repoNames, next); | ||
}); | ||
return this; | ||
}; | ||
if (err || !contributors) { | ||
return complete(); | ||
} | ||
_ref2 = contributors || []; | ||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { | ||
contributor = _ref2[_j]; | ||
contributorData = { | ||
url: contributor.html_url, | ||
username: contributor.login | ||
}; | ||
addContributor(repo, contributorData); | ||
} | ||
return complete(); | ||
}); | ||
}); | ||
packageUrl = repo.html_url.replace('//github.com', '//raw.github.com') + '/master/package.json'; | ||
return tasks.addTask(function(complete) { | ||
return feedr.readFeed(packageUrl, function(err, packageData) { | ||
var contributor, contributorData, contributorMatch, _j, _len1, _ref2; | ||
GetContributors.prototype.fetchContributorsFromRepos = function(repos, next) { | ||
var me, tasks; | ||
this.log('debug', 'Get contributors from repos:', repos); | ||
me = this; | ||
tasks = new TaskGroup().setConfig({ | ||
concurrency: 0 | ||
}).once('complete', next); | ||
eachr(repos, function(repo) { | ||
tasks.addTask(function(complete) { | ||
return me.fetchContributorsFromPackage(repo, complete); | ||
}); | ||
return tasks.addTask(function(complete) { | ||
return me.fetchContributorsFromRepo(repo, complete); | ||
}); | ||
}); | ||
tasks.run(); | ||
return this; | ||
}; | ||
if (err || !packageData) { | ||
return complete(); | ||
} | ||
_ref2 = packageData.contributors || []; | ||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { | ||
contributor = _ref2[_j]; | ||
contributorData = {}; | ||
if (typeChecker.isString(contributor)) { | ||
contributorMatch = /^([^<(]+)\s*(?:<(.+?)>)?\s*(?:\((.+?)\))?$/.exec(contributor); | ||
if (!contributorMatch) { | ||
continue; | ||
} | ||
contributorData = { | ||
name: (contributorMatch[1] || '').trim() || null, | ||
email: (contributorMatch[2] || '').trim() || null, | ||
url: (contributorMatch[3] || '').trim() || null | ||
}; | ||
} else if (typeChecker.isPlainObject(contributor)) { | ||
contributorData = { | ||
name: contributor.name || null, | ||
email: contributor.email || null, | ||
url: contributor.web || null, | ||
username: contributor.username || null | ||
}; | ||
} else { | ||
continue; | ||
} | ||
addContributor(repo, contributorData); | ||
} | ||
return complete(); | ||
}); | ||
}); | ||
}); | ||
GetContributors.prototype.fetchContributorsFromPackage = function(repo, next) { | ||
var me, packageUrl; | ||
this.log('debug', 'Get contributors from package:', repo); | ||
me = this; | ||
packageUrl = "http://raw.github.com/" + repo + "/master/package.json"; | ||
this.feedr.readFeed(packageUrl, function(err, packageData) { | ||
var contributor, contributorData, contributorMatch, _i, _len, _ref; | ||
if (err || (packageData == null)) { | ||
return next(); | ||
} | ||
_ref = [].concat(packageData.contributors || []).concat(packageData.maintainers || []); | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
contributor = _ref[_i]; | ||
contributorData = {}; | ||
if (typeChecker.isString(contributor)) { | ||
contributorMatch = /^([^<(]+)\s*(?:<(.+?)>)?\s*(?:\((.+?)\))?$/.exec(contributor); | ||
if (!contributorMatch) { | ||
continue; | ||
} | ||
contributorData = { | ||
name: (contributorMatch[1] || '').trim() || null, | ||
email: (contributorMatch[2] || '').trim() || null, | ||
url: (contributorMatch[3] || '').trim() || null, | ||
repos: {} | ||
}; | ||
} else if (typeChecker.isPlainObject(contributor)) { | ||
contributorData = { | ||
name: contributor.name || null, | ||
email: contributor.email || null, | ||
url: contributor.web || null, | ||
username: contributor.username || null, | ||
repos: {} | ||
}; | ||
} else { | ||
continue; | ||
} | ||
contributorData.repos[repo] = "https://github.com/" + repo; | ||
me.addContributor(contributorData); | ||
} | ||
return next(); | ||
}); | ||
return tasks.run(); | ||
}); | ||
return this; | ||
return this; | ||
}; | ||
GetContributors.prototype.fetchContributorsFromRepo = function(repo, next) { | ||
var contributorsUrl, me; | ||
this.log('debug', 'Get contributors from repo:', repo); | ||
me = this; | ||
contributorsUrl = "https://api.github.com/repos/" + repo + "/contributors?per_page=100&client_id=" + this.config.githubClientId + "&client_secret=" + this.config.githubClientSecret; | ||
this.feedr.readFeed(contributorsUrl, function(err, result) { | ||
var contributor, contributorData, _i, _len; | ||
if (result == null) { | ||
result = []; | ||
} | ||
if (err || !(result != null ? result.length : void 0)) { | ||
return next(); | ||
} | ||
for (_i = 0, _len = result.length; _i < _len; _i++) { | ||
contributor = result[_i]; | ||
contributorData = { | ||
url: contributor.html_url, | ||
username: contributor.login, | ||
repos: {} | ||
}; | ||
contributorData.repos[repo] = "https://github.com/" + repo; | ||
me.addContributor(contributorData); | ||
} | ||
return next(); | ||
}); | ||
return this; | ||
}; | ||
return GetContributors; | ||
})(); | ||
module.exports = { | ||
create: function() { | ||
var args; | ||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
return (function(func, args, ctor) { | ||
ctor.prototype = func.prototype; | ||
var child = new ctor, result = func.apply(child, args); | ||
return Object(result) === result ? result : child; | ||
})(GetContributors, args, function(){}); | ||
} | ||
}; |
102
package.json
{ | ||
"name": "getcontributors", | ||
"version": "1.1.1", | ||
"description": "Fetch the contributors of the repositories of the specified github users", | ||
"homepage": "https://github.com/bevry/getcontributors", | ||
"keywords": [ | ||
"contributors","package.json","github","organisation","organization","users","owners","maintainers" | ||
], | ||
"author": "Benjamin Lupton <b@lupton.cc> (http://balupton.com)", | ||
"maintainers": [ | ||
"Benjamin Lupton <b@lupton.cc> (https://github.com/balupton)" | ||
], | ||
"contributors": [ | ||
"Benjamin Lupton <b@lupton.cc> (https://github.com/balupton)" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/bevry/getcontributors/issues" | ||
}, | ||
"repository" : { | ||
"type": "git", | ||
"url": "http://github.com/bevry/getcontributors.git" | ||
}, | ||
"engines" : { | ||
"node": ">=0.4" | ||
}, | ||
"dependencies": { | ||
"bal-util": "~2.0.0", | ||
"extendr": "~2.0.1", | ||
"taskgroup": "~3.1.2", | ||
"eachr": "~2.0.2", | ||
"typechecker": "~2.0.1", | ||
"feedr": "~2.4.2" | ||
}, | ||
"devDependencies": { | ||
"coffee-script": "~1.6.2", | ||
"joe": "~1.2.0", | ||
"joe-reporter-console": "~1.2.1", | ||
"chai": "~1.6.0" | ||
}, | ||
"directories": { | ||
"lib": "./out/lib" | ||
}, | ||
"scripts": { | ||
"test": "node ./out/test/everything-test.js" | ||
}, | ||
"main": "./out/lib/getcontributors.js" | ||
} | ||
"name": "getcontributors", | ||
"version": "1.2.0", | ||
"description": "Fetch the contributors of the repositories of the specified github users", | ||
"homepage": "https://github.com/bevry/getcontributors", | ||
"keywords": [ | ||
"contributors", | ||
"package.json", | ||
"github", | ||
"organisation", | ||
"organization", | ||
"users", | ||
"owners", | ||
"maintainers" | ||
], | ||
"author": "Benjamin Lupton <b@lupton.cc> (http://balupton.com)", | ||
"maintainers": [ | ||
"Benjamin Lupton <b@lupton.cc> (https://github.com/balupton)" | ||
], | ||
"contributors": [ | ||
"Benjamin Lupton <b@lupton.cc> (https://github.com/balupton)" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/bevry/getcontributors/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "http://github.com/bevry/getcontributors.git" | ||
}, | ||
"engines": { | ||
"node": ">=0.4" | ||
}, | ||
"dependencies": { | ||
"extendr": "~2.1.0", | ||
"taskgroup": "~3.2.3", | ||
"eachr": "~2.0.2", | ||
"typechecker": "~2.0.1", | ||
"feedr": "~2.5.1", | ||
"extract-opts": "~2.2.0", | ||
"caterpillar-filter": "~2.0.1", | ||
"caterpillar-human": "~2.1.0", | ||
"caterpillar": "~2.0.4" | ||
}, | ||
"devDependencies": { | ||
"coffee-script": "~1.6.2", | ||
"joe": "~1.3.0", | ||
"joe-reporter-console": "~1.2.1", | ||
"chai": "~1.8.0" | ||
}, | ||
"directories": { | ||
"lib": "./out/lib" | ||
}, | ||
"scripts": { | ||
"test": "node ./out/test/everything-test.js" | ||
}, | ||
"main": "./out/lib/getcontributors.js" | ||
} |
@@ -20,12 +20,24 @@ # Get Contributors | ||
``` javascript | ||
require('getcontributors')({ | ||
users: ['bevry'], | ||
github_client_id: null, // optional | ||
github_client_secret: null, // optional | ||
log: console.log, // args: level, message... | ||
next: console.log // args: err, contributors | ||
}) | ||
// Create our contributors instance | ||
var contributors = require('getcontributors').create({ | ||
githubClientId: null, // optional, will try process.env.GITHUB_CLIENT_ID | ||
githubClientSecret: null, // optional, will try process.env.GITHUB_CLIENT_SECRET | ||
log: console.log // optional, arguments: level, message... | ||
}); | ||
// Fetch all the contributors on these github repositories | ||
contributors.fetchContributorsFromRepos(['bevry/getcontributors'], function(err){ | ||
console.log(err); | ||
// Fetch all the contributors on these github users/organisations | ||
contributors.fetchContributorsFromUsers(['bevry'], function(err){ | ||
console.log(err); | ||
// Get the combined listing | ||
console.log(contributors.getContributors()); | ||
}); | ||
}); | ||
``` | ||
Contributors are returned as an array of contributor objects, here is an examply contributor object: | ||
Contributors are returned as an array of contributor objects, here is an example contributor object: | ||
@@ -40,4 +52,4 @@ ``` javascript | ||
repos: { | ||
docpad: "https://github.com/bevry/docpad", | ||
getcontributors: "https://github.com/bevry/getcontributors" | ||
"bevry/docpad": "https://github.com/bevry/docpad", | ||
"bevry/getcontributors": "https://github.com/bevry/getcontributors" | ||
// ... | ||
@@ -50,3 +62,2 @@ } | ||
## History | ||
You can discover the history inside the `History.md` file | ||
@@ -56,4 +67,3 @@ | ||
## License | ||
Licensed under the incredibly [permissive](http://en.wikipedia.org/wiki/Permissive_free_software_licence) [MIT License](http://creativecommons.org/licenses/MIT/) | ||
<br/>Copyright © 2012 [Bevry Pty Ltd](http://bevry.me) | ||
<br/>Copyright © 2012+ [Bevry Pty Ltd](http://bevry.me) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15314
235
66
9
2
1
+ Addedcaterpillar@~2.0.4
+ Addedcaterpillar-filter@~2.0.1
+ Addedcaterpillar-human@~2.1.0
+ Addedextract-opts@~2.2.0
+ Addedambi@2.5.0(transitive)
+ Addedansicolors@0.3.2(transitive)
+ Addedansistyles@0.1.3(transitive)
+ Addedbal-util@2.2.0(transitive)
+ Addedcaterpillar@2.0.9(transitive)
+ Addedcaterpillar-filter@2.0.3(transitive)
+ Addedcaterpillar-human@2.1.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedcsextends@1.2.0(transitive)
+ Addededitions@2.3.1(transitive)
+ Addederrlop@2.2.0(transitive)
+ Addedextendr@2.1.0(transitive)
+ Addedextract-opts@2.2.0(transitive)
+ Addedfeedr@2.5.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedreadable-stream@1.1.14(transitive)
+ Addedsafefs@3.2.2(transitive)
+ Addedsafeps@2.2.13(transitive)
+ Addedsemver@6.3.1(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedtaskgroup@3.2.44.3.1(transitive)
+ Addedtypechecker@4.11.0(transitive)
- Removedbal-util@~2.0.0
- Removedbal-util@2.0.5(transitive)
- Removedfeedr@2.4.4(transitive)
Updatedextendr@~2.1.0
Updatedfeedr@~2.5.1
Updatedtaskgroup@~3.2.3