1
0
Fork 0
mirror of https://github.com/actions/setup-node synced 2024-12-26 07:02:41 +00:00
setup-node/node_modules/@octokit/rest/plugins/pagination/paginate.js
Danny McCormick 5273d0df9c Add auth
2019-08-06 18:29:44 -04:00

34 lines
808 B
JavaScript

module.exports = paginate
const iterator = require('./iterator')
function paginate (octokit, route, options, mapFn) {
if (typeof options === 'function') {
mapFn = options
options = undefined
}
options = octokit.request.endpoint.merge(route, options)
return gather(octokit, [], iterator(octokit, options)[Symbol.asyncIterator](), mapFn)
}
function gather (octokit, results, iterator, mapFn) {
return iterator.next()
.then(result => {
if (result.done) {
return results
}
let earlyExit = false
function done () {
earlyExit = true
}
results = results.concat(mapFn ? mapFn(result.value, done) : result.value.data)
if (earlyExit) {
return results
}
return gather(octokit, results, iterator, mapFn)
})
}