Search in sources :

Example 6 with GitPushCommitActionEntry

use of com.epam.pipeline.entity.git.GitPushCommitActionEntry 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 7 with GitPushCommitActionEntry

use of com.epam.pipeline.entity.git.GitPushCommitActionEntry 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

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