use of com.epam.pipeline.exception.git.UnexpectedResponseStatusException in project cloud-pipeline by epam.
the class GitlabClient method getFileContents.
public byte[] getFileContents(String projectId, String path, String revision) throws GitClientException {
Assert.isTrue(StringUtils.isNotBlank(path), "File path can't be null");
Assert.isTrue(StringUtils.isNotBlank(revision), "Revision can't be null");
try {
if (StringUtils.isBlank(projectId)) {
projectId = makeProjectId(namespace, projectName);
}
Map<String, Object> params = new HashMap<>();
params.put("file_path", path);
params.put("ref", revision);
String url = addUrlParameters(String.format(GIT_GET_SOURCE_FILE_URL, gitHost, projectId), params);
URI uri = new URI(url);
LOGGER.trace("Getting file contents on path {}, URL: {}", path, uri);
RestTemplate template = new RestTemplate();
ResponseEntity<GitFile> sourcesResponse = template.exchange(uri, HttpMethod.GET, getAuthHeaders(), GitFile.class);
if (sourcesResponse.getStatusCode() == HttpStatus.OK) {
return Base64.getDecoder().decode(sourcesResponse.getBody().getContent());
} else {
throw new UnexpectedResponseStatusException(sourcesResponse.getStatusCode());
}
} catch (UnsupportedEncodingException | URISyntaxException | UnexpectedResponseStatusException e) {
throw new GitClientException(e);
}
}
use of com.epam.pipeline.exception.git.UnexpectedResponseStatusException in project cloud-pipeline by epam.
the class GitlabClient method deleteRepository.
public void deleteRepository() throws UnexpectedResponseStatusException, URISyntaxException, UnsupportedEncodingException {
String projectId = makeProjectId(namespace, projectName);
String url = addUrlParameters(String.format(GIT_PROJECT_URL, gitHost, projectId), null);
URI uri = new URI(url);
ResponseEntity<Void> response = new RestTemplate().exchange(uri, HttpMethod.DELETE, getAuthHeaders(), new ParameterizedTypeReference<Void>() {
});
if (response.getStatusCode() != HttpStatus.OK) {
throw new UnexpectedResponseStatusException(response.getStatusCode());
}
}
use of com.epam.pipeline.exception.git.UnexpectedResponseStatusException in project cloud-pipeline by epam.
the class GitlabClient method projectExists.
public boolean projectExists(String name) throws GitClientException {
String project = convertPipeNameToProject(name);
try {
URI uri = new URI(String.format(GIT_PROJECT_URL, gitHost, makeProjectId(adminName, project)));
ResponseEntity<GitProject> response = new RestTemplate().exchange(uri, HttpMethod.GET, getAuthHeaders(), new ParameterizedTypeReference<GitProject>() {
});
return response.getStatusCode() == HttpStatus.OK;
} catch (HttpClientErrorException e) {
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
return false;
}
throw new UnexpectedResponseStatusException(e.getStatusCode());
} catch (URISyntaxException | UnsupportedEncodingException e) {
throw new GitClientException(e.getMessage(), e);
}
}
use of com.epam.pipeline.exception.git.UnexpectedResponseStatusException in project cloud-pipeline by epam.
the class GitlabClient method addProjectHook.
private GitRepositoryEntry addProjectHook(String projectId, String hookUrl) throws UnsupportedEncodingException, UnexpectedResponseStatusException, URISyntaxException {
HttpHeaders headers = new HttpHeaders();
headers.add(TOKEN_HEADER, token);
Map<String, Object> parameters = new HashMap<>();
parameters.put("url", hookUrl);
parameters.put("push_events", true);
parameters.put("push_events_branch_filter", DEFAULT_BRANCH);
parameters.put("tag_push_events", true);
parameters.put("enable_ssl_verification", false);
String url = addUrlParameters(String.format(GITLAB_PROJECT_HOOKS, gitHost, projectId), parameters);
URI uri = new URI(url);
HttpEntity entity = new HttpEntity(headers);
ResponseEntity<GitRepositoryEntry> response = new RestTemplate().exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference<GitRepositoryEntry>() {
});
if (response.getStatusCode() == HttpStatus.CREATED) {
return response.getBody();
} else {
throw new UnexpectedResponseStatusException(response.getStatusCode());
}
}
Aggregations