Search in sources :

Example 1 with GitPushCommitActionEntry

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

Example 2 with GitPushCommitActionEntry

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

Example 3 with GitPushCommitActionEntry

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

Example 4 with GitPushCommitActionEntry

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

Example 5 with GitPushCommitActionEntry

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