github-pages-deploy-action/node_modules/@octokit/plugin-paginate-rest/dist-src/iterator.js

27 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-03-02 21:16:42 +08:00
import { normalizePaginatedListResponse } from "./normalize-paginated-list-response";
export function iterator(octokit, route, parameters) {
2020-06-07 00:27:02 +08:00
const options = octokit.request.endpoint(route, parameters);
2020-03-02 21:16:42 +08:00
const method = options.method;
const headers = options.headers;
let url = options.url;
return {
[Symbol.asyncIterator]: () => ({
next() {
if (!url) {
return Promise.resolve({ done: true });
}
2020-06-07 00:27:02 +08:00
return octokit
.request({ method, url, headers })
2020-03-02 21:16:42 +08:00
.then((response) => {
2020-06-07 00:27:02 +08:00
normalizePaginatedListResponse(octokit, url, response);
2020-03-02 21:16:42 +08:00
// `response.headers.link` format:
// '<https://api.github.com/users/aseemk/followers?page=2>; rel="next", <https://api.github.com/users/aseemk/followers?page=2>; rel="last"'
// sets `url` to undefined if "next" URL is not present or `link` header is not set
url = ((response.headers.link || "").match(/<([^>]+)>;\s*rel="next"/) || [])[1];
return { value: response };
});
2020-06-07 00:27:02 +08:00
}
})
2020-03-02 21:16:42 +08:00
};
}