-
Notifications
You must be signed in to change notification settings - Fork 769
1209 GHCompare supports per_page and page params #1214
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
1209 GHCompare supports per_page and page params #1214
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1214 +/- ##
============================================
+ Coverage 74.26% 74.95% +0.68%
- Complexity 1882 1903 +21
============================================
Files 188 188
Lines 6202 6232 +30
Branches 368 371 +3
============================================
+ Hits 4606 4671 +65
+ Misses 1374 1338 -36
- Partials 222 223 +1
Continue to review full report at Codecov.
|
…tps://github.com/ravingbool/github-api into 1209_ghcompare_supports_per_page_and_page+params
|
@bitwiseman please run the checks again, I pushed the test |
|
@bitwiseman thank you for changing the test, please merge the pull request, seems like the checks are ok |
|
It is all ok with MR? |
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.
@ravingbool
Sorry for the delay, I'm currently on vacation.
This is a harder problem to solve right than it might appear at first. What you have done is okay and exposes this new feature of the endpoint, but it does so in a way that is inconsistent with the rest of the APIs in this library.
All the other endpoints that support per_page and page parameters use PagedIterable to iterate over items. However, those endpoints also for the most part return simple lists. There are also some endpoints that return pages as relatively sparse objects that then contain lists.
For example GHRepository.getCheckRuns returns PagedIterable<GHCheckRun>:
github-api/src/main/java/org/kohsuke/github/GHRepository.java
Lines 2027 to 2033 in 4247c8a
| public PagedIterable<GHCheckRun> getCheckRuns(String ref) throws IOException { | |
| GitHubRequest request = root.createRequest() | |
| .withUrlPath(String.format("/repos/%s/%s/commits/%s/check-runs", getOwnerName(), name, ref)) | |
| .withPreview(ANTIOPE) | |
| .build(); | |
| return new GHCheckRunsIterable(this, request); | |
| } |
This actually an instance of GHCheckRunsIterable which pages through GHCheckRunsPage objects.
I think the right way to address this will be to add GHCompare.listCommits() method that returns a PagedIterable<Commit> and internally implements something similar GHCheckRunsIterable that uses GHCompare objects as the pages.
Then change your new method to be GHRepository.getCompare(String id1, String id2, int default_commits_per_page). The query for that would set per_page to 1 and set a new default_commits_per_page field on the GHCompare instance. This would result in only one commit being returned as part of the that query, minimizing extra data transmission.
If default_commits_per_page field is set, GHCompare.listCommits() would have it's per_page set to the that by default and GHCompare.getCommits() would call listCommits().getArray() instead of it's current behavior.
You'll also need a few new tests for this behavior. Specifically, at least one test that has two pages of results.
Does this make sense? Do you have time to do this additional work?
|
@bitwiseman well, I didn't suppose that it would so a lot of work. Can we merge it as is now and make a follow up for it? Because I would like to have a new version with this functionality as soon as possible. I will refactor it in the future, but now I would like to have it as is, pleeeease @bitwiseman |
b0da60d to
d03edbf
Compare
|
@ravingbool |
|
@bitwiseman |
e616828 to
2a16336
Compare
2a16336 to
20fce64
Compare
GHCompare supports per page and page+params
Fixes #1209