Add pagination to search endpoints by alaycock · Pull Request #583 · github-tools/github · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Add pagination to search endpoints #583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alaycock
Copy link

@alaycock alaycock commented Sep 6, 2019

Changes:

  • Updated the jsdoc to correctly document the Github.search function.
  • If a page option is passed into _requestAllPages, it will only fetch that single page, instead of attempting to fetch all of the pages.
  • Removed the results parameter from _requestAllPages, since that is only meant to be used internally anyway. It's trivial to re-introduce, so let me know if this makes sense to do, since this could break some backwards compatibility if folks are using an unsupported argument.
  • Added a test for pagination, and a new fixture for that test. Fixed a number of other fixtures that didn't seem to have the correct page number.
  • Changed the fixtures to use rawHeader instead of header, since the tests were not paginating. This was introduced when the spec for fixture files changed from nock@7 to nock@8.

Let me know if this is the right approach. I've only run tests for the search endpoints (due to lack of access to the testing repo), so I'm not sure if this is going to introduce errors elsewhere.

Closes #406
This could be a potential solution for #460, although introducing a limit could be an alternate solution.

@@ -91,11 +91,11 @@ class GitHub {

/**
* Create a new Search wrapper
* @param {string} query - the query to search for
* @param {Search.Params} searchParameters - the query and other search parameters
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if jsdoc understands how to reach into other files (Search.js). Let me know if this will be a problem.

@@ -256,19 +273,19 @@ class Requestable {
results.push(...thisGroup);

const nextUrl = getNextPage(response.headers.link);
if(nextUrl) {
if(nextUrl && !manualPagination) {
if (!options) {
options = {};
}
options.page = parseInt(
Copy link
Author

@alaycock alaycock Sep 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone can clarify this, I would appreciate it.

Why does the page number need to be manually extracted and appended to the options?

nextUrl is being extracted from the headers, wouldn't it have all the options it already needs? Then by calling this._requestAllPages(nextUrl, options, cb, results); the options are being re-added to the url, which results in duplicate parameters in the path, eg:

/search/repositories?q=tetris+language%3Aassembly&sort=stars&order=desc&type=all&per_page=100&page=4&q=tetris+language:assembly&sort=stars&order=desc&type=all&per_page=100&page=4

Although this might just be a workaround for other endpoints, since I have't done exploration into how other endpoints paginate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Ability to fetch a single page of items in a list
1 participant

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.