MCPcopy
hub / github.com/github-tools/github / _requestAllPages

Method _requestAllPages

lib/Requestable.js:242–282  ·  view source on GitHub ↗

* Make a request and fetch all the available data. Github will paginate responses so for queries * that might span multiple pages this method is preferred to Requestable#request * @param {string} path - the path to request * @param {Object} options - the query parameters to inclu

(path, options, cb, results)

Source from the content-addressed store, hash-verified

240 * @deprecated This will be folded into {@link Requestable#_request} in the 2.0 release.
241 */
242 _requestAllPages(path, options, cb, results) {
243 results = results || [];
244
245 return this._request('GET', path, options)
246 .then((response) => {
247 let thisGroup;
248 if (response.data instanceof Array) {
249 thisGroup = response.data;
250 } else if (response.data.items instanceof Array) {
251 thisGroup = response.data.items;
252 } else {
253 let message = `cannot figure out how to append ${response.data} to the result set`;
254 throw new ResponseError(message, path, response);
255 }
256 results.push(...thisGroup);
257
258 const nextUrl = getNextPage(response.headers.link);
259 if(nextUrl) {
260 if (!options) {
261 options = {};
262 }
263 options.page = parseInt(
264 nextUrl.match(/([&\?]page=[0-9]*)/g)
265 .shift()
266 .split('=')
267 .pop()
268 );
269 if (!(options && typeof options.page !== 'number')) {
270 log(`getting next page: ${nextUrl}`);
271 return this._requestAllPages(nextUrl, options, cb, results);
272 }
273 }
274
275 if (cb) {
276 cb(null, results, response);
277 }
278
279 response.data = results;
280 return response;
281 }).catch(callbackErrorOrThrow(cb, path));
282 }
283}
284
285module.exports = Requestable;

Callers 15

getReposMethod · 0.80
getTeamsMethod · 0.80
listProjectsMethod · 0.80
listCommitsMethod · 0.80
listCommentsMethod · 0.80
listIssuesMethod · 0.80
listReposMethod · 0.80
listMembersMethod · 0.80
listProjectColumnsMethod · 0.80
listProjectCardsMethod · 0.80
listColumnCardsMethod · 0.80
_searchMethod · 0.80

Calls 3

_requestMethod · 0.95
callbackErrorOrThrowFunction · 0.85
getNextPageFunction · 0.70

Tested by

no test coverage detected