* 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)
| 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 | |
| 285 | module.exports = Requestable; |
no test coverage detected