lib/unifile-github.js
function paginate(reqOptions, link, memo) {
	const links = link.split(/,\s*/);
	let matches;
	links.some(function(link) {
		matches = link.trim().match(/<(.+)>;\s*rel="next"/);
		return matches !== null;
	});
	// End of pagination
	if(!matches) {
		return Promise.resolve(memo);
	}
	return new Promise(function(resolve, reject) {
		reqOptions.url = matches[1];
		request(reqOptions, function(err, res, body) {
			paginate(reqOptions, res.headers.link, memo.concat(JSON.parse(body))).then(resolve);
		});
	});
}
function paginate(reqOptions, link, memo) {
	const links = link.split(/,\s*/);
	let matches;
	links.some(function(link) {
		matches = link.trim().match(/<(.+)>;\s*rel="next"/);
		return matches !== null;
	});
	// End of pagination
	if(!matches) {
		return Promise.resolve(memo);
	}
	return new Promise(function(resolve, reject) {
		reqOptions.url = matches[1];
		request(reqOptions, function(err, res, body) {
			paginate(reqOptions, res.headers.link, memo.concat(JSON.parse(body))).then(resolve);
		});
	});
}
function paginate ( reqOptions , link , memo ) { const links = link . split ( / ,\s* / ) ; let matches ; links . some ( function ( link ) { matches = link . trim ( ) . match ( / <(.+)>;\s*rel="next" / ) ; return matches !== null ; } ) ; // End of pagination if ( ! matches ) { return Promise . resolve ( memo ) ; } return new Promise ( function ( resolve , reject ) { reqOptions . url = matches [ 1 ] ; request ( reqOptions , function ( err , res , body ) { paginate ( reqOptions , res . headers . link , memo . concat ( JSON . parse ( body ) ) ) . then ( resolve ) ; } ) ; } ) ; }
Handle GitHub pagination
@param  {Object} reqOptions - Options to pass to the request. Url will be overidden
@param  {string} link - Link header
@param  {Object[]} memo - Aggregator of result
@return {Promise} a Promise of aggregated result
@private
Handle GitHub pagination