use of org.sonar.alm.client.github.GithubApplicationHttpClient.GetResponse 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);
}
}
use of org.sonar.alm.client.github.GithubApplicationHttpClient.GetResponse in project sonarqube by SonarSource.
the class GithubApplicationHttpClientImplTest method get_returns_empty_endPoint_when_no_link_header.
@Test
public void get_returns_empty_endPoint_when_no_link_header() throws IOException {
server.enqueue(new MockResponse().setBody(randomBody));
GetResponse response = underTest.get(appUrl, accessToken, randomEndPoint);
assertThat(response.getNextEndPoint()).isEmpty();
}
use of org.sonar.alm.client.github.GithubApplicationHttpClient.GetResponse in project sonarqube by SonarSource.
the class GithubApplicationHttpClientImplTest method get_returns_body_as_response_if_code_is_200.
@Test
public void get_returns_body_as_response_if_code_is_200() throws IOException {
server.enqueue(new MockResponse().setResponseCode(200).setBody(randomBody));
GetResponse response = underTest.get(appUrl, accessToken, randomEndPoint);
assertThat(response.getContent()).contains(randomBody);
}
use of org.sonar.alm.client.github.GithubApplicationHttpClient.GetResponse in project sonarqube by SonarSource.
the class GithubApplicationHttpClientImplTest method get_returns_endPoint_when_link_header_has_next_rel.
@Test
@UseDataProvider("linkHeadersWithNextRel")
public void get_returns_endPoint_when_link_header_has_next_rel(String linkHeader) throws IOException {
server.enqueue(new MockResponse().setBody(randomBody).setHeader("link", linkHeader));
GetResponse response = underTest.get(appUrl, accessToken, randomEndPoint);
assertThat(response.getNextEndPoint()).contains("https://api.github.com/installation/repositories?per_page=5&page=2");
}
use of org.sonar.alm.client.github.GithubApplicationHttpClient.GetResponse in project sonarqube by SonarSource.
the class GithubApplicationHttpClientImplTest method get_empty_response_if_code_is_not_200.
@Test
@UseDataProvider("someHttpCodesWithContentBut200")
public void get_empty_response_if_code_is_not_200(int code) throws IOException {
server.enqueue(new MockResponse().setResponseCode(code).setBody(randomBody));
GetResponse response = underTest.get(appUrl, accessToken, randomEndPoint);
assertThat(response.getContent()).isEmpty();
}
Aggregations