Skip to content

JENKINS-72894 - Adding support to more than 1000 repositories #773

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ public void visitSources(SCMSourceObserver observer) throws IOException, Interru
String.format(
"Looking up repositories for topics: '%s'",
gitHubSCMNavigatorContext.getTopics())));
repositories = searchRepositories(github, gitHubSCMNavigatorContext);
repositories = searchRepositories(github, gitHubSCMNavigatorContext, myself);
} else {
repositories = myself.listRepositories(100);
}
Expand Down Expand Up @@ -1114,7 +1114,7 @@ public void visitSources(SCMSourceObserver observer) throws IOException, Interru
String.format(
"Looking up repositories for topics: '%s'",
gitHubSCMNavigatorContext.getTopics())));
repositories = searchRepositories(github, gitHubSCMNavigatorContext);
repositories = searchRepositories(github, gitHubSCMNavigatorContext, org);
} else {
repositories = org.listRepositories(100);
}
Expand Down Expand Up @@ -1239,13 +1239,37 @@ public void visitSources(SCMSourceObserver observer) throws IOException, Interru
}
}

private Iterable<GHRepository> searchRepositories(final GitHub github, final GitHubSCMNavigatorContext context) {
private Iterable<GHRepository> searchRepositories(
final GitHub github, final GitHubSCMNavigatorContext context, final GHOrganization org) {
final GHRepositorySearchBuilder ghRepositorySearchBuilder = github.searchRepositories();
context.getTopics().forEach(ghRepositorySearchBuilder::topic);
ghRepositorySearchBuilder.org(getRepoOwner());
if (!context.isExcludeForkedRepositories()) {
ghRepositorySearchBuilder.q("fork:true");
}

// Only the first 1000 search results are available
if (ghRepositorySearchBuilder.list().getTotalCount() > 1000) {
return org.listRepositories(100);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks to me like this is ignoring all the search settings above.
There is also redundant code in these two new methods that can be reduced.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, the query above only returns the first 1000 records. This is a github limitation.
The query also returns the number of existing records and this value is used to make a decision.

}

return ghRepositorySearchBuilder.list().withPageSize(100);
}

private Iterable<GHRepository> searchRepositories(
final GitHub github, final GitHubSCMNavigatorContext context, final GHMyself myself) {
final GHRepositorySearchBuilder ghRepositorySearchBuilder = github.searchRepositories();
context.getTopics().forEach(ghRepositorySearchBuilder::topic);
ghRepositorySearchBuilder.org(getRepoOwner());
if (!context.isExcludeForkedRepositories()) {
ghRepositorySearchBuilder.q("fork:true");
}

// Only the first 1000 search results are available
if (ghRepositorySearchBuilder.list().getTotalCount() > 1000) {
return myself.listRepositories(100);
}

return ghRepositorySearchBuilder.list().withPageSize(100);
}

Expand Down