How to get more than 100 results when searching for repositories with the Java GitHub API?

StackOverflow https://stackoverflow.com/questions/21507461

  •  05-10-2022
  •  | 
  •  

Question

I'm currently using the org.eclipse.egit.github.core-2.1.5 GitHub API for Java with the goal of searching for all repositories on GitHub using Python.

I know how to do the search, but the RepositoryService.searchRepositories(query) method only returns 100 results. If I redo the search, the same results are given back. Is there any way to get the next 101-X search results?

Is there any way to use a command similar in functionality to curl https://api.github.com/legacy/repos/search/Go?language=Go within the Java GitHub API? If so, what method would offer this functionality?

Was it helpful?

Solution

Judging by the code, there are several overloaded variants of searchRepositories, one of which accepts a query parameter, a language parameter and a startPage parameter. This means you should be able to run the query that you specified by using:

RepositoryService.searchRepositories("Go", "go")

If you then want to get more results, you would specify the page as well:

RepositoryService.searchRepositories("Go", "go", 2)
RepositoryService.searchRepositories("Go", "go", 3)
...

Unfortunately I cannot see a way for you to tell how many pages there actually are. The code used by searchRepositories to do the request suggests that the first request should in fact return all the results across all the pages, but if you are only getting 100 results back, then it seems this is not the case. You might just have to keep trying later pages until you get no results back.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top