github-api icon indicating copy to clipboard operation
github-api copied to clipboard

Document reading pages of items

Open eric-5512 opened this issue 4 years ago • 8 comments

Return open or closed issues in pagination

public List<GHIssue> getIssues(GHIssueState state) throws IOException {
        return this.listIssues(state).toList();
    }

    public List<GHIssue> getIssues(GHIssueState state, GHMilestone milestone) throws IOException {
        Requester requester = (Requester)((Requester)this.root.createRequest().with("state", state)).with("milestone", milestone == null ? "none" : "" + milestone.getNumber());
        return ((Requester)requester.withUrlPath(this.getApiTailUrl("issues"), new String[0])).toIterable(GHIssue[].class, (item) -> {
            item.wrap(this);
        }).toList();
    }

I didn’t see any support for paging

image

Need to manually specify page and pre_page

eric-5512 avatar Oct 30 '20 10:10 eric-5512

Pagination is built into the library using PagedIterable. getIssues() will automatically traverse all pages to get a list.

Have you looked at this?

https://github.com/hub4j/github-api/blob/3a11b7ccbf5ef80e6231c15b539c5d386f827caf/src/main/java/org/kohsuke/github/GHRepository.java#L425-L430

That will allow you to set page size as well.

bitwiseman avatar Nov 05 '20 17:11 bitwiseman

HI @bitwiseman

I know that there is automatic traversal of all pages, but I need a page that can be divided according to parameters, because our above sometimes produces tens of thousands of issues, if automatic page traversal takes a lot of time.

eric-5512 avatar Nov 06 '20 00:11 eric-5512

@eric-5512

Do you mean you want to start at a specific page? Or that you want to set the page size before you start iterating? Or that you want support for getting a single page of your choice?

What would you like to be able to do that you cannot currently do? If you can provide a sample of what you'd like your code to look like that would help with understanding your reuqest.

bitwiseman avatar Nov 12 '20 17:11 bitwiseman

HI @bitwiseman

Only one page of information is displayed at a time, and then how many pieces of data can be displayed on one page.

When I select the second page, I re-request the data of the second page.

For example, the first page https://api.github.com/user/repos?page=1&per_page=25

Call https://api.github.com/user/repos?page=2&per_page=25 when I click on the second page

eric-5512 avatar Nov 23 '20 01:11 eric-5512

@eric-5512 I'm sorry, I'm still not understanding.

GHIssueState state;
List<GHIssue> page; 
PagedIterator<GHIssue> iterator = listIssues(state).withPageSize(20).iterator()
while (iterator.hasNext()) {
  page = iterator. nextPage();
}

https://github.com/hub4j/github-api/blob/3a11b7ccbf5ef80e6231c15b539c5d386f827caf/src/main/java/org/kohsuke/github/PagedIterator.java#L120

If you're talking about paging forward and back or selecting a specific page, see #348.

bitwiseman avatar Nov 24 '20 16:11 bitwiseman

HI @bitwiseman

Ok let me see, thanks

eric-5512 avatar Nov 25 '20 00:11 eric-5512

@eric-5512 Any update?

bitwiseman avatar Dec 18 '20 23:12 bitwiseman

I'm going to leave this open as a documentation issue. It would be helpful to have a doc that covers this behavior.

bitwiseman avatar Mar 15 '21 18:03 bitwiseman