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