use of com.epam.pipeline.entity.git.GitRepositoryEntry in project cloud-pipeline by epam.
the class GitManager method renameFolder.
private GitCommitEntry renameFolder(Pipeline pipeline, String folder, String newFolderName, String lastCommitId, String commitMessage) throws GitClientException {
if (commitMessage == null) {
commitMessage = String.format("Renaming update %s to %s", folder, newFolderName);
}
Assert.isTrue(lastCommitId.equals(pipeline.getCurrentVersion().getCommitId()), messageHelper.getMessage(MessageConstants.ERROR_REPOSITORY_FILE_WAS_UPDATED, folder));
Assert.isTrue(folderExists(pipeline, folder), messageHelper.getMessage(MessageConstants.ERROR_REPOSITORY_FOLDER_NOT_FOUND, folder));
Assert.isTrue(!folderExists(pipeline, newFolderName), messageHelper.getMessage(MessageConstants.ERROR_REPOSITORY_FOLDER_ALREADY_EXISTS, newFolderName));
final GitlabClient gitlabClient = getGitlabClientForPipeline(pipeline);
final List<GitRepositoryEntry> allFiles = gitlabClient.getRepositoryContents(folder, GIT_MASTER_REPOSITORY, true);
final GitPushCommitEntry gitPushCommitEntry = new GitPushCommitEntry();
gitPushCommitEntry.setCommitMessage(commitMessage);
for (GitRepositoryEntry file : allFiles) {
if (file.getType().equalsIgnoreCase("tree")) {
continue;
}
prepareFileForRenaming(file.getPath().replaceFirst(folder, newFolderName), file.getPath(), gitPushCommitEntry, gitlabClient);
}
return gitlabClient.commit(gitPushCommitEntry);
}
use of com.epam.pipeline.entity.git.GitRepositoryEntry in project cloud-pipeline by epam.
the class PipelineCodeHandlerTest method setup.
@BeforeEach
void setup() {
pipelineCodeHandler = new PipelineCodeHandler(INDEX_PREFIX, INDEX_NAME, apiClient, new ElasticIndexService(), FILE_INDEX_PATHS, objectMapper, pipelineLoader, new PipelineCodeMapper(), "master");
expectedPipelineEvent = new PipelineEvent();
expectedPipelineEvent.setEventType(EventType.INSERT);
expectedPipelineEvent.setObjectType(PipelineEvent.ObjectType.PIPELINE);
expectedPipelineEvent.setObjectId(1L);
expectedPipelineEvent.setCreatedDate(LocalDateTime.now());
expectedPipelineEvent.setData("{\"tag\": {\"type\": \"string\", \"value\": \"admin\"}}");
pipeline = new Pipeline();
pipeline.setId(1L);
pipeline.setName(TEST_NAME);
pipeline.setCreatedDate(DateUtils.now());
pipeline.setParentFolderId(2L);
pipeline.setDescription(TEST_DESCRIPTION);
pipeline.setRepository(TEST_REPO);
pipeline.setTemplateId(TEST_TEMPLATE);
Revision revision = new Revision();
revision.setName(TEST_VERSION);
PipelineDoc pipelineDoc = PipelineDoc.builder().pipeline(pipeline).revisions(Collections.singletonList(revision)).build();
gitPushEventData = new GitEventData();
gitPushEventData.setGitEventType(GitEventType.push);
gitPushEventData.setPaths(Collections.singletonList(FILE_INDEX_PATHS));
gitPushEventData.setVersion(VERSION);
gitTagEventData = new GitEventData();
gitTagEventData.setGitEventType(GitEventType.tag_push);
gitTagEventData.setPaths(Collections.singletonList(FILE_INDEX_PATHS));
gitTagEventData.setVersion(VERSION);
gitRepositoryEntry = new GitRepositoryEntry();
gitRepositoryEntry.setId("1");
gitRepositoryEntry.setName(TEST_NAME);
gitRepositoryEntry.setPath(FOLDER_INDEX_PATHS);
gitRepositoryEntry.setType("blob");
container = EntityContainer.<PipelineDoc>builder().entity(pipelineDoc).owner(USER).metadata(METADATA).permissions(PERMISSIONS_CONTAINER).build();
}
use of com.epam.pipeline.entity.git.GitRepositoryEntry in project cloud-pipeline by epam.
the class GitlabClient method createFile.
private void createFile(GitProject project, String path, String content) throws URISyntaxException, UnexpectedResponseStatusException, UnsupportedEncodingException {
HttpHeaders headers = new HttpHeaders();
headers.add(TOKEN_HEADER, token);
Map<String, Object> parameters = new HashMap<>();
parameters.put("file_path", path);
parameters.put("branch_name", DEFAULT_BRANCH);
parameters.put("commit_message", "New pipeline initial commit");
parameters.put("content", content);
String url = addUrlParameters(String.format(GIT_POST_FILE_URL, gitHost, project.getId().toString(), URLEncoder.encode(path, Charset.defaultCharset().displayName())), 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) {
throw new UnexpectedResponseStatusException(response.getStatusCode());
}
}
use of com.epam.pipeline.entity.git.GitRepositoryEntry 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());
}
}
use of com.epam.pipeline.entity.git.GitRepositoryEntry in project cloud-pipeline by epam.
the class GitManagerTest method shouldFetchPipelineDocs.
@Test
public void shouldFetchPipelineDocs() throws GitClientException {
final Pipeline pipeline = testingPipeline();
final GitRepositoryEntry bla = new GitRepositoryEntry();
bla.setName(README_FILE);
bla.setType(BLOB_TYPE);
final List<GitRepositoryEntry> tree = singletonList(bla);
givenThat(get(urlPathEqualTo(api(REPOSITORY_TREE))).withQueryParam(REF_NAME, equalTo(TEST_REVISION)).withQueryParam(PATH, equalTo(DOCS + "/")).withQueryParam(RECURSIVE, equalTo(String.valueOf(false))).willReturn(okJson(with(tree))));
final GitTagEntry tag = new GitTagEntry();
givenThat(get(urlPathEqualTo(api(REPOSITORY_TAGS + "/" + TEST_REVISION))).willReturn(okJson(with(tag))));
final List<GitRepositoryEntry> repoEntries = gitManager.getPipelineDocs(pipeline.getId(), TEST_REVISION);
final boolean noEntries = repoEntries.isEmpty();
final boolean docsOnly = repoEntries.stream().filter(e -> !e.getName().startsWith(".")).allMatch(e -> e.getName().endsWith(".md"));
assertFalse(noEntries);
assertTrue(docsOnly);
}
Aggregations