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);
}
}
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);
}
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());
}
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());
}
Aggregations