use of io.jenkins.blueocean.blueocean_bitbucket_pipeline.model.BbSaveContentResponse in project blueocean-plugin by jenkinsci.
the class BitbucketApiTest method createNewRepoContent.
@Test
public void createNewRepoContent() throws JsonProcessingException, UnsupportedEncodingException {
// create new file
BbSaveContentResponse saveResponse = api.saveContent("vivekp7", "demo1", "foo", "This is test content in new file", "first commit", "null", null, null);
assertNotNull(saveResponse.getCommitId());
String content = api.getContent("vivekp7", "demo1", "foo", (String) saveResponse.getCommitId());
assertEquals("This is test content in new file", content);
}
use of io.jenkins.blueocean.blueocean_bitbucket_pipeline.model.BbSaveContentResponse in project blueocean-plugin by jenkinsci.
the class BitbucketApiTest method testEmptyRepo.
@Test
public void testEmptyRepo() {
boolean empty = api.isEmptyRepo("TESTP", "empty-repo-test");
assertTrue(empty);
// create new file
BbSaveContentResponse saveResponse = api.saveContent("TESTP", "empty-repo-test", "README.md", "This is test content in new file", "another commit", "master", null, null);
assertNotNull(saveResponse.getCommitId());
String content = api.getContent("TESTP", "empty-repo-test", "README.md", (String) saveResponse.getCommitId());
assertEquals("This is test content in new file", content);
}
use of io.jenkins.blueocean.blueocean_bitbucket_pipeline.model.BbSaveContentResponse in project blueocean-plugin by jenkinsci.
the class BitbucketApiTest method createNewRepoContent.
@Test
public void createNewRepoContent() throws JsonProcessingException, UnsupportedEncodingException {
boolean exists = api.fileExists("TESTP", "pipeline-demo-test", "README.md", "master");
assertFalse(exists);
// create new file
BbSaveContentResponse saveResponse = api.saveContent("TESTP", "pipeline-demo-test", "README.md", "This is test content in new file", "another commit", "master", null, null);
assertNotNull(saveResponse.getCommitId());
String content = api.getContent("TESTP", "pipeline-demo-test", "README.md", (String) saveResponse.getCommitId());
assertEquals("This is test content in new file", content);
}
use of io.jenkins.blueocean.blueocean_bitbucket_pipeline.model.BbSaveContentResponse in project blueocean-plugin by jenkinsci.
the class AbstractBitbucketScmContentProvider method saveContent.
@Override
public Object saveContent(@Nonnull StaplerRequest staplerRequest, @Nonnull Item item) {
JSONObject body;
try {
body = JSONObject.fromObject(IOUtils.toString(staplerRequest.getReader()));
} catch (IOException e) {
throw new ServiceException.UnexpectedErrorException("Failed to read request body");
}
BitbucketScmSaveFileRequest scmSaveFileRequest = staplerRequest.bindJSON(BitbucketScmSaveFileRequest.class, body);
if (scmSaveFileRequest == null) {
throw new ServiceException.BadRequestException(new ErrorMessage(400, "Failed to bind request"));
}
GitContent gitContent = scmSaveFileRequest.getContent();
BitbucketScmParams scmParamsFromItem = new BitbucketScmParams(item);
String owner = scmParamsFromItem.getOwner();
String repo = scmParamsFromItem.getRepo();
String commitId = StringUtils.isNotBlank(gitContent.getCommitId()) ? gitContent.getCommitId() : gitContent.getSha();
BitbucketApi api = BitbucketServerScm.getApi(scmParamsFromItem.getApiUrl(), this.getScmId(), scmParamsFromItem.getCredentials());
String content;
try {
content = new String(Base64.decodeBase64(gitContent.getBase64Data()), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new ServiceException.UnexpectedErrorException(e.getMessage(), e);
}
String message = gitContent.getMessage();
if (message == null) {
message = gitContent.getPath() + " created with BlueOcean";
}
BbSaveContentResponse response = api.saveContent(owner, repo, gitContent.getPath(), content, message, gitContent.getBranch(), gitContent.getSourceBranch(), commitId);
final GitContent respContent = new GitContent.Builder().branch(gitContent.getBranch()).path(gitContent.getPath()).owner(gitContent.getOwner()).repo(gitContent.getRepo()).sha(response.getCommitId()).name(gitContent.getPath()).commitId(response.getCommitId()).build();
return new ScmFile<GitContent>() {
@Override
public GitContent getContent() {
return respContent;
}
};
}
Aggregations