mirror of
https://github.com/ASzc/change-string-case-action.git
synced 2024-11-27 20:53:51 +08:00
25 lines
795 B
JavaScript
25 lines
795 B
JavaScript
|
import { iterator } from "./iterator";
|
||
|
export function paginate(octokit, route, parameters, mapFn) {
|
||
|
if (typeof parameters === "function") {
|
||
|
mapFn = parameters;
|
||
|
parameters = undefined;
|
||
|
}
|
||
|
return gather(octokit, [], iterator(octokit, route, parameters)[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);
|
||
|
});
|
||
|
}
|