use of com.epam.pipeline.entity.git.GitProject in project cloud-pipeline by epam.
the class GitManagerTest method shouldReturnTrueWhenProjectExists.
@Test
public void shouldReturnTrueWhenProjectExists() {
final GitProject project = new GitProject();
project.setRepoUrl(gitHost.withNamespace(ROOT_USER_NAME).withProject(REPOSITORY_NAME).asString());
givenThat(get(urlPathEqualTo(api())).willReturn(okJson(with(project))));
final boolean projectExists = gitManager.checkProjectExists(REPOSITORY_NAME);
assertTrue(projectExists);
}
use of com.epam.pipeline.entity.git.GitProject in project cloud-pipeline by epam.
the class GitlabClient method createRepo.
private GitProject createRepo(String repoName, String description) throws UnexpectedResponseStatusException, URISyntaxException {
HttpHeaders headers = new HttpHeaders();
headers.add(TOKEN_HEADER, token);
Map<String, String> parameters = new HashMap<>();
parameters.put("name", repoName);
if (!StringUtils.isEmpty(description)) {
parameters.put("description", description);
}
parameters.put("visibility", PUBLIC_VISIBILITY);
HttpEntity entity = new HttpEntity<>(parameters, headers);
URI uri = new URI(String.format(GIT_POST_PROJECT_URL, gitHost));
LOGGER.trace("Creating repo {}, URL: {}, token: {}", repoName, uri, token);
ResponseEntity<GitProject> response = new RestTemplate().exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference<GitProject>() {
});
if (response.getStatusCode() == HttpStatus.CREATED) {
return response.getBody();
} else {
throw new UnexpectedResponseStatusException(response.getStatusCode());
}
}
use of com.epam.pipeline.entity.git.GitProject 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.entity.git.GitProject in project cloud-pipeline by epam.
the class GitlabClient method createGitProject.
private GitProject createGitProject(Template template, String description, String repoName, boolean indexingEnabled, String hookUrl) throws UnexpectedResponseStatusException, URISyntaxException, IOException {
GitProject project = createRepo(repoName, description);
if (indexingEnabled) {
addProjectHook(String.valueOf(project.getId()), hookUrl);
}
uploadFolder(template, repoName, project);
try {
boolean fileExists = getFileContents(project.getId().toString(), DEFAULT_README, DEFAULT_BRANCH) != null;
if (!fileExists) {
createFile(project, DEFAULT_README, README_DEFAULT_CONTENTS);
}
} catch (HttpClientErrorException e) {
createFile(project, DEFAULT_README, README_DEFAULT_CONTENTS);
} catch (GitClientException exception) {
LOGGER.debug(exception.getMessage(), exception);
}
return project;
}
Aggregations