Skip to content

Commit

Permalink
Issue 3636 Bitbucket Cloud Support - fix billing and folder creation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
okolesn authored Aug 27, 2024
1 parent b058b2a commit 6a310f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -274,37 +275,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("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<String> 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
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("File renaming is not supported for Bitbucket repository");
throw new UnsupportedOperationException(NOT_SUPPORTED_PATTERN);
}
final BitbucketCloudClient client = getClient(pipeline);

Expand All @@ -317,7 +318,7 @@ 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, "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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@
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<Long, RepositoryType> idMap = new HashMap<>();
static {
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<String, RepositoryType> 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) {
Expand Down

0 comments on commit 6a310f4

Please sign in to comment.