Search in sources :

Example 1 with PipelineSourceItemErrorVO

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);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HttpEntity(org.springframework.http.HttpEntity) UnexpectedResponseStatusException(com.epam.pipeline.exception.git.UnexpectedResponseStatusException) GitClientException(com.epam.pipeline.exception.git.GitClientException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) RestTemplate(org.springframework.web.client.RestTemplate) PipelineSourceItemErrorVO(com.epam.pipeline.controller.vo.PipelineSourceItemErrorVO) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GitCommitEntry(com.epam.pipeline.entity.git.GitCommitEntry)

Aggregations

PipelineSourceItemErrorVO (com.epam.pipeline.controller.vo.PipelineSourceItemErrorVO)1 GitCommitEntry (com.epam.pipeline.entity.git.GitCommitEntry)1 GitClientException (com.epam.pipeline.exception.git.GitClientException)1 UnexpectedResponseStatusException (com.epam.pipeline.exception.git.UnexpectedResponseStatusException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)1 RestTemplate (org.springframework.web.client.RestTemplate)1