Search in sources :

Example 1 with BbServerBranch

use of io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerBranch 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 BbServerBranch

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

the class BitbucketApiTest method updateRepoContent.

@Test
public void updateRepoContent() throws JsonProcessingException, UnsupportedEncodingException {
    BbBranch branch = api.getBranch("TESTP", "pipeline-demo-test", "master");
    assertEquals("master", branch.getDisplayId());
    assertTrue(branch instanceof BbServerBranch);
    assertEquals("refs/heads/master", ((BbServerBranch) branch).getId());
    assertNotNull(branch.getLatestCommit());
    String content = api.getContent("TESTP", "pipeline-demo-test", "Jenkinsfile", branch.getLatestCommit());
    assertEquals("node{\n" + "  echo 'hello world'\n" + "}", content);
    // update content
    api.saveContent("TESTP", "pipeline-demo-test", "Jenkinsfile", "node{\n" + "  echo 'hello world!'\n" + "}", "another commit", "master", null, branch.getLatestCommit());
}
Also used : BbBranch(io.jenkins.blueocean.blueocean_bitbucket_pipeline.model.BbBranch) BbServerBranch(io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerBranch) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with BbServerBranch

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

the class BitbucketServerApi method getDefaultBranch.

@Override
@CheckForNull
public BbBranch getDefaultBranch(@Nonnull String orgId, @Nonnull String repoSlug) {
    try {
        HttpResponse response = request.get(String.format("%s/%s/repos/%s/branches/default", baseUrl + "projects", orgId, repoSlug));
        int status = response.getStatus();
        // With 5.6.0 its 204, before that it was 404
        if (status == 404 || status == 204) {
            // empty repo gives 404, we ignore these
            return null;
        }
        InputStream inputStream = response.getContent();
        return om.readValue(inputStream, new TypeReference<BbServerBranch>() {
        });
    } catch (IOException e) {
        throw new ServiceException.UnexpectedErrorException(e.getMessage(), e);
    }
}
Also used : ServiceException(io.jenkins.blueocean.commons.ServiceException) InputStream(java.io.InputStream) HttpResponse(io.jenkins.blueocean.blueocean_bitbucket_pipeline.HttpResponse) IOException(java.io.IOException) BbServerBranch(io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerBranch) CheckForNull(javax.annotation.CheckForNull)

Example 4 with BbServerBranch

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

the class BitbucketApiTest method defaultBranch.

@Test
public void defaultBranch() {
    BbBranch branch = api.getDefaultBranch("TESTP", "pipeline-demo-test");
    assertNotNull(branch);
    assertEquals("master", branch.getDisplayId());
    assertTrue(branch instanceof BbServerBranch);
    assertEquals("refs/heads/master", ((BbServerBranch) branch).getId());
}
Also used : BbBranch(io.jenkins.blueocean.blueocean_bitbucket_pipeline.model.BbBranch) BbServerBranch(io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerBranch) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

BbServerBranch (io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerBranch)4 BbBranch (io.jenkins.blueocean.blueocean_bitbucket_pipeline.model.BbBranch)2 IOException (java.io.IOException)2 CheckForNull (javax.annotation.CheckForNull)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 HttpResponse (io.jenkins.blueocean.blueocean_bitbucket_pipeline.HttpResponse)1 BbServerPage (io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerPage)1 ServiceException (io.jenkins.blueocean.commons.ServiceException)1 InputStream (java.io.InputStream)1 URISyntaxException (java.net.URISyntaxException)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1