Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 3683 GitHub Support - fix create folder error message #3696

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ public List<GitRepositoryEntry> getPipelineSources(Long id,
final Pipeline pipeline = loadPipelineAndCheckRevision(id, version);
entries = pipelineRepositoryService.getRepositoryContents(
pipeline, findRepoSrcPath(pipeline), version, recursive);
if (!RepositoryType.BITBUCKET.equals(pipeline.getRepositoryType()) &&
!RepositoryType.BITBUCKET_CLOUD.equals(pipeline.getRepositoryType()) &&
if (RepositoryType.GITLAB.equals(pipeline.getRepositoryType()) &&
appendConfigurationFileIfNeeded) {
final GitRepositoryEntry configurationEntry = getConfigurationFileEntry(id, version,
pipeline.getConfigurationPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public class PipelineRepositoryService {
private static final String DEFAULT_README = "docs/README.md";
private static final String DEFAULT_BRANCH = "master";
private static final String GITKEEP_CONTENT = "keep";
public static final String NOT_SUPPORTED_PATTERN = "%s is not supported for %s repository";

private final PipelineRepositoryProviderService providerService;
private final MessageHelper messageHelper;
Expand Down Expand Up @@ -267,8 +268,10 @@ public GitCommitEntry createFolder(final Pipeline pipeline,
final String folder,
final String lastCommitId,
final String commitMessage) throws GitClientException {
if (pipeline.getRepositoryType() == RepositoryType.BITBUCKET_CLOUD) {
throw new UnsupportedOperationException("Folder creation is not supported for Bitbucket Cloud repository");
if (pipeline.getRepositoryType() == RepositoryType.BITBUCKET_CLOUD ||
pipeline.getRepositoryType() == RepositoryType.GITHUB) {
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "Folder creation",
pipeline.getRepositoryType()));
}
Assert.isTrue(lastCommitId.equals(pipeline.getCurrentVersion().getCommitId()),
messageHelper.getMessage(MessageConstants.ERROR_REPOSITORY_FILE_WAS_UPDATED, folder));
Expand Down Expand Up @@ -300,8 +303,10 @@ public GitCommitEntry renameFolder(final Pipeline pipeline,
final String newFolderName,
final String lastCommitId,
final String commitMessage) throws GitClientException {
if (pipeline.getRepositoryType() == RepositoryType.BITBUCKET_CLOUD) {
throw new UnsupportedOperationException("Folder renaming is not supported for Bitbucket Cloud repository");
if (pipeline.getRepositoryType() == RepositoryType.BITBUCKET_CLOUD ||
pipeline.getRepositoryType() == RepositoryType.GITHUB) {
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "Folder renaming",
pipeline.getRepositoryType()));
}
final String message = StringUtils.isNotBlank(commitMessage)
? commitMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
import java.util.Optional;
import java.util.stream.Collectors;

import static com.epam.pipeline.manager.git.PipelineRepositoryService.NOT_SUPPORTED_PATTERN;

@Service
@RequiredArgsConstructor
public class BitbucketCloudService implements GitClientService {
Expand All @@ -67,7 +69,6 @@ public class BitbucketCloudService implements GitClientService {
private static final String BITBUCKET_CLOUD_FILE_MARKER = "commit_file";
private static final int MAX_DEPTH = 20;
private static final String PAGE_PARAMETER = "page=";
private static final String NOT_SUPPORTED_PATTERN = "%s is not supported for Bitbucket Cloud repository";
private final BitbucketCloudMapper mapper;
private final MessageHelper messageHelper;
private final PreferenceManager preferenceManager;
Expand Down Expand Up @@ -275,37 +276,37 @@ public GitCommitEntry updateFile(final Pipeline pipeline, final String path, fin
@Override
public GitCommitEntry renameFile(final Pipeline pipeline, final String message,
final String filePreviousPath, final String filePath) {
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "File renaming"));
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "File renaming", getType()));
}

@Override
public GitCommitEntry deleteFile(final Pipeline pipeline, final String filePath, final String commitMessage) {
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "File deletion"));
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "File deletion", getType()));
}

@Override
public GitCommitEntry createFolder(final Pipeline pipeline, final List<String> filesToCreate,
final String message) {
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "Folder creation"));
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "Folder creation", getType()));
}

@Override
public GitCommitEntry renameFolder(final Pipeline pipeline, final String message,
final String folder, final String newFolderName) {
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "Folder renaming"));
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "Folder renaming", getType()));
}

@Override
public GitCommitEntry deleteFolder(final Pipeline pipeline, final String message, final String folder) {
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "Folder deletion"));
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "Folder deletion", getType()));
}

@Override
public GitCommitEntry updateFiles(final Pipeline pipeline, final PipelineSourceItemsVO sourceItemVOList,
final String message) {
if (ListUtils.emptyIfNull(sourceItemVOList.getItems()).stream()
.anyMatch(sourceItemVO -> StringUtils.isNotBlank(sourceItemVO.getPreviousPath()))) {
throw new UnsupportedOperationException(NOT_SUPPORTED_PATTERN);
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "File renaming", getType()));
}
final BitbucketCloudClient client = getClient(pipeline);

Expand All @@ -318,7 +319,8 @@ public GitCommitEntry updateFiles(final Pipeline pipeline, final PipelineSourceI
@Override
public GitCommitEntry uploadFiles(final Pipeline pipeline, final List<UploadFileMetadata> files,
final String message) {
Assert.isTrue(files.size() == 1, String.format(NOT_SUPPORTED_PATTERN, "Multiple files upload"));
Assert.isTrue(files.size() == 1,
String.format(NOT_SUPPORTED_PATTERN, "Multiple files upload", getType()));
final UploadFileMetadata file = files.get(0);
final BitbucketCloudClient client = getClient(pipeline);
client.upsertFile(file.getFileName(), file.getFileType(), file.getBytes(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.epam.pipeline.manager.git.PipelineRepositoryService.NOT_SUPPORTED_PATTERN;

@Service
@RequiredArgsConstructor
public class GitHubService implements GitClientService {
private static final String REPOSITORY_NAME = "repository name";
private static final String PROJECT_NAME = "project name";
private static final String GITHUB_FOLDER_MARKER = "tree";
private static final String GITHUB_FILE_MARKER = "blob";
private static final String NOT_SUPPORTED_PATTERN = "%s is not supported for GitHub repository";
private static final String LINK = "link";
private static final String REL_NEXT = "rel=\"next\"";
private static final String COMMIT = "commit";
Expand All @@ -95,7 +96,7 @@ public GitProject createRepository(final String description,
final String path,
final String token,
final String visibility) {
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "Create repository"));
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "Create repository", getType()));
}

@Override
Expand Down Expand Up @@ -283,7 +284,7 @@ public GitCommitEntry updateFile(final Pipeline pipeline, final String path, fin
@Override
public GitCommitEntry renameFile(final Pipeline pipeline, final String message,
final String filePreviousPath, final String filePath) {
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "File renaming"));
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "File renaming", getType()));
}

@Override
Expand All @@ -296,26 +297,26 @@ public GitCommitEntry deleteFile(final Pipeline pipeline, final String filePath,
@Override
public GitCommitEntry createFolder(final Pipeline pipeline, final List<String> filesToCreate,
final String message) {
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "Folder creation"));
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "Folder creation", getType()));
}

@Override
public GitCommitEntry renameFolder(final Pipeline pipeline, final String message,
final String folder, final String newFolderName) {
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "Folder renaming"));
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "Folder renaming", getType()));
}

@Override
public GitCommitEntry deleteFolder(final Pipeline pipeline, final String message, final String folder) {
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "Folder deletion"));
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "Folder deletion", getType()));
}

@Override
public GitCommitEntry updateFiles(final Pipeline pipeline, final PipelineSourceItemsVO sourceItemVOList,
final String message) {
if (ListUtils.emptyIfNull(sourceItemVOList.getItems()).stream()
.anyMatch(sourceItemVO -> StringUtils.isNotBlank(sourceItemVO.getPreviousPath()))) {
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "File renaming"));
throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "File renaming", getType()));
}
final GitHubClient client = getClient(pipeline);
GitHubSource gitHubSource = null;
Expand All @@ -330,7 +331,8 @@ public GitCommitEntry updateFiles(final Pipeline pipeline, final PipelineSourceI
public GitCommitEntry uploadFiles(final Pipeline pipeline,
final List<UploadFileMetadata> files,
final String message) {
Assert.isTrue(files.size() == 1, String.format(NOT_SUPPORTED_PATTERN, "Multiple files upload"));
Assert.isTrue(files.size() == 1,
String.format(NOT_SUPPORTED_PATTERN, "Multiple files upload", getType()));
final UploadFileMetadata file = files.get(0);
final GitHubClient client = getClient(pipeline);
final GitHubSource gitHubSource = client.createFile(file.getFileName(), file.getBytes(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
@AclSync
public class PipelineManager implements SecuredEntityManager {

public static final String FROM_URLS_ONLY_PATTERN = "%s repository creation supported from urls only";
@Value("${templates.default.template}")
private String defaultTemplate;

Expand Down Expand Up @@ -111,10 +112,8 @@ public Pipeline create(final PipelineVO pipelineVO) throws GitClientException {
pipelineVO.setRepositoryType(RepositoryType.GITLAB);
}
if (StringUtils.isEmpty(pipelineVO.getRepository())) {
Assert.isTrue(RepositoryType.BITBUCKET != pipelineVO.getRepositoryType(),
"Bitbucket repository creation supported from urls only");
Assert.isTrue(RepositoryType.BITBUCKET_CLOUD != pipelineVO.getRepositoryType(),
"Bitbucket Cloud repository creation supported from urls only");
Assert.isTrue(RepositoryType.GITLAB.equals(pipelineVO.getRepositoryType()),
String.format(FROM_URLS_ONLY_PATTERN, pipelineVO.getRepositoryType()));
Assert.isTrue(!gitManager.checkProjectExists(pipelineVO.getName()),
messageHelper.getMessage(MessageConstants.ERROR_PIPELINE_REPO_EXISTS, pipelineVO.getName()));
final GitProject project = createGitRepository(pipelineVO);
Expand Down
Loading