use of org.sonar.alm.client.github.GithubBinding.GsonGithubRepository in project sonarqube by SonarSource.
the class GithubApplicationClientImpl method listRepositories.
@Override
public Repositories listRepositories(String appUrl, AccessToken accessToken, String organization, @Nullable String query, int page, int pageSize) {
checkPageArgs(page, pageSize);
String searchQuery = "fork:true+org:" + organization;
if (query != null) {
searchQuery = query.replace(" ", "+") + "+" + searchQuery;
}
try {
Repositories repositories = new Repositories();
GetResponse response = appHttpClient.get(appUrl, accessToken, String.format("/search/repositories?q=%s&page=%s&per_page=%s", searchQuery, page, pageSize));
Optional<GsonRepositorySearch> gsonRepositories = response.getContent().map(content -> GSON.fromJson(content, GsonRepositorySearch.class));
if (!gsonRepositories.isPresent()) {
return repositories;
}
repositories.setTotal(gsonRepositories.get().totalCount);
if (gsonRepositories.get().items != null) {
repositories.setRepositories(gsonRepositories.get().items.stream().map(GsonGithubRepository::toRepository).collect(toList()));
}
return repositories;
} catch (Exception e) {
throw new IllegalStateException(format("Failed to list all repositories of '%s' accessible by user access token on '%s' using query '%s'", organization, appUrl, searchQuery), e);
}
}
Aggregations