use of com.epam.pipeline.exception.git.GitClientException in project cloud-pipeline by epam.
the class GitManager method getConfigurationFileEntry.
private GitRepositoryEntry getConfigurationFileEntry(Long id, String version) throws GitClientException {
Pipeline pipeline = pipelineManager.load(id);
try {
loadRevision(pipeline, version);
} catch (GitClientException e) {
LOGGER.error(e.getMessage(), e);
throw new IllegalArgumentException(e.getMessage());
}
GitRepositoryEntry configurationFileEntry = null;
List<GitRepositoryEntry> rootEntries = this.getGitlabClientForPipeline(pipeline).getRepositoryContents("", getRevisionName(version), false);
for (GitRepositoryEntry rootEntry : rootEntries) {
if (rootEntry.getName().equalsIgnoreCase(CONFIG_FILE_NAME)) {
configurationFileEntry = rootEntry;
break;
}
}
return configurationFileEntry;
}
use of com.epam.pipeline.exception.git.GitClientException 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.exception.git.GitClientException 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.exception.git.GitClientException in project cloud-pipeline by epam.
the class GitlabClient method getRepositoryRevision.
public GitTagEntry getRepositoryRevision(String tag) throws GitClientException {
try {
String projectId = makeProjectId(namespace, projectName);
String url = addUrlParameters(String.format(GIT_REVISION, gitHost, projectId, tag), new HashMap<>());
URI uri = new URI(url);
LOGGER.trace("Getting repository revisions from URL: {}", uri);
RestTemplate template = new RestTemplate();
ResponseEntity<GitTagEntry> sourcesResponse = template.exchange(uri, HttpMethod.GET, getAuthHeaders(), new ParameterizedTypeReference<GitTagEntry>() {
});
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.exception.git.GitClientException in project cloud-pipeline by epam.
the class GitlabClient method getRepositoryRevisions.
public List<GitTagEntry> getRepositoryRevisions(Long pageSize) throws GitClientException {
try {
String projectId = makeProjectId(namespace, projectName);
Map<String, Object> params = new HashMap<>();
if (pageSize != null) {
params.put("per_page", pageSize);
}
String url = addUrlParameters(String.format(GIT_REVISIONS, gitHost, projectId), params);
URI uri = new URI(url);
LOGGER.trace("Getting repository revisions from URL: {}", uri);
RestTemplate template = new RestTemplate();
ResponseEntity<List<GitTagEntry>> sourcesResponse = template.exchange(uri, HttpMethod.GET, getAuthHeaders(), new ParameterizedTypeReference<List<GitTagEntry>>() {
});
if (sourcesResponse.getStatusCode() == HttpStatus.OK) {
return sourcesResponse.getBody();
} else {
throw new UnexpectedResponseStatusException(sourcesResponse.getStatusCode());
}
} catch (UnsupportedEncodingException | URISyntaxException e) {
throw new GitClientException(e);
}
}
Aggregations