use of com.epam.pipeline.controller.vo.PipelineSourceItemErrorVO 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);
}
}
Aggregations