-
Notifications
You must be signed in to change notification settings - Fork 27
feat: Paginate compareCommits and compareCommitsWithBasehead #678
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
base: main
Are you sure you want to change the base?
feat: Paginate compareCommits and compareCommitsWithBasehead #678
Conversation
👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with |
if (!url && "total_commits" in normalizedResponse.data) { | ||
const parsedUrl = new URL(normalizedResponse.url); | ||
const params = parsedUrl.searchParams; | ||
const page = parseInt(params.get('page') || '1', 10) | ||
const per_page = parseInt(params.get('per_page') || '250', 10); | ||
if (page * per_page < normalizedResponse.data.total_commits) { | ||
params.set('page', String(page + 1)); | ||
url = parsedUrl.toString(); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why this is necessary?
Don't the existing methods do this already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, the other methods rely on response.headers.link
, which is not present in responses to compareCommits
or compareCommitsWithBasehead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems like an oversight on GitHub's part, their page on pagination says to use the link
header
https://docs.github.com/en/rest/using-the-rest-api/using-pagination-in-the-rest-api?apiVersion=2022-11-28#using-link-headers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test that covers this?
Resolves #647
Before the change?
compareCommits
andcompareCommitsWithBasehead
are not correctly paginated.After the change?
compareCommits
andcompareCommitsWithBasehead
are paginatedPull request checklist
Does this introduce a breaking change?
No breaking changes (unless someone is using paginate with
compareCommits
, which doesn't work).Please see our docs on breaking changes to help!