From 6a310f4a7f21d5d160930fce887db833d0601e14 Mon Sep 17 00:00:00 2001 From: Oksana Kolesnikova <83080415+okolesn@users.noreply.github.com> Date: Tue, 27 Aug 2024 10:42:17 +0300 Subject: [PATCH] Issue 3636 Bitbucket Cloud Support - fix billing and folder creation (#3655) --- .../manager/git/PipelineRepositoryService.java | 6 ++++++ .../bitbucketcloud/BitbucketCloudService.java | 17 +++++++++-------- .../entity/pipeline/RepositoryType.java | 4 +++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/api/src/main/java/com/epam/pipeline/manager/git/PipelineRepositoryService.java b/api/src/main/java/com/epam/pipeline/manager/git/PipelineRepositoryService.java index 585f531c22..51c67002cf 100644 --- a/api/src/main/java/com/epam/pipeline/manager/git/PipelineRepositoryService.java +++ b/api/src/main/java/com/epam/pipeline/manager/git/PipelineRepositoryService.java @@ -267,6 +267,9 @@ 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"); + } Assert.isTrue(lastCommitId.equals(pipeline.getCurrentVersion().getCommitId()), messageHelper.getMessage(MessageConstants.ERROR_REPOSITORY_FILE_WAS_UPDATED, folder)); Assert.isTrue(!folderExists(pipeline, folder), @@ -297,6 +300,9 @@ 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"); + } final String message = StringUtils.isNotBlank(commitMessage) ? commitMessage : String.format("Renaming folder %s to %s", folder, newFolderName); diff --git a/api/src/main/java/com/epam/pipeline/manager/git/bitbucketcloud/BitbucketCloudService.java b/api/src/main/java/com/epam/pipeline/manager/git/bitbucketcloud/BitbucketCloudService.java index 86fa121486..d4e02cde11 100644 --- a/api/src/main/java/com/epam/pipeline/manager/git/bitbucketcloud/BitbucketCloudService.java +++ b/api/src/main/java/com/epam/pipeline/manager/git/bitbucketcloud/BitbucketCloudService.java @@ -66,7 +66,8 @@ public class BitbucketCloudService implements GitClientService { private static final String BITBUCKET_CLOUD_FOLDER_MARKER = "commit_directory"; private static final String BITBUCKET_CLOUD_FILE_MARKER = "commit_file"; private static final int MAX_DEPTH = 20; - public static final String PAGE_PARAMETER = "page="; + 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; @@ -274,29 +275,29 @@ 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("File renaming is not supported for Bitbucket repository"); + throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "File renaming")); } @Override public GitCommitEntry deleteFile(final Pipeline pipeline, final String filePath, final String commitMessage) { - throw new UnsupportedOperationException("File deletion is not supported for Bitbucket repository"); + throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "File deletion")); } @Override public GitCommitEntry createFolder(final Pipeline pipeline, final List filesToCreate, final String message) { - throw new UnsupportedOperationException("Folder creation is not supported for Bitbucket repository"); + throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "Folder creation")); } @Override public GitCommitEntry renameFolder(final Pipeline pipeline, final String message, final String folder, final String newFolderName) { - throw new UnsupportedOperationException("Folder renaming is not supported for Bitbucket repository"); + throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "Folder renaming")); } @Override public GitCommitEntry deleteFolder(final Pipeline pipeline, final String message, final String folder) { - throw new UnsupportedOperationException("Folder deletion is not supported for Bitbucket repository"); + throw new UnsupportedOperationException(String.format(NOT_SUPPORTED_PATTERN, "Folder deletion")); } @Override @@ -304,7 +305,7 @@ public GitCommitEntry updateFiles(final Pipeline pipeline, final PipelineSourceI final String message) { if (ListUtils.emptyIfNull(sourceItemVOList.getItems()).stream() .anyMatch(sourceItemVO -> StringUtils.isNotBlank(sourceItemVO.getPreviousPath()))) { - throw new UnsupportedOperationException("File renaming is not supported for Bitbucket repository"); + throw new UnsupportedOperationException(NOT_SUPPORTED_PATTERN); } final BitbucketCloudClient client = getClient(pipeline); @@ -317,7 +318,7 @@ public GitCommitEntry updateFiles(final Pipeline pipeline, final PipelineSourceI @Override public GitCommitEntry uploadFiles(final Pipeline pipeline, final List files, final String message) { - Assert.isTrue(files.size() == 1, "Multiple files upload is not supported for Bitbucket repository"); + Assert.isTrue(files.size() == 1, String.format(NOT_SUPPORTED_PATTERN, "Multiple files upload")); final UploadFileMetadata file = files.get(0); final BitbucketCloudClient client = getClient(pipeline); client.upsertFile(file.getFileName(), file.getFileType(), file.getBytes(), diff --git a/cloud-pipeline-common/model/src/main/java/com/epam/pipeline/entity/pipeline/RepositoryType.java b/cloud-pipeline-common/model/src/main/java/com/epam/pipeline/entity/pipeline/RepositoryType.java index 6439a1fc4e..db7846980c 100644 --- a/cloud-pipeline-common/model/src/main/java/com/epam/pipeline/entity/pipeline/RepositoryType.java +++ b/cloud-pipeline-common/model/src/main/java/com/epam/pipeline/entity/pipeline/RepositoryType.java @@ -20,7 +20,7 @@ import java.util.Map; public enum RepositoryType { - GITLAB(0), GITHUB(1), BITBUCKET(2); + GITLAB(0), GITHUB(1), BITBUCKET(2), BITBUCKET_CLOUD(3); private long id; private static Map idMap = new HashMap<>(); @@ -28,12 +28,14 @@ public enum RepositoryType { idMap.put(GITLAB.id, GITLAB); idMap.put(GITHUB.id, GITHUB); idMap.put(BITBUCKET.id, BITBUCKET); + idMap.put(BITBUCKET_CLOUD.id, BITBUCKET_CLOUD); } private static Map namesMap = new HashMap<>(); static { namesMap.put(GITLAB.name(), GITLAB); namesMap.put(GITHUB.name(), GITHUB); namesMap.put(BITBUCKET.name(), BITBUCKET); + namesMap.put(BITBUCKET_CLOUD.name(), BITBUCKET_CLOUD); } RepositoryType(long id) {