use of com.epam.pipeline.entity.git.GitPushCommitActionEntry in project cloud-pipeline by epam.
the class GitManager method removeFolder.
public GitCommitEntry removeFolder(Pipeline pipeline, String folder, String lastCommitId, String commitMessage) throws GitClientException {
if (commitMessage == null) {
commitMessage = String.format("Removing update %s", folder);
}
Assert.isTrue(lastCommitId.equals(pipeline.getCurrentVersion().getCommitId()), messageHelper.getMessage(MessageConstants.ERROR_REPOSITORY_FILE_WAS_UPDATED, folder));
Assert.isTrue(!StringUtils.isNullOrEmpty(folder), messageHelper.getMessage(MessageConstants.ERROR_REPOSITORY_ROOT_FOLDER_CANNOT_BE_REMOVED));
Assert.isTrue(!folder.equalsIgnoreCase(srcDirectory), messageHelper.getMessage(MessageConstants.ERROR_REPOSITORY_FOLDER_CANNOT_BE_REMOVED, folder));
GitlabClient gitlabClient = this.getGitlabClientForPipeline(pipeline);
List<GitRepositoryEntry> allFiles = gitlabClient.getRepositoryContents(folder, GIT_MASTER_REPOSITORY, true);
GitPushCommitEntry gitPushCommitEntry = new GitPushCommitEntry();
gitPushCommitEntry.setCommitMessage(commitMessage);
for (GitRepositoryEntry file : allFiles) {
if (file.getType().equalsIgnoreCase("tree")) {
continue;
}
GitPushCommitActionEntry gitPushCommitActionEntry = new GitPushCommitActionEntry();
gitPushCommitActionEntry.setAction("delete");
gitPushCommitActionEntry.setFilePath(file.getPath());
gitPushCommitEntry.getActions().add(gitPushCommitActionEntry);
}
return gitlabClient.commit(gitPushCommitEntry);
}
use of com.epam.pipeline.entity.git.GitPushCommitActionEntry in project cloud-pipeline by epam.
the class GitManager method uploadFiles.
public GitCommitEntry uploadFiles(Pipeline pipeline, String folder, List<UploadFileMetadata> files, String lastCommitId, String commitMessage) throws GitClientException {
Assert.isTrue(lastCommitId.equals(pipeline.getCurrentVersion().getCommitId()), messageHelper.getMessage(MessageConstants.ERROR_REPOSITORY_WAS_UPDATED));
GitlabClient gitlabClient = this.getGitlabClientForPipeline(pipeline);
GitPushCommitEntry gitPushCommitEntry = new GitPushCommitEntry();
for (UploadFileMetadata file : files) {
String filePath = folder + PATH_DELIMITER + file.getFileName();
Arrays.stream(filePath.split(PATH_DELIMITER)).forEach(pathPart -> Assert.isTrue(GitUtils.checkGitNaming(pathPart), messageHelper.getMessage(MessageConstants.ERROR_INVALID_PIPELINE_FILE_NAME, filePath)));
boolean fileExists = false;
try {
fileExists = gitlabClient.getFileContents(filePath, GIT_MASTER_REPOSITORY) != null;
} catch (HttpClientErrorException exception) {
LOGGER.debug(exception.getMessage(), exception);
}
GitPushCommitActionEntry gitPushCommitActionEntry = new GitPushCommitActionEntry();
commitMessage = getCommitMessage(commitMessage, filePath, fileExists, gitPushCommitActionEntry);
gitPushCommitActionEntry.setFilePath(filePath);
gitPushCommitActionEntry.setContent(Base64.getEncoder().encodeToString(file.getBytes()));
gitPushCommitActionEntry.setEncoding(BASE64_ENCODING);
gitPushCommitEntry.getActions().add(gitPushCommitActionEntry);
}
gitPushCommitEntry.setCommitMessage(commitMessage);
return gitlabClient.commit(gitPushCommitEntry);
}
use of com.epam.pipeline.entity.git.GitPushCommitActionEntry in project cloud-pipeline by epam.
the class GitManager method updateFiles.
public GitCommitEntry updateFiles(Pipeline pipeline, PipelineSourceItemsVO sourceItemVOList) throws GitClientException {
if (CollectionUtils.isEmpty(sourceItemVOList.getItems())) {
return null;
}
String lastCommitId = sourceItemVOList.getLastCommitId();
Assert.isTrue(lastCommitId.equals(pipeline.getCurrentVersion().getCommitId()), messageHelper.getMessage(MessageConstants.ERROR_REPOSITORY_WAS_UPDATED));
GitlabClient gitlabClient = getGitlabClientForPipeline(pipeline);
GitPushCommitEntry gitPushCommitEntry = new GitPushCommitEntry();
if (StringUtils.isNullOrEmpty(sourceItemVOList.getComment())) {
gitPushCommitEntry.setCommitMessage(String.format("Updating files %s", StringUtils.join(", ", String.valueOf(sourceItemVOList.getItems().stream().map(PipelineSourceItemVO::getPath)))));
} else {
gitPushCommitEntry.setCommitMessage(sourceItemVOList.getComment());
}
for (PipelineSourceItemVO sourceItemVO : sourceItemVOList.getItems()) {
String sourcePath = sourceItemVO.getPath();
Arrays.stream(sourcePath.split(PATH_DELIMITER)).forEach(pathPart -> Assert.isTrue(GitUtils.checkGitNaming(pathPart), messageHelper.getMessage(MessageConstants.ERROR_INVALID_PIPELINE_FILE_NAME, sourcePath)));
String action;
if (!StringUtils.isNullOrEmpty(sourceItemVO.getPreviousPath())) {
action = ACTION_MOVE;
} else {
boolean fileExists = false;
try {
fileExists = gitlabClient.getFileContents(sourcePath, GIT_MASTER_REPOSITORY) != null;
} catch (HttpClientErrorException exception) {
LOGGER.debug(exception.getMessage(), exception);
}
if (fileExists) {
action = "update";
} else {
action = "create";
}
}
GitPushCommitActionEntry gitPushCommitActionEntry = new GitPushCommitActionEntry();
gitPushCommitActionEntry.setFilePath(sourcePath);
gitPushCommitActionEntry.setAction(action);
if (StringUtils.isNullOrEmpty(sourceItemVO.getPreviousPath())) {
gitPushCommitActionEntry.setContent(sourceItemVO.getContents());
} else {
gitPushCommitActionEntry.setPreviousPath(sourceItemVO.getPreviousPath());
}
gitPushCommitEntry.getActions().add(gitPushCommitActionEntry);
}
return gitlabClient.commit(gitPushCommitEntry);
}
use of com.epam.pipeline.entity.git.GitPushCommitActionEntry in project cloud-pipeline by epam.
the class GitManager method prepareFileForRenaming.
private GitPushCommitEntry prepareFileForRenaming(final String filePath, final String filePreviousPath, final GitPushCommitEntry gitPushCommitEntry, final GitlabClient gitlabClient) throws GitClientException {
final byte[] fileContents = gitlabClient.getFileContents(filePreviousPath, GIT_MASTER_REPOSITORY);
final GitPushCommitActionEntry gitPushCommitActionEntry = new GitPushCommitActionEntry();
gitPushCommitActionEntry.setAction(ACTION_MOVE);
gitPushCommitActionEntry.setFilePath(filePath);
gitPushCommitActionEntry.setPreviousPath(filePreviousPath);
gitPushCommitActionEntry.setContent(Base64.getEncoder().encodeToString(fileContents));
gitPushCommitActionEntry.setEncoding(BASE64_ENCODING);
gitPushCommitEntry.getActions().add(gitPushCommitActionEntry);
return gitPushCommitEntry;
}
use of com.epam.pipeline.entity.git.GitPushCommitActionEntry in project cloud-pipeline by epam.
the class GitManager method updateFile.
protected GitCommitEntry updateFile(Pipeline pipeline, String filePath, String fileContent, String lastCommitId, String commitMessage, boolean checkCommit) throws GitClientException {
if (checkCommit) {
Assert.isTrue(lastCommitId.equals(pipeline.getCurrentVersion().getCommitId()), messageHelper.getMessage(MessageConstants.ERROR_REPOSITORY_FILE_WAS_UPDATED, filePath));
}
GitlabClient gitlabClient = this.getGitlabClientForPipeline(pipeline);
boolean fileExists = false;
try {
fileExists = gitlabClient.getFileContents(filePath, GIT_MASTER_REPOSITORY) != null;
} catch (HttpClientErrorException exception) {
LOGGER.debug(exception.getMessage(), exception);
}
GitPushCommitActionEntry gitPushCommitActionEntry = new GitPushCommitActionEntry();
String message = getCommitMessage(commitMessage, filePath, fileExists, gitPushCommitActionEntry);
gitPushCommitActionEntry.setFilePath(filePath);
gitPushCommitActionEntry.setContent(fileContent);
GitPushCommitEntry gitPushCommitEntry = new GitPushCommitEntry();
gitPushCommitEntry.setCommitMessage(message);
gitPushCommitEntry.getActions().add(gitPushCommitActionEntry);
return gitlabClient.commit(gitPushCommitEntry);
}
Aggregations