Search in sources :

Example 1 with GitTagEntry

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

the class GitManagerTest method shouldFetchRevision.

@Test
public void shouldFetchRevision() throws GitClientException {
    final Pipeline pipeline = testingPipeline();
    final long pageSize = 1;
    final List<GitTagEntry> tags = Collections.emptyList();
    givenThat(get(urlPathEqualTo(api(REPOSITORY_TAGS))).withQueryParam("per_page", equalTo(String.valueOf(pageSize))).willReturn(okJson(with(tags))));
    final GitCommitEntry initialCommit = new GitCommitEntry();
    initialCommit.setMessage("New pipeline initial commit");
    initialCommit.setCreatedAt("2017-07-25T13:13:11Z");
    final List<GitCommitEntry> commits = singletonList(initialCommit);
    givenThat(get(urlPathEqualTo(api(REPOSITORY_COMMITS))).willReturn(okJson(with(commits))));
    final List<Revision> revisions = gitManager.getPipelineRevisions(pipeline, pageSize);
    assertFalse(revisions.isEmpty());
}
Also used : Revision(com.epam.pipeline.entity.pipeline.Revision) GitTagEntry(com.epam.pipeline.entity.git.GitTagEntry) 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 2 with GitTagEntry

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

the class GitManager method createPipelineRevision.

public Revision createPipelineRevision(Pipeline pipeline, String revisionName, String commit, String message, String releaseDescription) throws GitClientException {
    Assert.isTrue(GitUtils.checkGitNaming(revisionName), messageHelper.getMessage(MessageConstants.ERROR_INVALID_PIPELINE_REVISION_NAME, revisionName));
    GitlabClient client = this.getGitlabClientForPipeline(pipeline);
    GitTagEntry gitTagEntry = client.createRepositoryRevision(revisionName, commit, message, releaseDescription);
    return new Revision(gitTagEntry.getName(), gitTagEntry.getMessage(), parseGitDate(gitTagEntry.getCommit().getAuthoredDate()), gitTagEntry.getCommit().getId());
}
Also used : Revision(com.epam.pipeline.entity.pipeline.Revision) GitTagEntry(com.epam.pipeline.entity.git.GitTagEntry)

Example 3 with GitTagEntry

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

the class GitlabClient method getRepositoryRevision.

public GitTagEntry getRepositoryRevision(String tag) throws GitClientException {
    try {
        String projectId = makeProjectId(namespace, projectName);
        String url = addUrlParameters(String.format(GIT_REVISION, gitHost, projectId, tag), new HashMap<>());
        URI uri = new URI(url);
        LOGGER.trace("Getting repository revisions from URL: {}", uri);
        RestTemplate template = new RestTemplate();
        ResponseEntity<GitTagEntry> sourcesResponse = template.exchange(uri, HttpMethod.GET, getAuthHeaders(), new ParameterizedTypeReference<GitTagEntry>() {
        });
        if (sourcesResponse.getStatusCode() == HttpStatus.OK) {
            return sourcesResponse.getBody();
        } else {
            throw new UnexpectedResponseStatusException(sourcesResponse.getStatusCode());
        }
    } catch (UnsupportedEncodingException | URISyntaxException | HttpClientErrorException e) {
        throw new GitClientException(e.getMessage(), e);
    }
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) UnexpectedResponseStatusException(com.epam.pipeline.exception.git.UnexpectedResponseStatusException) GitClientException(com.epam.pipeline.exception.git.GitClientException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) RestTemplate(org.springframework.web.client.RestTemplate) GitTagEntry(com.epam.pipeline.entity.git.GitTagEntry)

Example 4 with GitTagEntry

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

the class GitlabClient method createRepositoryRevision.

public GitTagEntry createRepositoryRevision(String name, String ref, String message, String releaseDescription) throws GitClientException {
    if (name == null) {
        throw new GitClientException("Tag name is required");
    }
    if (ref == null) {
        throw new GitClientException("Ref (commit SHA, another tag name, or branch name) is required");
    }
    try {
        String projectId = makeProjectId(namespace, projectName);
        Map<String, Object> params = new HashMap<>();
        params.put("tag_name", name);
        params.put("ref", ref);
        if (message != null) {
            params.put("message", message);
        }
        if (releaseDescription != null) {
            params.put("release_description", releaseDescription);
        }
        String url = addUrlParameters(String.format(GIT_REVISIONS, gitHost, projectId), params);
        URI uri = new URI(url);
        LOGGER.trace("Creating new tag using URL: {}", uri);
        RestTemplate template = new RestTemplate();
        ResponseEntity<GitTagEntry> sourcesResponse = template.exchange(uri, HttpMethod.POST, getAuthHeaders(), new ParameterizedTypeReference<GitTagEntry>() {
        });
        if (sourcesResponse.getStatusCode() == HttpStatus.CREATED) {
            return sourcesResponse.getBody();
        } else {
            throw new UnexpectedResponseStatusException(sourcesResponse.getStatusCode());
        }
    } catch (UnsupportedEncodingException | URISyntaxException e) {
        throw new GitClientException(e);
    }
}
Also used : HashMap(java.util.HashMap) UnexpectedResponseStatusException(com.epam.pipeline.exception.git.UnexpectedResponseStatusException) GitClientException(com.epam.pipeline.exception.git.GitClientException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) RestTemplate(org.springframework.web.client.RestTemplate) GitTagEntry(com.epam.pipeline.entity.git.GitTagEntry)

Example 5 with GitTagEntry

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

the class GitManagerTest method shouldFetchConfigFileContent.

@Test
public void shouldFetchConfigFileContent() throws GitClientException {
    final GitCommitEntry gitCommitEntry = new GitCommitEntry();
    givenThat(post(urlPathEqualTo(api(REPOSITORY_COMMITS))).willReturn(okJson(with(gitCommitEntry))));
    final GitTagEntry tag = new GitTagEntry();
    tag.setName(TEST_REVISION);
    givenThat(get(urlPathEqualTo(api(REPOSITORY_TAGS + "/" + tag.getName()))).willReturn(okJson(with(tag))));
    final GitFile gitFile = new GitFile();
    gitFile.setContent(Base64.getEncoder().encodeToString(FILE_CONTENT.getBytes()));
    givenThat(get(urlPathEqualTo(api(REPOSITORY_FILES))).withQueryParam(FILE_PATH, equalTo("config.json")).withQueryParam(REF, equalTo(tag.getName())).willReturn(okJson(with(gitFile))));
    final Pipeline pipeline = testingPipeline();
    final String fileContent = gitManager.getConfigFileContent(pipeline, pipeline.getCurrentVersion().getName());
    assertThat(fileContent, not(isEmptyString()));
}
Also used : GitFile(com.epam.pipeline.entity.git.GitFile) GitTagEntry(com.epam.pipeline.entity.git.GitTagEntry) 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) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test)

Aggregations

GitTagEntry (com.epam.pipeline.entity.git.GitTagEntry)10 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)7 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)7 Test (org.junit.Test)7 GitCommitEntry (com.epam.pipeline.entity.git.GitCommitEntry)5 Revision (com.epam.pipeline.entity.pipeline.Revision)5 IsEmptyString.isEmptyString (org.hamcrest.text.IsEmptyString.isEmptyString)5 Matchers.anyString (org.mockito.Matchers.anyString)5 GitFile (com.epam.pipeline.entity.git.GitFile)3 GitClientException (com.epam.pipeline.exception.git.GitClientException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 UnexpectedResponseStatusException (com.epam.pipeline.exception.git.UnexpectedResponseStatusException)2 File (java.io.File)2 URI (java.net.URI)2 Date (java.util.Date)2 PipelineSourceItemVO (com.epam.pipeline.controller.vo.PipelineSourceItemVO)1 PipelineSourceItemsVO (com.epam.pipeline.controller.vo.PipelineSourceItemsVO)1 UploadFileMetadata (com.epam.pipeline.controller.vo.UploadFileMetadata)1 GitProject (com.epam.pipeline.entity.git.GitProject)1 GitRepositoryEntry (com.epam.pipeline.entity.git.GitRepositoryEntry)1