use of com.epam.pipeline.entity.git.GitCommitEntry in project cloud-pipeline by epam.
the class GitManagerTest method shouldModifyFile.
@Test
@Ignore
public void shouldModifyFile() throws GitClientException {
final GitCommitEntry expectedCommit = new GitCommitEntry();
givenThat(post(urlPathEqualTo(api(REPOSITORY_COMMITS))).willReturn(okJson(with(expectedCommit))));
final Pipeline pipeline = testingPipeline();
final String lastCommit = pipeline.getCurrentVersion().getCommitId();
final PipelineSourceItemVO file = new PipelineSourceItemVO();
file.setLastCommitId(lastCommit);
file.setContents(FILE_CONTENT);
file.setComment("Update some file");
file.setPath(DOCS + "/" + README_FILE);
file.setPreviousPath(DOCS + "/" + README_FILE);
final GitCommitEntry resultingCommit = gitManager.modifyFile(pipeline, file);
assertThat(resultingCommit, is(expectedCommit));
}
use of com.epam.pipeline.entity.git.GitCommitEntry in project cloud-pipeline by epam.
the class GitManagerTest method shouldRenameFile.
@Test
public void shouldRenameFile() throws GitClientException, UnsupportedEncodingException {
final Pipeline pipeline = testingPipeline();
final UploadFileMetadata file = new UploadFileMetadata();
final byte[] readmeContent = "Some inconsiderable content".getBytes("UTF-8");
file.setFileName(README_FILE);
file.setFileSize(readmeContent.length / 1024 + " Kb");
file.setFileType("text/markdown; charset=UTF-8");
file.setBytes(readmeContent);
final GitCommitEntry expectedCommit = new GitCommitEntry();
expectedCommit.setMessage("Rename the file");
expectedCommit.setCreatedAt("2017-07-25T13:13:11Z");
givenThat(post(urlPathEqualTo(api(REPOSITORY_COMMITS))).willReturn(okJson(with(expectedCommit))));
final GitFile gitFile = new GitFile();
gitFile.setContent(Base64.getEncoder().encodeToString(FILE_CONTENT.getBytes()));
givenThat(get(urlPathEqualTo(api(REPOSITORY_FILES))).withQueryParam(FILE_PATH, equalTo(DOCS + "/" + README_FILE)).withQueryParam(REF, equalTo(GIT_MASTER_REPOSITORY)).willReturn(okJson(with(gitFile))));
final GitCommitEntry resultingCommit = gitManager.uploadFiles(pipeline, DOCS, singletonList(file), pipeline.getCurrentVersion().getCommitId(), "Rename the file");
assertThat(resultingCommit, is(expectedCommit));
}
use of com.epam.pipeline.entity.git.GitCommitEntry in project cloud-pipeline by epam.
the class GitlabClient method commit.
public GitCommitEntry commit(GitPushCommitEntry commitEntry) throws GitClientException {
try {
String projectId = makeProjectId(namespace, projectName);
String url = addUrlParameters(String.format(GIT_COMMITS, gitHost, projectId), null);
URI uri = new URI(url);
LOGGER.trace("Performing commit; URL: {}", uri);
HttpHeaders headers = new HttpHeaders();
headers.add(TOKEN_HEADER, token);
HttpEntity entity = new HttpEntity<>(commitEntry, headers);
ResponseEntity<GitCommitEntry> response = new RestTemplate().exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference<GitCommitEntry>() {
});
if (response.getStatusCode() == HttpStatus.OK || response.getStatusCode() == HttpStatus.CREATED) {
return response.getBody();
} else {
throw new UnexpectedResponseStatusException(response.getStatusCode());
}
} catch (HttpClientErrorException e) {
ObjectMapper mapper = new ObjectMapper();
try {
PipelineSourceItemErrorVO error = mapper.readValue(e.getResponseBodyAsByteArray(), PipelineSourceItemErrorVO.class);
throw new GitClientException(error.getMessage());
} catch (IOException e1) {
throw new GitClientException(e.getMessage(), e);
}
} catch (UnsupportedEncodingException | URISyntaxException e) {
throw new GitClientException(e.getMessage(), e);
}
}
use of com.epam.pipeline.entity.git.GitCommitEntry in project cloud-pipeline by epam.
the class GitlabClient method getRepositoryCommit.
public GitCommitEntry getRepositoryCommit(String commitId) throws GitClientException {
try {
String projectId = makeProjectId(namespace, projectName);
String url = addUrlParameters(String.format(GIT_GET_COMMIT, gitHost, projectId, commitId), new HashMap<>());
URI uri = new URI(url);
LOGGER.trace("Getting repository commit {} from URL: {}", commitId, uri);
RestTemplate template = new RestTemplate();
ResponseEntity<GitCommitEntry> sourcesResponse = template.exchange(uri, HttpMethod.GET, getAuthHeaders(), new ParameterizedTypeReference<GitCommitEntry>() {
});
if (sourcesResponse.getStatusCode() == HttpStatus.OK) {
return sourcesResponse.getBody();
} else {
throw new UnexpectedResponseStatusException(sourcesResponse.getStatusCode());
}
} catch (UnsupportedEncodingException | URISyntaxException | HttpClientErrorException e) {
throw new GitClientException(e.getMessage(), e);
}
}
use of com.epam.pipeline.entity.git.GitCommitEntry in project cloud-pipeline by epam.
the class GitManagerTest method shouldFetchConfigFileContent.
@Test
public void shouldFetchConfigFileContent() throws GitClientException {
final GitCommitEntry gitCommitEntry = new GitCommitEntry();
givenThat(post(urlPathEqualTo(api(REPOSITORY_COMMITS))).willReturn(okJson(with(gitCommitEntry))));
final GitTagEntry tag = new GitTagEntry();
tag.setName(TEST_REVISION);
givenThat(get(urlPathEqualTo(api(REPOSITORY_TAGS + "/" + tag.getName()))).willReturn(okJson(with(tag))));
final GitFile gitFile = new GitFile();
gitFile.setContent(Base64.getEncoder().encodeToString(FILE_CONTENT.getBytes()));
givenThat(get(urlPathEqualTo(api(REPOSITORY_FILES))).withQueryParam(FILE_PATH, equalTo("config.json")).withQueryParam(REF, equalTo(tag.getName())).willReturn(okJson(with(gitFile))));
final Pipeline pipeline = testingPipeline();
final String fileContent = gitManager.getConfigFileContent(pipeline, pipeline.getCurrentVersion().getName());
assertThat(fileContent, not(isEmptyString()));
}
Aggregations