Skip to content

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

roryabraham
Copy link

Resolves #647

Before the change?

  • compareCommits and compareCommitsWithBasehead are not correctly paginated.

After the change?

  • compareCommits and compareCommitsWithBasehead are paginated

Pull request checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

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!

  • Yes
  • No

Copy link
Contributor

👋 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 Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

Comment on lines +43 to +53
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();
}
}

Copy link
Member

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?

Copy link
Author

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

Copy link
Member

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

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

Successfully merging this pull request may close these issues.

[FEAT]: Add pagination support for compareCommitsWithBasehead()
2 participants