@gohcltech/bitbucket-mcp
Version:
Bitbucket integration for Claude via Model Context Protocol
220 lines • 9.91 kB
TypeScript
/**
* @fileoverview Commit-specific HTTP client for Bitbucket API operations.
*
* This module provides commit-related functionality including:
* - Listing commits with branch and filtering options
* - Getting detailed commit information and metadata
* - Retrieving commit diffs to see code changes
* - Generating Git patches for commit application
* - Commit history analysis and exploration
*
* Commits represent individual changes to the repository and contain
* information about what changed, who made the change, when it occurred,
* and the complete history of the repository.
*/
import { BaseClient, BitbucketApiResponse } from './base-client.js';
import { Commit, CommitDiff } from '../types/commit/index.js';
/**
* HTTP client for Bitbucket commit operations.
*
* Provides methods for exploring repository history, analyzing changes,
* and retrieving commit metadata. This client supports filtering commits
* by branch, author, date range, and other criteria to help understand
* code evolution and track specific changes.
*
* @example
* ```typescript
* const client = new CommitClient(oauthService);
*
* // Get recent commits from main branch
* const commits = await client.getCommits('workspace', 'repo', {
* include: 'main',
* pagelen: '10'
* });
*
* // Analyze specific commit changes
* const commit = await client.getCommit('workspace', 'repo', 'abc123def456');
* const diff = await client.getCommitDiff('workspace', 'repo', 'abc123def456');
*
* // Generate patch for applying changes
* const patch = await client.getCommitPatch('workspace', 'repo', 'abc123def456');
* ```
*/
export declare class CommitClient extends BaseClient {
/**
* Retrieves commits from a repository with optional filtering.
*
* Supports filtering by branch, author, date range, and path to find
* specific commits or analyze repository history. Commits are returned
* in reverse chronological order (newest first) by default.
*
* @param workspaceSlug - Unique identifier for the workspace
* @param repoSlug - Unique identifier for the repository
* @param params - Optional query parameters for filtering commits
* @param params.include - Branch or commit to include in the results
* @param params.exclude - Branch or commit to exclude from the results
* @param params.path - Filter commits that touched specific file/directory path
* @param params.author - Filter by commit author username
* @param params.since - ISO 8601 date to filter commits after this date
* @param params.until - ISO 8601 date to filter commits before this date
* @param params.pagelen - Number of commits per page (default: 30, max: 100)
* @returns Promise resolving to paginated commit list
* @throws {AuthenticationError} If not authenticated
* @throws {BitbucketApiError} If repository not found or request fails
*
* @example
* ```typescript
* // Get recent commits from develop branch
* const recentCommits = await client.getCommits('workspace', 'repo', {
* include: 'develop',
* pagelen: '20'
* });
*
* // Get commits by specific author
* const authorCommits = await client.getCommits('workspace', 'repo', {
* author: 'john.doe',
* since: '2024-01-01T00:00:00Z'
* });
*
* // Get commits that modified a specific file
* const fileCommits = await client.getCommits('workspace', 'repo', {
* path: 'src/auth/oauth.ts'
* });
* ```
*/
getCommits(workspaceSlug: string, repoSlug: string, params?: Record<string, string>): Promise<BitbucketApiResponse<Commit>>;
/**
* Retrieves all commits from a repository (all pages) with optional filtering.
*
* This method automatically handles pagination to return all commits
* across multiple pages. Use this when you need a complete history
* or want to perform comprehensive analysis across all commits.
*
* @param workspaceSlug - Unique identifier for the workspace
* @param repoSlug - Unique identifier for the repository
* @param params - Optional query parameters for filtering commits
* @returns Promise resolving to array of all matching commits
* @throws {AuthenticationError} If not authenticated
* @throws {BitbucketApiError} If repository not found or request fails
*
* @example
* ```typescript
* // Get complete commit history for analysis
* const allCommits = await client.getAllCommits('workspace', 'repo');
*
* // Get all commits from a feature branch
* const featureCommits = await client.getAllCommits('workspace', 'repo', {
* include: 'feature/auth',
* exclude: 'develop'
* });
*
* // Analyze commit patterns
* const commitsByAuthor = allCommits.reduce((groups, commit) => {
* const author = commit.author.user?.display_name || 'Unknown';
* groups[author] = (groups[author] || 0) + 1;
* return groups;
* }, {});
* ```
*/
getAllCommits(workspaceSlug: string, repoSlug: string, params?: Record<string, string>): Promise<Commit[]>;
/**
* Retrieves detailed information for a specific commit.
*
* Returns comprehensive commit data including author information,
* commit message, timestamp, parent commits, and file statistics.
* This is useful for commit inspection and analysis.
*
* @param workspaceSlug - Unique identifier for the workspace
* @param repoSlug - Unique identifier for the repository
* @param commitHash - SHA-1 hash of the commit (40 hexadecimal characters)
* @returns Promise resolving to detailed commit information
* @throws {AuthenticationError} If not authenticated
* @throws {BitbucketApiError} If commit not found or request fails
*
* @example
* ```typescript
* // Get commit details for inspection
* const commit = await client.getCommit('workspace', 'repo', 'abc123def456');
* console.log(`Commit: ${commit.message}`);
* console.log(`Author: ${commit.author.user?.display_name}`);
* console.log(`Date: ${commit.date}`);
* console.log(`Files changed: ${commit.summary?.file_changes || 'Unknown'}`);
* console.log(`Parents: ${commit.parents.map(p => p.hash.substring(0, 8)).join(', ')}`);
* ```
*/
getCommit(workspaceSlug: string, repoSlug: string, commitHash: string): Promise<Commit>;
/**
* Retrieves the diff showing changes introduced by a specific commit.
*
* Returns a unified diff format showing all changes made in the commit
* including added, modified, and deleted lines. Supports filtering
* to specific files and controlling diff context lines.
*
* @param workspaceSlug - Unique identifier for the workspace
* @param repoSlug - Unique identifier for the repository
* @param commitHash - SHA-1 hash of the commit (40 hexadecimal characters)
* @param params - Optional parameters for diff customization
* @param params.path - Filter diff to specific file path
* @param params.context - Number of context lines around changes (default: 3)
* @param params.ignore_whitespace - Whether to ignore whitespace changes
* @param params.binary - Whether to include binary file changes
* @returns Promise resolving to commit diff data
* @throws {AuthenticationError} If not authenticated
* @throws {BitbucketApiError} If commit not found or request fails
*
* @example
* ```typescript
* // Get complete diff for a commit
* const diff = await client.getCommitDiff('workspace', 'repo', 'abc123def456');
* console.log('Files changed:', diff.diffstat?.files_changed);
* console.log('Lines added:', diff.diffstat?.lines_added);
* console.log('Lines removed:', diff.diffstat?.lines_removed);
*
* // Get diff for specific file with more context
* const fileDiff = await client.getCommitDiff('workspace', 'repo', 'abc123def456', {
* path: 'src/auth.ts',
* context: '5'
* });
*
* // Get diff ignoring whitespace changes
* const cleanDiff = await client.getCommitDiff('workspace', 'repo', 'abc123def456', {
* ignore_whitespace: 'true'
* });
* ```
*/
getCommitDiff(workspaceSlug: string, repoSlug: string, commitHash: string, params?: Record<string, string>): Promise<CommitDiff>;
/**
* Generates a Git-compatible patch for a specific commit.
*
* Returns the commit changes in Git patch format that can be applied
* using 'git apply' or 'git am'. This is useful for transferring
* specific commits between repositories or creating patches for
* external distribution.
*
* @param workspaceSlug - Unique identifier for the workspace
* @param repoSlug - Unique identifier for the repository
* @param commitHash - SHA-1 hash of the commit (40 hexadecimal characters)
* @returns Promise resolving to Git patch format string
* @throws {AuthenticationError} If not authenticated
* @throws {BitbucketApiError} If commit not found or request fails
*
* @example
* ```typescript
* // Generate patch for commit
* const patch = await client.getCommitPatch('workspace', 'repo', 'abc123def456');
*
* // Save patch to file for later application
* await fs.writeFile('feature-patch.patch', patch);
*
* // The patch can then be applied with:
* // git apply feature-patch.patch
* // or
* // git am feature-patch.patch
*
* console.log('Patch generated successfully');
* console.log(`Patch size: ${patch.length} bytes`);
* ```
*/
getCommitPatch(workspaceSlug: string, repoSlug: string, commitHash: string): Promise<string>;
}
//# sourceMappingURL=commit-client.d.ts.map