use of io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerSaveContentResponse in project blueocean-plugin by jenkinsci.
the class BitbucketServerApi method saveContent.
@Override
@Nonnull
public BbSaveContentResponse saveContent(@Nonnull String projectKey, @Nonnull String repoSlug, @Nonnull String path, @Nonnull String content, @Nonnull String commitMessage, @Nullable String branch, @Nullable String sourceBranch, @Nullable String commitId) {
try {
String version = getVersion(apiUrl);
if (!isSupportedVersion(version)) {
throw new ServiceException.PreconditionRequired(Messages.bbserver_version_validation_error(version, BitbucketServerApi.MINIMUM_SUPPORTED_VERSION));
}
MultipartEntityBuilder builder = MultipartEntityBuilder.create().addTextBody("content", content).addTextBody("message", commitMessage);
if (StringUtils.isNotBlank(branch)) {
builder.addTextBody("branch", branch);
}
if (StringUtils.isNotBlank(sourceBranch)) {
builder.addTextBody("sourceBranch", sourceBranch);
}
if (org.apache.commons.lang.StringUtils.isNotBlank(commitId)) {
builder.addTextBody("sourceCommitId", commitId);
}
HttpEntity entity = builder.build();
HttpResponse response = request.put(String.format("%s/%s/repos/%s/browse/%s", baseUrl + "projects", projectKey, repoSlug, path), entity);
// we ignore error and return the response as if it was saved successfully
if (commitId != null && response.getStatus() == 409) {
return new BbServerSaveContentResponse(commitId);
}
InputStream inputStream = response.getContent();
return om.readValue(inputStream, BbServerSaveContentResponse.class);
} catch (IOException e) {
throw new ServiceException.UnexpectedErrorException(e.getMessage(), e);
}
}
Aggregations