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());
}
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());
}
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);
}
}
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);
}
}
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()));
}
Aggregations