github-contributors
Advanced tools
Comparing version 0.3.0 to 0.4.0
80
index.js
'use strict'; | ||
var extend = require('extend-shallow'); | ||
var pad = require('right-pad-values'); | ||
var mdu = require('markdown-utils'); | ||
var GitHub = require('github-base'); | ||
var format = {}; | ||
var format = require('format-people'); | ||
module.exports = function contributors(repo, options, cb) { | ||
if (typeof repo !== 'string') { | ||
throw new TypeError('github-contributors expects repo to be a string.'); | ||
} | ||
if (typeof options === 'function') { | ||
@@ -20,69 +13,16 @@ cb = options; | ||
if (typeof cb !== 'function') { | ||
throw new TypeError('github-contributors expects callback to be a function.'); | ||
throw new TypeError('expected callback to be a function.'); | ||
} | ||
if (typeof repo !== 'string') { | ||
cb(new TypeError('expected repo to be a string.')); | ||
return; | ||
} | ||
var opts = extend({format: 'noop'}, options); | ||
var github = new GitHub(opts); | ||
var method = options && options.format || 'noop'; | ||
var github = new GitHub(options); | ||
github.getAll('/repos/:repo/contributors', {repo: repo}, function (err, res) { | ||
github.paged(`/repos/:${repo}/contributors`, function(err, data) { | ||
if (err) return cb(err); | ||
if (!format.hasOwnProperty(opts.format)) { | ||
cb(new Error('github-contributors does not have format: ' + opts.format)); | ||
return; | ||
} | ||
cb(null, format[opts.format](res)); | ||
cb(null, format(data, options)); | ||
}); | ||
}; | ||
format.noop = function noop(arr) { | ||
return arr; | ||
}; | ||
format.table = function table(arr) { | ||
arr = pad(arr, 'contributions'); | ||
var res = '| **Commits** | **Contributor**<br/> | '; | ||
res += '\n'; | ||
res += '| --- | --- | '; | ||
res += '\n'; | ||
arr.forEach(function (person) { | ||
res += '| '; | ||
res += person.contributions; | ||
res += ' | '; | ||
res += mdu.link(person.login, person.html_url); | ||
res += ' | '; | ||
res += '\n'; | ||
}); | ||
return res; | ||
}; | ||
format.list = function list(arr) { | ||
arr = pad(arr, 'contributions'); | ||
var res = '**Commits** / **Contributor**\n'; | ||
arr.forEach(function (person) { | ||
res += '+ '; | ||
res += person.contributions; | ||
res += ' '; | ||
res += mdu.link(person.login, person.html_url); | ||
res += '\n'; | ||
}); | ||
return res; | ||
}; | ||
format.aligned = function aligned(arr) { | ||
arr = pad(arr, 'contributions'); | ||
var res = '```bash\n'; | ||
res += 'COMMITS / CONTRIBUTOR\n'; | ||
res += '------- | -----------\n'; | ||
arr.forEach(function (person) { | ||
res += person.contributions; | ||
res += ' '; | ||
res += person.login; | ||
res += '\n'; | ||
}); | ||
res += '```\n'; | ||
return res; | ||
}; |
{ | ||
"name": "github-contributors", | ||
"description": "Generate a markdown or JSON list of contributors for a project using the GitHub API.", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"homepage": "https://github.com/jonschlinkert/github-contributors", | ||
@@ -13,5 +13,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"files": [ | ||
"index.js", | ||
"LICENSE", | ||
"README.md" | ||
"index.js" | ||
], | ||
@@ -26,11 +24,10 @@ "main": "index.js", | ||
"dependencies": { | ||
"extend-shallow": "^2.0.1", | ||
"github-base": "^0.4.1", | ||
"markdown-utils": "^0.7.3", | ||
"right-pad-values": "^0.3.1" | ||
"format-people": "^0.1.1", | ||
"github-base": "^0.5.0" | ||
}, | ||
"devDependencies": { | ||
"data-store": "^0.16.1", | ||
"extend-shallow": "^2.0.1", | ||
"gulp-format-md": "^0.1.10", | ||
"mocha": "^3.0.2", | ||
"should": "^11.1.0" | ||
"mocha": "^3.0.2" | ||
}, | ||
@@ -37,0 +34,0 @@ "keywords": [ |
# github-contributors [![NPM version](https://img.shields.io/npm/v/github-contributors.svg?style=flat)](https://www.npmjs.com/package/github-contributors) [![NPM downloads](https://img.shields.io/npm/dm/github-contributors.svg?style=flat)](https://npmjs.org/package/github-contributors) [![Build Status](https://img.shields.io/travis/jonschlinkert/github-contributors.svg?style=flat)](https://travis-ci.org/jonschlinkert/github-contributors) | ||
Generate a markdown or JSON list of contributors for a project using the GitHub API. | ||
> Generate a markdown or JSON list of contributors for a project using the GitHub API. | ||
@@ -127,3 +127,3 @@ ## Install | ||
* [get-pkgs](https://www.npmjs.com/package/get-pkgs): Get the package.json for an array of repos from the npm registry, optionally filtering properties… [more](https://github.com/jonschlinkert/get-pkgs) | [homepage](https://github.com/jonschlinkert/get-pkgs "Get the package.json for an array of repos from the npm registry, optionally filtering properties using glob patterns.") | ||
* [github-base](https://www.npmjs.com/package/github-base): Base methods for creating node.js apps that work with the GitHub API. | [homepage](https://github.com/jonschlinkert/github-base "Base methods for creating node.js apps that work with the GitHub API.") | ||
* [github-base](https://www.npmjs.com/package/github-base): JavaScript wrapper that greatly simplifies working with GitHub's API. | [homepage](https://github.com/jonschlinkert/github-base "JavaScript wrapper that greatly simplifies working with GitHub's API.") | ||
@@ -166,2 +166,2 @@ ### Contributing | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.1.30, on August 21, 2016._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.1.30, on September 09, 2016._ |
2
8805
4
22
+ Addedformat-people@^0.1.1
+ Addedcopy-descriptor@0.1.1(transitive)
+ Addeddecompress-response@3.3.0(transitive)
+ Addedformat-people@0.1.4(transitive)
+ Addedgithub-base@0.5.4(transitive)
+ Addedmimic-response@1.0.1(transitive)
+ Addedobject-copy@0.1.0(transitive)
+ Addedsimple-concat@1.0.1(transitive)
+ Addedsimple-get@2.8.2(transitive)
+ Addedstatic-extend@0.1.2(transitive)
+ Addeduse@3.1.1(transitive)
- Removedextend-shallow@^2.0.1
- Removedmarkdown-utils@^0.7.3
- Removedright-pad-values@^0.3.1
- Removedbuffer-from@1.1.2(transitive)
- Removedclone-deep@0.2.4(transitive)
- Removedconcat-stream@1.6.2(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddelegate-properties@0.3.0(transitive)
- Removedfor-in@0.1.8(transitive)
- Removedgithub-base@0.4.1(transitive)
- Removedinherits@2.0.4(transitive)
- Removedkind-of@2.0.1(transitive)
- Removedlazy-cache@0.2.71.0.4(transitive)
- Removedmixin-object@2.0.1(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedshallow-clone@0.1.2(transitive)
- Removedsimple-get@1.4.3(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedtypedarray@0.0.6(transitive)
- Removedunzip-response@1.0.2(transitive)
- Removedutil-deprecate@1.0.2(transitive)
Updatedgithub-base@^0.5.0