use of io.jenkins.blueocean.blueocean_bitbucket_pipeline.cloud.model.BbCloudSaveContentResponse in project blueocean-plugin by jenkinsci.
the class BitbucketCloudApi method saveContent.
@Nonnull
@Override
public BbSaveContentResponse saveContent(@Nonnull String orgId, @Nonnull String repoSlug, @Nonnull String path, @Nonnull String content, @Nonnull String commitMessage, @Nullable String branch, @Nullable String sourceBranch, @Nullable String commitId) {
MultipartEntityBuilder builder = MultipartEntityBuilder.create().addTextBody(path, content).addTextBody("message", commitMessage);
if (isNotBlank(branch)) {
builder.addTextBody("branch", branch);
}
if (isNotBlank(commitId)) {
builder.addTextBody("parents", commitId);
}
HttpEntity entity = builder.build();
HttpResponse response = request.post(String.format("%s/%s/%s/src", baseUrl + "repositories", orgId, repoSlug), entity);
int status = response.getStatus();
if (status == 201) {
String location = response.getHeader("Location");
if (location == null) {
throw new ServiceException.UnexpectedErrorException("Location header is missing on save content response");
}
String cid = location.substring(location.lastIndexOf("/") + 1);
return new BbCloudSaveContentResponse(cid);
} else {
throw new ServiceException.UnexpectedErrorException("Failed to save file: " + path + " server returned status: " + status);
}
}
Aggregations