Search in sources :

Example 1 with GitRepositoryEntry

use of com.epam.pipeline.entity.git.GitRepositoryEntry in project cloud-pipeline by epam.

the class PipelineDocumentTemplate method getCustomScriptsTable.

@Placeholder(regex = "Analytical Pipeline Custom Scripts", processor = TableTemplateProcessor.class)
public Table getCustomScriptsTable() {
    Table table = new Table();
    table.setContainsHeaderRow(true);
    table.addColumn("Custom script");
    table.addColumn("Version");
    for (GitRepositoryEntry customScript : this.customScripts) {
        TableRow row = table.addRow(customScript.getName());
        table.setData(row.getIndex(), 0, customScript.getName());
        table.setData(row.getIndex(), 1, "");
    }
    return table;
}
Also used : Table(com.epam.pipeline.manager.pipeline.documents.templates.structure.Table) TableRow(com.epam.pipeline.manager.pipeline.documents.templates.structure.TableRow) GitRepositoryEntry(com.epam.pipeline.entity.git.GitRepositoryEntry) Placeholder(com.epam.pipeline.manager.pipeline.documents.templates.processors.base.Placeholder)

Example 2 with GitRepositoryEntry

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

use of com.epam.pipeline.entity.git.GitRepositoryEntry in project cloud-pipeline by epam.

the class GitManagerTest method shouldRemoveFolder.

@Test
public void shouldRemoveFolder() throws GitClientException {
    final GitRepositoryEntry repositoryEntry = new GitRepositoryEntry();
    repositoryEntry.setName(README_FILE);
    repositoryEntry.setType(BLOB_TYPE);
    final List<GitRepositoryEntry> tree = singletonList(repositoryEntry);
    givenThat(get(urlPathEqualTo(api(REPOSITORY_TREE))).withQueryParam(REF_NAME, equalTo(GIT_MASTER_REPOSITORY)).withQueryParam(PATH, equalTo(DOCS)).withQueryParam(RECURSIVE, equalTo(String.valueOf(true))).willReturn(okJson(with(tree))));
    final GitCommitEntry expectedCommit = new GitCommitEntry();
    givenThat(post(urlPathEqualTo(api(REPOSITORY_COMMITS))).willReturn(okJson(with(expectedCommit))));
    final Pipeline pipeline = testingPipeline();
    final GitCommitEntry resultingCommit = gitManager.removeFolder(pipeline, DOCS, pipeline.getCurrentVersion().getCommitId(), "Remove the folder");
    assertThat(resultingCommit, is(expectedCommit));
}
Also used : GitRepositoryEntry(com.epam.pipeline.entity.git.GitRepositoryEntry) GitCommitEntry(com.epam.pipeline.entity.git.GitCommitEntry) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test)

Example 4 with GitRepositoryEntry

use of com.epam.pipeline.entity.git.GitRepositoryEntry in project cloud-pipeline by epam.

the class GitManager method getConfigurationFileEntry.

private GitRepositoryEntry getConfigurationFileEntry(Long id, String version) throws GitClientException {
    Pipeline pipeline = pipelineManager.load(id);
    try {
        loadRevision(pipeline, version);
    } catch (GitClientException e) {
        LOGGER.error(e.getMessage(), e);
        throw new IllegalArgumentException(e.getMessage());
    }
    GitRepositoryEntry configurationFileEntry = null;
    List<GitRepositoryEntry> rootEntries = this.getGitlabClientForPipeline(pipeline).getRepositoryContents("", getRevisionName(version), false);
    for (GitRepositoryEntry rootEntry : rootEntries) {
        if (rootEntry.getName().equalsIgnoreCase(CONFIG_FILE_NAME)) {
            configurationFileEntry = rootEntry;
            break;
        }
    }
    return configurationFileEntry;
}
Also used : GitClientException(com.epam.pipeline.exception.git.GitClientException) GitRepositoryEntry(com.epam.pipeline.entity.git.GitRepositoryEntry) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline)

Example 5 with GitRepositoryEntry

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

Aggregations

GitRepositoryEntry (com.epam.pipeline.entity.git.GitRepositoryEntry)11 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)6 GitCommitEntry (com.epam.pipeline.entity.git.GitCommitEntry)4 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)4 Test (org.junit.Test)4 PipelineSourceItemVO (com.epam.pipeline.controller.vo.PipelineSourceItemVO)3 GitFile (com.epam.pipeline.entity.git.GitFile)3 GitPushCommitEntry (com.epam.pipeline.entity.git.GitPushCommitEntry)2 Revision (com.epam.pipeline.entity.pipeline.Revision)2 GitClientException (com.epam.pipeline.exception.git.GitClientException)2 UnexpectedResponseStatusException (com.epam.pipeline.exception.git.UnexpectedResponseStatusException)2 URI (java.net.URI)2 HashMap (java.util.HashMap)2 Ignore (org.junit.Ignore)2 HttpEntity (org.springframework.http.HttpEntity)2 HttpHeaders (org.springframework.http.HttpHeaders)2 RestTemplate (org.springframework.web.client.RestTemplate)2 PipelineSourceItemsVO (com.epam.pipeline.controller.vo.PipelineSourceItemsVO)1 UploadFileMetadata (com.epam.pipeline.controller.vo.UploadFileMetadata)1 PipelineDoc (com.epam.pipeline.elasticsearchagent.model.PipelineDoc)1