Search in sources :

Example 6 with BbBranch

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

the class AbstractBitbucketScmContentProvider method getContent.

@Override
protected Object getContent(ScmGetRequest request) {
    BitbucketApi api = BitbucketServerScm.getApi(request.getApiUrl(), this.getScmId(), request.getCredentials());
    BbBranch branch = null;
    String branchName = request.getBranch();
    BbBranch defaultBranch = api.getDefaultBranch(request.getOwner(), request.getRepo());
    if (defaultBranch == null) {
        // empty repo
        throw new ServiceException.NotFoundException(request.getPath() + " not found. This is empty and un-initialized repository");
    }
    if (branchName == null) {
        branch = defaultBranch;
    }
    if (branchName != null) {
        branch = api.getBranch(request.getOwner(), request.getRepo(), branchName);
        // Given branchName create this branch
        if (branch == null) {
            throw new ServiceException.BadRequestException("branch: " + branchName + " not found");
        }
    }
    String content = api.getContent(request.getOwner(), request.getRepo(), request.getPath(), branch.getLatestCommit());
    try {
        final GitContent gitContent = new GitContent.Builder().base64Data(Base64.encodeBase64String(content.getBytes("UTF-8"))).branch(request.getBranch()).size(content.length()).path(request.getPath()).owner(request.getOwner()).repo(request.getRepo()).name(request.getPath()).sha(branch.getLatestCommit()).commitId(branch.getLatestCommit()).build();
        return new ScmFile<GitContent>() {

            @Override
            public GitContent getContent() {
                return gitContent;
            }
        };
    } catch (UnsupportedEncodingException e) {
        throw new ServiceException.UnexpectedErrorException("Failed to base64 encode content: " + e.getMessage(), e);
    }
}
Also used : ServiceException(io.jenkins.blueocean.commons.ServiceException) BbBranch(io.jenkins.blueocean.blueocean_bitbucket_pipeline.model.BbBranch) UnsupportedEncodingException(java.io.UnsupportedEncodingException) GitContent(io.jenkins.blueocean.rest.impl.pipeline.scm.GitContent) ScmFile(io.jenkins.blueocean.rest.impl.pipeline.scm.ScmFile)

Example 7 with BbBranch

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

the class BitbucketApiTest method getRepoContent.

@Test
public void getRepoContent() throws JsonProcessingException, UnsupportedEncodingException {
    BbBranch branch = api.getDefaultBranch("vivekp7", "demo1");
    assertNotNull(branch);
    String content = api.getContent("vivekp7", "demo1", "Jenkinsfile", branch.getLatestCommit());
    assertEquals("node{\n" + "  echo 'hello world!'\n" + "}", content);
}
Also used : BbBranch(io.jenkins.blueocean.blueocean_bitbucket_pipeline.model.BbBranch) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with BbBranch

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

Example 9 with BbBranch

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

the class BitbucketApiTest method testCreateNewBranchOnExistingRepo.

@Test
public void testCreateNewBranchOnExistingRepo() {
    BbBranch branch = api.getDefaultBranch("TESTP", "pipeline-demo-test");
    BbBranch newBranch = api.createBranch("TESTP", "pipeline-demo-test", ImmutableMap.of("name", "feature1", "startPoint", branch.getLatestCommit(), "message", "new branch"));
    assertEquals("feature1", newBranch.getDisplayId());
    assertEquals(branch.getLatestCommit(), newBranch.getLatestCommit());
}
Also used : BbBranch(io.jenkins.blueocean.blueocean_bitbucket_pipeline.model.BbBranch) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

BbBranch (io.jenkins.blueocean.blueocean_bitbucket_pipeline.model.BbBranch)9 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 BbServerBranch (io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerBranch)2 ServiceException (io.jenkins.blueocean.commons.ServiceException)1 GitContent (io.jenkins.blueocean.rest.impl.pipeline.scm.GitContent)1 ScmFile (io.jenkins.blueocean.rest.impl.pipeline.scm.ScmFile)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1