Search in sources :

Example 1 with BbCloudTeam

use of io.jenkins.blueocean.blueocean_bitbucket_pipeline.cloud.model.BbCloudTeam in project blueocean-plugin by jenkinsci.

the class BitbucketCloudApi method getOrg.

@Nonnull
@Override
public BbOrg getOrg(@Nonnull String orgName) {
    try {
        BbUser user = getUser();
        // If user org, get user and return BbCloudTeam model
        if (orgName.equalsIgnoreCase(user.getSlug())) {
            return new BbCloudTeam(user.getSlug(), user.getDisplayName(), user.getAvatar());
        }
        InputStream inputStream = request.get(String.format("%s/%s", baseUrl + "teams", orgName)).getContent();
        return om.readValue(inputStream, BbCloudTeam.class);
    } catch (IOException e) {
        throw handleException(e);
    }
}
Also used : BbUser(io.jenkins.blueocean.blueocean_bitbucket_pipeline.model.BbUser) InputStream(java.io.InputStream) IOException(java.io.IOException) BbCloudTeam(io.jenkins.blueocean.blueocean_bitbucket_pipeline.cloud.model.BbCloudTeam) Nonnull(javax.annotation.Nonnull)

Example 2 with BbCloudTeam

use of io.jenkins.blueocean.blueocean_bitbucket_pipeline.cloud.model.BbCloudTeam in project blueocean-plugin by jenkinsci.

the class BitbucketCloudApi method getOrgs.

@Nonnull
@Override
public BbPage<BbOrg> getOrgs(int pageNumber, int pageSize) {
    try {
        /*
             * Bitbucket teams API work with three roles: admin, contributor, member
             *
             * We default to 'contributor' role, because we only want to only list teams that have at least one repo
             * where user has WRITE access.
             *
             * see: https://developer.atlassian.com/bitbucket/api/2/reference/resource/teams
             */
        if (pageNumber <= 0) {
            pageNumber = 1;
        }
        if (pageSize <= 0) {
            pageSize = PagedResponse.DEFAULT_LIMIT;
        }
        InputStream inputStream = request.get(String.format("%s&page=%s&pagelen=%s", baseUrl + "teams/?role=contributor", pageNumber, pageSize)).getContent();
        BbPage<BbOrg> page = om.readValue(inputStream, new TypeReference<BbCloudPage<BbCloudTeam>>() {
        });
        if (pageNumber == 1) {
            // add user org as the first org on first page
            BbUser user = getUser();
            if (page instanceof BbCloudPage) {
                List<BbOrg> teams = new ArrayList<>();
                teams.add(new BbCloudTeam(user.getSlug(), user.getDisplayName(), user.getAvatar()));
                int newSize = page.getSize() + 1;
                int newPageLength = page.getLimit();
                if (page.getSize() > page.getLimit()) {
                    newPageLength++;
                }
                teams.addAll(page.getValues());
                return new BbCloudPage<>(newPageLength, pageNumber, newSize, ((BbCloudPage) page).getNext(), teams);
            }
        }
        return page;
    } catch (IOException e) {
        throw handleException(e);
    }
}
Also used : InputStream(java.io.InputStream) BbUser(io.jenkins.blueocean.blueocean_bitbucket_pipeline.model.BbUser) ArrayList(java.util.ArrayList) BbCloudPage(io.jenkins.blueocean.blueocean_bitbucket_pipeline.cloud.model.BbCloudPage) BbOrg(io.jenkins.blueocean.blueocean_bitbucket_pipeline.model.BbOrg) IOException(java.io.IOException) BbCloudTeam(io.jenkins.blueocean.blueocean_bitbucket_pipeline.cloud.model.BbCloudTeam) Nonnull(javax.annotation.Nonnull)

Aggregations

BbCloudTeam (io.jenkins.blueocean.blueocean_bitbucket_pipeline.cloud.model.BbCloudTeam)2 BbUser (io.jenkins.blueocean.blueocean_bitbucket_pipeline.model.BbUser)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Nonnull (javax.annotation.Nonnull)2 BbCloudPage (io.jenkins.blueocean.blueocean_bitbucket_pipeline.cloud.model.BbCloudPage)1 BbOrg (io.jenkins.blueocean.blueocean_bitbucket_pipeline.model.BbOrg)1 ArrayList (java.util.ArrayList)1