@gohcltech/bitbucket-mcp
Version:
Bitbucket integration for Claude via Model Context Protocol
129 lines • 5.5 kB
JavaScript
/**
* @fileoverview Repository-specific HTTP client for Bitbucket API operations.
*
* This module provides repository-related functionality including:
* - Listing repositories in a workspace
* - Getting detailed repository information
* - Creating new repositories
* - Updating repository settings
* - Deleting repositories
*
*/
import { BaseClient } from './base-client.js';
/**
* HTTP client for Bitbucket repository operations.
*
* Provides methods for managing repositories within workspaces including
* CRUD operations and repository configuration management.
*/
export class RepositoryClient extends BaseClient {
// =============================================================================
// REPOSITORY API METHODS
// =============================================================================
/**
* Retrieves all repositories in a workspace.
*
* @param workspaceSlug - Unique identifier for the workspace
* @returns Promise resolving to paginated repository list
* @throws {AuthenticationError} If not authenticated
* @throws {BitbucketApiError} If workspace not found or request fails
*/
async getRepositories(workspaceSlug) {
return this.get(`/repositories/${workspaceSlug}`, undefined, {
operationName: 'get_repositories',
});
}
/**
* Retrieves all repositories in a workspace (all pages).
*
* This method automatically handles pagination to return all repositories
* across multiple pages. Use this when you need a complete list of repositories.
*
* @param workspaceSlug - Unique identifier for the workspace
* @returns Promise resolving to array of all repositories
* @throws {AuthenticationError} If not authenticated
* @throws {BitbucketApiError} If workspace not found or request fails
*/
async getAllRepositories(workspaceSlug) {
// Try without role parameter to get all accessible repositories
const params = {
sort: 'created_on',
pagelen: '100', // Use larger page size to reduce API calls
};
return this.getAllPages(`/repositories/${workspaceSlug}`, params, {
operationName: 'get_all_repositories',
});
}
/**
* Retrieves details for a specific repository.
*
* @param workspaceSlug - Unique identifier for the workspace
* @param repoSlug - Unique identifier for the repository
* @returns Promise resolving to repository details
* @throws {AuthenticationError} If not authenticated
* @throws {BitbucketApiError} If repository not found or request fails
*/
async getRepository(workspaceSlug, repoSlug) {
return this.get(`/repositories/${workspaceSlug}/${repoSlug}`, undefined, {
operationName: 'get_repository',
});
}
/**
* Creates a new repository in the specified workspace.
*
* @param workspaceSlug - Unique identifier for the workspace
* @param name - Name for the new repository
* @param payload - Repository configuration (privacy, description, etc.)
* @returns Promise resolving to created repository details
* @throws {AuthenticationError} If not authenticated
* @throws {BitbucketApiError} If creation fails or name conflicts exist
*/
async createRepository(workspaceSlug, name, payload) {
return this.post(`/repositories/${workspaceSlug}/${name}`, payload, {
operationName: 'create_repository',
priority: 3, // Higher priority for creation operations
});
}
/**
* Updates an existing repository's settings and metadata.
*
* Allows modification of repository properties including:
* - Name and description
* - Privacy settings (public/private)
* - Fork policies
* - Issue and wiki settings
* - Website URL and language
*
* @param workspaceSlug - Unique identifier for the workspace
* @param repoSlug - Current unique identifier for the repository
* @param payload - Repository update data (only specified fields will be updated)
* @returns Promise resolving to the updated repository data
* @throws {AuthenticationError} If not authenticated
* @throws {BitbucketApiError} If repository not found or update fails
*/
async updateRepository(workspaceSlug, repoSlug, payload) {
return this.put(`/repositories/${workspaceSlug}/${repoSlug}`, payload, {
operationName: 'update_repository',
priority: 1, // High priority for configuration changes
});
}
/**
* Deletes a repository permanently.
*
* WARNING: This operation is irreversible and will delete all repository data,
* including code, issues, pull requests, and commit history.
*
* @param workspaceSlug - Unique identifier for the workspace
* @param repoSlug - Unique identifier for the repository to delete
* @returns Promise that resolves when deletion is complete
* @throws {AuthenticationError} If not authenticated
* @throws {BitbucketApiError} If repository not found or deletion fails
*/
async deleteRepository(workspaceSlug, repoSlug) {
return this.delete(`/repositories/${workspaceSlug}/${repoSlug}`, {
operationName: 'delete_repository',
priority: 2, // Highest priority for destructive operations
});
}
}
//# sourceMappingURL=repository-client.js.map