Search in sources :

Example 6 with GitPushCommitEntry

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);
}
Also used : GitPushCommitActionEntry(com.epam.pipeline.entity.git.GitPushCommitActionEntry) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) GitPushCommitEntry(com.epam.pipeline.entity.git.GitPushCommitEntry)

Example 7 with 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);
}
Also used : Path(java.nio.file.Path) GitPushCommitActionEntry(com.epam.pipeline.entity.git.GitPushCommitActionEntry) ArrayList(java.util.ArrayList) GitPushCommitEntry(com.epam.pipeline.entity.git.GitPushCommitEntry)

Example 8 with 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);
}
Also used : GitPushCommitActionEntry(com.epam.pipeline.entity.git.GitPushCommitActionEntry) GitPushCommitEntry(com.epam.pipeline.entity.git.GitPushCommitEntry)

Aggregations

GitPushCommitEntry (com.epam.pipeline.entity.git.GitPushCommitEntry)8 GitPushCommitActionEntry (com.epam.pipeline.entity.git.GitPushCommitActionEntry)6 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)3 GitRepositoryEntry (com.epam.pipeline.entity.git.GitRepositoryEntry)2 PipelineSourceItemVO (com.epam.pipeline.controller.vo.PipelineSourceItemVO)1 UploadFileMetadata (com.epam.pipeline.controller.vo.UploadFileMetadata)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1