Search in sources :

Example 1 with PipelineSourceItemVO

use of com.epam.pipeline.controller.vo.PipelineSourceItemVO in project cloud-pipeline by epam.

the class PipelineVersionManager method saveUpdatedConfiguration.

private List<ConfigurationEntry> saveUpdatedConfiguration(String configName, Pipeline pipeline, List<ConfigurationEntry> updatedConf, String message) throws GitClientException {
    PipelineSourceItemVO configCommit = createConfigVO(updatedConf, configName, message);
    gitManager.modifyFile(pipeline, configCommit);
    return updatedConf;
}
Also used : PipelineSourceItemVO(com.epam.pipeline.controller.vo.PipelineSourceItemVO)

Example 2 with PipelineSourceItemVO

use of com.epam.pipeline.controller.vo.PipelineSourceItemVO in project cloud-pipeline by epam.

the class PipelineVersionManager method createConfigVO.

private PipelineSourceItemVO createConfigVO(List<ConfigurationEntry> currentConfigurations, String updatedConfig, String message) {
    String configContent;
    try {
        configContent = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(currentConfigurations);
    } catch (JsonProcessingException e) {
        throw new ConfigDecodingException(updatedConfig, e);
    }
    PipelineSourceItemVO source = new PipelineSourceItemVO();
    source.setPath(CONFIG_FILE_NAME);
    source.setContents(configContent);
    source.setComment(message);
    return source;
}
Also used : PipelineSourceItemVO(com.epam.pipeline.controller.vo.PipelineSourceItemVO) ConfigDecodingException(com.epam.pipeline.exception.ConfigDecodingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 3 with PipelineSourceItemVO

use of com.epam.pipeline.controller.vo.PipelineSourceItemVO in project cloud-pipeline by epam.

the class GitManagerTest method shouldCreateFolder.

@Test
public void shouldCreateFolder() throws GitClientException {
    final Pipeline pipeline = testingPipeline();
    final PipelineSourceItemVO folder = new PipelineSourceItemVO();
    folder.setPath(DOCS);
    folder.setLastCommitId(pipeline.getCurrentVersion().getCommitId());
    final GitRepositoryEntry bla = new GitRepositoryEntry();
    bla.setName(README_FILE);
    bla.setType(BLOB_TYPE);
    bla.setPath(DOCS + "/" + README_FILE);
    final List<GitRepositoryEntry> tree = singletonList(bla);
    givenThat(get(urlPathEqualTo(api(REPOSITORY_TREE))).withQueryParam(REF_NAME, equalTo(GIT_MASTER_REPOSITORY)).withQueryParam(PATH, equalTo(DOCS)).willReturn(okJson(with(tree))));
    final GitFile file = new GitFile();
    file.setContent(Base64.getEncoder().encodeToString(FILE_CONTENT.getBytes()));
    givenThat(get(urlPathEqualTo(api(REPOSITORY_FILES))).withQueryParam(FILE_PATH, equalTo(DOCS + File.separator + ".gitkeep")).withQueryParam(REF, equalTo(GIT_MASTER_REPOSITORY)).willReturn(okJson(with(file))));
    final GitCommitEntry expectedCommit = new GitCommitEntry();
    givenThat(post(urlPathEqualTo(api(REPOSITORY_COMMITS))).willReturn(okJson(with(expectedCommit))));
    final GitCommitEntry resultingCommit = gitManager.createOrRenameFolder(pipeline.getId(), folder);
    assertThat(resultingCommit, is(expectedCommit));
}
Also used : PipelineSourceItemVO(com.epam.pipeline.controller.vo.PipelineSourceItemVO) GitFile(com.epam.pipeline.entity.git.GitFile) GitRepositoryEntry(com.epam.pipeline.entity.git.GitRepositoryEntry) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) GitCommitEntry(com.epam.pipeline.entity.git.GitCommitEntry) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test)

Example 4 with PipelineSourceItemVO

use of com.epam.pipeline.controller.vo.PipelineSourceItemVO in project cloud-pipeline by epam.

the class GitManagerTest method shouldModifyFile.

@Test
@Ignore
public void shouldModifyFile() throws GitClientException {
    final GitCommitEntry expectedCommit = new GitCommitEntry();
    givenThat(post(urlPathEqualTo(api(REPOSITORY_COMMITS))).willReturn(okJson(with(expectedCommit))));
    final Pipeline pipeline = testingPipeline();
    final String lastCommit = pipeline.getCurrentVersion().getCommitId();
    final PipelineSourceItemVO file = new PipelineSourceItemVO();
    file.setLastCommitId(lastCommit);
    file.setContents(FILE_CONTENT);
    file.setComment("Update some file");
    file.setPath(DOCS + "/" + README_FILE);
    file.setPreviousPath(DOCS + "/" + README_FILE);
    final GitCommitEntry resultingCommit = gitManager.modifyFile(pipeline, file);
    assertThat(resultingCommit, is(expectedCommit));
}
Also used : PipelineSourceItemVO(com.epam.pipeline.controller.vo.PipelineSourceItemVO) IsEmptyString.isEmptyString(org.hamcrest.text.IsEmptyString.isEmptyString) Matchers.anyString(org.mockito.Matchers.anyString) GitCommitEntry(com.epam.pipeline.entity.git.GitCommitEntry) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) Ignore(org.junit.Ignore) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test)

Example 5 with PipelineSourceItemVO

use of com.epam.pipeline.controller.vo.PipelineSourceItemVO 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)

Aggregations

PipelineSourceItemVO (com.epam.pipeline.controller.vo.PipelineSourceItemVO)7 GitCommitEntry (com.epam.pipeline.entity.git.GitCommitEntry)4 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)4 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)4 Test (org.junit.Test)4 GitFile (com.epam.pipeline.entity.git.GitFile)2 GitRepositoryEntry (com.epam.pipeline.entity.git.GitRepositoryEntry)2 IsEmptyString.isEmptyString (org.hamcrest.text.IsEmptyString.isEmptyString)2 Ignore (org.junit.Ignore)2 Matchers.anyString (org.mockito.Matchers.anyString)2 PipelineSourceItemsVO (com.epam.pipeline.controller.vo.PipelineSourceItemsVO)1 GitPushCommitActionEntry (com.epam.pipeline.entity.git.GitPushCommitActionEntry)1 GitPushCommitEntry (com.epam.pipeline.entity.git.GitPushCommitEntry)1 ConfigDecodingException (com.epam.pipeline.exception.ConfigDecodingException)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)1