Search in sources :

Example 1 with GsonInstallations

use of org.sonar.alm.client.github.GithubBinding.GsonInstallations in project sonarqube by SonarSource.

the class GithubApplicationClientImpl method listOrganizations.

@Override
public Organizations listOrganizations(String appUrl, AccessToken accessToken, int page, int pageSize) {
    checkPageArgs(page, pageSize);
    try {
        Organizations organizations = new Organizations();
        GetResponse response = appHttpClient.get(appUrl, accessToken, String.format("/user/installations?page=%s&per_page=%s", page, pageSize));
        Optional<GsonInstallations> gsonInstallations = response.getContent().map(content -> GSON.fromJson(content, GsonInstallations.class));
        if (!gsonInstallations.isPresent()) {
            return organizations;
        }
        organizations.setTotal(gsonInstallations.get().totalCount);
        if (gsonInstallations.get().installations != null) {
            organizations.setOrganizations(gsonInstallations.get().installations.stream().map(gsonInstallation -> new Organization(gsonInstallation.account.id, gsonInstallation.account.login, null, null, null, null, null, gsonInstallation.targetType)).collect(toList()));
        }
        return organizations;
    } catch (IOException e) {
        throw new IllegalStateException(format("Failed to list all organizations accessible by user access token on %s", appUrl), e);
    }
}
Also used : IOException(java.io.IOException) GetResponse(org.sonar.alm.client.github.GithubApplicationHttpClient.GetResponse) GsonInstallations(org.sonar.alm.client.github.GithubBinding.GsonInstallations)

Aggregations

IOException (java.io.IOException)1 GetResponse (org.sonar.alm.client.github.GithubApplicationHttpClient.GetResponse)1 GsonInstallations (org.sonar.alm.client.github.GithubBinding.GsonInstallations)1