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