Search in sources :

Example 1 with BbServerPage

use of io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerPage in project blueocean-plugin by jenkinsci.

the class BitbucketServerApi method getBranch.

@Override
@CheckForNull
public BbBranch getBranch(@Nonnull String orgId, @Nonnull String repoSlug, @Nonnull String branch) {
    try {
        URIBuilder uriBuilder = new URIBuilder(String.format("%s/%s/repos/%s/branches/", baseUrl + "projects", orgId, repoSlug));
        uriBuilder.addParameter("filterText", branch);
        BbServerPage<BbServerBranch> branches = om.readValue(request.get(uriBuilder.build().toString()).getContent(), new TypeReference<BbServerPage<BbServerBranch>>() {
        });
        String expectedId = "refs/heads/" + branch;
        for (BbServerBranch b : branches.getValues()) {
            if (b.getId().equals(expectedId)) {
                return b;
            }
        }
        return null;
    } catch (IOException | URISyntaxException e) {
        throw handleException(e);
    }
}
Also used : BbServerPage(io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerPage) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URIBuilder(org.apache.http.client.utils.URIBuilder) BbServerBranch(io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerBranch) CheckForNull(javax.annotation.CheckForNull)

Example 2 with BbServerPage

use of io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerPage in project blueocean-plugin by jenkinsci.

the class BitbucketServerApi method getOrgs.

@Override
@Nonnull
public BbPage<BbOrg> getOrgs(int pageNumber, int pageSize) {
    try {
        if (pageNumber <= 0) {
            pageNumber = 1;
        }
        if (pageSize <= 0) {
            pageSize = PagedResponse.DEFAULT_LIMIT;
        }
        InputStream inputStream = request.get(String.format("%s?start=%s&limit=%s", baseUrl + "projects/", toStart(pageNumber, pageSize), pageSize)).getContent();
        BbPage<BbOrg> page = om.readValue(inputStream, new TypeReference<BbServerPage<BbServerProject>>() {
        });
        if (pageNumber == 1) {
            // add user org as the first org on first page
            BbServerUser user = getUser(userName);
            List<BbOrg> teams = new ArrayList<>();
            teams.add(user.toPersonalProject());
            teams.addAll(page.getValues());
            return new BbServerPage<>(page.getStart(), page.getLimit(), page.getSize() + 1, teams, page.isLastPage());
        }
        return page;
    } catch (IOException e) {
        throw handleException(e);
    }
}
Also used : BbServerPage(io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerPage) InputStream(java.io.InputStream) BbServerUser(io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerUser) ArrayList(java.util.ArrayList) BbOrg(io.jenkins.blueocean.blueocean_bitbucket_pipeline.model.BbOrg) IOException(java.io.IOException) Nonnull(javax.annotation.Nonnull)

Aggregations

BbServerPage (io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerPage)2 IOException (java.io.IOException)2 BbOrg (io.jenkins.blueocean.blueocean_bitbucket_pipeline.model.BbOrg)1 BbServerBranch (io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerBranch)1 BbServerUser (io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerUser)1 InputStream (java.io.InputStream)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 CheckForNull (javax.annotation.CheckForNull)1 Nonnull (javax.annotation.Nonnull)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1