use of com.epam.pipeline.entity.git.GitPushCommitEntry 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);
}
use of com.epam.pipeline.entity.git.GitPushCommitEntry in project cloud-pipeline by epam.
the class GitManager method createFolder.
private GitCommitEntry createFolder(Pipeline pipeline, String folder, String lastCommitId, String commitMessage) throws GitClientException {
Assert.isTrue(lastCommitId.equals(pipeline.getCurrentVersion().getCommitId()), messageHelper.getMessage(MessageConstants.ERROR_REPOSITORY_FILE_WAS_UPDATED, folder));
if (commitMessage == null) {
commitMessage = String.format("Creating update %s", folder);
}
List<String> filesToCreate = new ArrayList<>();
Path folderToCreate = Paths.get(folder);
while (folderToCreate != null && !StringUtils.isNullOrEmpty(folderToCreate.toString())) {
if (!this.folderExists(pipeline, folderToCreate.toString())) {
filesToCreate.add(Paths.get(folderToCreate.toString(), GIT_FOLDER_TOKEN_FILE).toString());
}
folderToCreate = folderToCreate.getParent();
}
GitPushCommitEntry gitPushCommitEntry = new GitPushCommitEntry();
gitPushCommitEntry.setCommitMessage(commitMessage);
for (String file : filesToCreate) {
GitPushCommitActionEntry gitPushCommitActionEntry = new GitPushCommitActionEntry();
gitPushCommitActionEntry.setAction("create");
gitPushCommitActionEntry.setFilePath(file);
gitPushCommitActionEntry.setContent("");
gitPushCommitEntry.getActions().add(gitPushCommitActionEntry);
}
return this.getGitlabClientForPipeline(pipeline).commit(gitPushCommitEntry);
}
use of com.epam.pipeline.entity.git.GitPushCommitEntry in project cloud-pipeline by epam.
the class GitManager method deleteFile.
public GitCommitEntry deleteFile(Pipeline pipeline, String filePath, String lastCommitId, String commitMessage) throws GitClientException {
Assert.isTrue(lastCommitId.equals(pipeline.getCurrentVersion().getCommitId()), messageHelper.getMessage(MessageConstants.ERROR_REPOSITORY_FILE_WAS_UPDATED, filePath));
GitlabClient gitlabClient = this.getGitlabClientForPipeline(pipeline);
GitPushCommitActionEntry gitPushCommitActionEntry = new GitPushCommitActionEntry();
gitPushCommitActionEntry.setAction("delete");
gitPushCommitActionEntry.setFilePath(filePath);
GitPushCommitEntry gitPushCommitEntry = new GitPushCommitEntry();
gitPushCommitEntry.setCommitMessage(commitMessage);
gitPushCommitEntry.getActions().add(gitPushCommitActionEntry);
return gitlabClient.commit(gitPushCommitEntry);
}
Aggregations