Comparing version 1.0.0 to 1.1.0
@@ -48,25 +48,31 @@ const jsonist = require('jsonist') | ||
var issues = [] | ||
, optqs = qs.stringify(options) | ||
var url = 'https://api.github.com/repos/' + org + '/' + repo + '/' + type + '?page=' + page + optqs | ||
lister(auth, url, options, callback) | ||
} | ||
} | ||
if (optqs) | ||
optqs = '&' + optqs | ||
//TODO: use 'Link' headers to improve the guesswork here | ||
;(function next (page) { | ||
var url = 'https://api.github.com/repos/' + org + '/' + repo + '/' + type + '?page=' + page + optqs | ||
function lister (auth, urlbase, options, callback) { | ||
var retdata = [] | ||
, optqs = qs.stringify(options) | ||
ghget(auth, url, options, function (err, data) { | ||
if (err) | ||
return callback(err) | ||
if (optqs) | ||
optqs = '&' + optqs | ||
if (!data.length) | ||
return callback(null, issues) | ||
//TODO: use 'Link' headers to improve the guesswork here | ||
;(function next (page) { | ||
var url = urlbase + '?page=' + page + optqs | ||
issues.push.apply(issues, data) | ||
ghget(auth, url, options, function (err, data) { | ||
if (err) | ||
return callback(err) | ||
next(page + 1) | ||
}) | ||
}(1)) | ||
} | ||
if (!data.length) | ||
return callback(null, retdata) | ||
retdata.push.apply(retdata, data) | ||
next(page + 1) | ||
}) | ||
}(1)) | ||
} | ||
@@ -79,2 +85,3 @@ | ||
module.exports.handler = handler | ||
module.exports.issuesList = issuesList | ||
module.exports.issuesList = issuesList | ||
module.exports.lister = lister |
{ | ||
"name": "ghutils", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A collection of utility functions for dealing with the GitHub API", | ||
@@ -5,0 +5,0 @@ "main": "ghutils.js", |
@@ -23,2 +23,6 @@ # ghutils | ||
### lister(auth, urlbase, options, callback) | ||
Given a paginated url resource, recursively fetch all available pages of data and return an array containing the complete list. | ||
### issuesList(type) | ||
@@ -30,2 +34,2 @@ | ||
**ghutils** is Copyright (c) 2015 Rod Vagg [@rvagg](https://twitter.com/rvagg) and licensed under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md file for more details. | ||
**ghutils** is Copyright (c) 2015 Rod Vagg [@rvagg](https://twitter.com/rvagg) and licensed under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md file for more details. |
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
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
5165
60
34