mcp-bitbucket-server 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/CLAUDE.md +97 -8
  2. package/dist/client/bitbucket.client.d.ts +71 -0
  3. package/dist/client/bitbucket.client.d.ts.map +1 -0
  4. package/dist/client/bitbucket.client.js +151 -0
  5. package/dist/client/bitbucket.client.js.map +1 -0
  6. package/dist/{types/pull-request.d.ts → client/bitbucket.types.d.ts} +311 -88
  7. package/dist/client/bitbucket.types.d.ts.map +1 -0
  8. package/dist/client/bitbucket.types.js +5 -0
  9. package/dist/client/bitbucket.types.js.map +1 -0
  10. package/dist/client/index.d.ts +3 -0
  11. package/dist/client/index.d.ts.map +1 -0
  12. package/dist/client/index.js +4 -0
  13. package/dist/client/index.js.map +1 -0
  14. package/dist/index.d.ts +1 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +4 -0
  17. package/dist/index.js.map +1 -1
  18. package/dist/services/bitbucket.d.ts +6 -1
  19. package/dist/services/bitbucket.d.ts.map +1 -1
  20. package/dist/services/bitbucket.js +8 -6
  21. package/dist/services/bitbucket.js.map +1 -1
  22. package/dist/tools/index.d.ts.map +1 -1
  23. package/dist/tools/index.js +6 -1
  24. package/dist/tools/index.js.map +1 -1
  25. package/dist/tools/projects/list_projects.d.ts.map +1 -1
  26. package/dist/tools/projects/list_projects.js +3 -5
  27. package/dist/tools/projects/list_projects.js.map +1 -1
  28. package/dist/tools/pull-requests/add_pr_comment.d.ts.map +1 -1
  29. package/dist/tools/pull-requests/add_pr_comment.js +16 -26
  30. package/dist/tools/pull-requests/add_pr_comment.js.map +1 -1
  31. package/dist/tools/pull-requests/add_pr_file_comment.d.ts +3 -0
  32. package/dist/tools/pull-requests/add_pr_file_comment.d.ts.map +1 -0
  33. package/dist/tools/pull-requests/add_pr_file_comment.js +33 -0
  34. package/dist/tools/pull-requests/add_pr_file_comment.js.map +1 -0
  35. package/dist/tools/pull-requests/add_pr_line_comment.d.ts +3 -0
  36. package/dist/tools/pull-requests/add_pr_line_comment.d.ts.map +1 -0
  37. package/dist/tools/pull-requests/add_pr_line_comment.js +41 -0
  38. package/dist/tools/pull-requests/add_pr_line_comment.js.map +1 -0
  39. package/dist/tools/pull-requests/delete_pr_comment.d.ts +3 -0
  40. package/dist/tools/pull-requests/delete_pr_comment.d.ts.map +1 -0
  41. package/dist/tools/pull-requests/delete_pr_comment.js +33 -0
  42. package/dist/tools/pull-requests/delete_pr_comment.js.map +1 -0
  43. package/dist/tools/pull-requests/get_inbox_pull_requests.d.ts.map +1 -1
  44. package/dist/tools/pull-requests/get_inbox_pull_requests.js +10 -16
  45. package/dist/tools/pull-requests/get_inbox_pull_requests.js.map +1 -1
  46. package/dist/tools/pull-requests/get_pr_activities.d.ts.map +1 -1
  47. package/dist/tools/pull-requests/get_pr_activities.js +15 -11
  48. package/dist/tools/pull-requests/get_pr_activities.js.map +1 -1
  49. package/dist/tools/pull-requests/get_pr_changes.d.ts.map +1 -1
  50. package/dist/tools/pull-requests/get_pr_changes.js +8 -3
  51. package/dist/tools/pull-requests/get_pr_changes.js.map +1 -1
  52. package/dist/tools/pull-requests/get_pr_details.d.ts +3 -0
  53. package/dist/tools/pull-requests/get_pr_details.d.ts.map +1 -0
  54. package/dist/tools/pull-requests/get_pr_details.js +29 -0
  55. package/dist/tools/pull-requests/get_pr_details.js.map +1 -0
  56. package/dist/tools/pull-requests/get_pr_diff.d.ts +3 -0
  57. package/dist/tools/pull-requests/get_pr_diff.d.ts.map +1 -0
  58. package/dist/tools/pull-requests/get_pr_diff.js +40 -0
  59. package/dist/tools/pull-requests/get_pr_diff.js.map +1 -0
  60. package/dist/tools/pull-requests/get_pr_file_diff.d.ts.map +1 -1
  61. package/dist/tools/pull-requests/get_pr_file_diff.js +9 -3
  62. package/dist/tools/pull-requests/get_pr_file_diff.js.map +1 -1
  63. package/dist/tools/pull-requests/index.d.ts +5 -0
  64. package/dist/tools/pull-requests/index.d.ts.map +1 -1
  65. package/dist/tools/pull-requests/index.js +5 -0
  66. package/dist/tools/pull-requests/index.js.map +1 -1
  67. package/dist/tools/pull-requests/update_review_status.d.ts.map +1 -1
  68. package/dist/tools/pull-requests/update_review_status.js +11 -13
  69. package/dist/tools/pull-requests/update_review_status.js.map +1 -1
  70. package/dist/tools/repositories/list_repositories.d.ts.map +1 -1
  71. package/dist/tools/repositories/list_repositories.js +10 -22
  72. package/dist/tools/repositories/list_repositories.js.map +1 -1
  73. package/dist/tools/tools.types.d.ts +122 -0
  74. package/dist/tools/tools.types.d.ts.map +1 -0
  75. package/dist/tools/tools.types.js +7 -0
  76. package/dist/tools/tools.types.js.map +1 -0
  77. package/dist/tools/users/get_all_users.js +5 -5
  78. package/dist/tools/users/get_all_users.js.map +1 -1
  79. package/dist/tools/users/get_user_profile.d.ts.map +1 -1
  80. package/dist/tools/users/get_user_profile.js +5 -3
  81. package/dist/tools/users/get_user_profile.js.map +1 -1
  82. package/package.json +1 -1
  83. package/dist/types/common.d.ts +0 -19
  84. package/dist/types/common.d.ts.map +0 -1
  85. package/dist/types/common.js +0 -2
  86. package/dist/types/common.js.map +0 -1
  87. package/dist/types/index.d.ts +0 -8
  88. package/dist/types/index.d.ts.map +0 -1
  89. package/dist/types/index.js +0 -11
  90. package/dist/types/index.js.map +0 -1
  91. package/dist/types/pull-request.d.ts.map +0 -1
  92. package/dist/types/pull-request.js +0 -2
  93. package/dist/types/pull-request.js.map +0 -1
  94. package/dist/types/repository.d.ts +0 -70
  95. package/dist/types/repository.d.ts.map +0 -1
  96. package/dist/types/repository.js +0 -2
  97. package/dist/types/repository.js.map +0 -1
package/CLAUDE.md CHANGED
@@ -6,8 +6,9 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
6
6
 
7
7
  This is an MCP (Model Context Protocol) server for Bitbucket Server/Data Center integration. The server provides tools for:
8
8
  - **User management**: Get user profile, list all users
9
+ - **Project operations**: List projects with filtering
9
10
  - **Repository operations**: List repositories in a project
10
- - **Pull request operations**: Get changed files, get structured diffs, add comments (general, replies, and inline), update review status (approve/request changes)
11
+ - **Pull request operations**: Get PR details, get inbox PRs, get changed files, get full/file diffs (text and structured), add comments (three separate tools: general, file-level, and line-level), get activities, update review status (approve/request changes)
11
12
 
12
13
  ## Architecture
13
14
 
@@ -363,6 +364,46 @@ export const getAllUsersTool = (server: McpServer) => {
363
364
 
364
365
  **Purpose**: Discover all PRs across all projects and repositories that need your review in one call. Much more efficient than querying project by project. Use the `id`, `projectKey`, and `repositorySlug` from the response to review specific PRs with other tools.
365
366
 
367
+ ### bitbucket_get_pull_request
368
+ **File**: `src/tools/pull-requests/get_pr_details.ts`
369
+ **Endpoint**: `GET /projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}`
370
+ **Parameters**:
371
+ - `projectKey` (required): The Bitbucket Server project key
372
+ - `repositorySlug` (required): The repository slug
373
+ - `pullRequestId` (required): The pull request ID
374
+
375
+ **Returns**: Full pull request object including:
376
+ - `id`, `version`, `title`, `description`
377
+ - `state` (OPEN/MERGED/DECLINED), `open`, `closed`
378
+ - `fromRef` - Source branch with `displayId` (branch name) and `latestCommit`
379
+ - `toRef` - Destination branch with `displayId` and `latestCommit`
380
+ - `author` - Author user object with display name, role, and approval status
381
+ - `reviewers` - Array of reviewer objects
382
+ - `participants` - Array of participant objects
383
+ - `createdDate`, `updatedDate` - Timestamps
384
+
385
+ **Purpose**: Get comprehensive metadata for a pull request. Use this when you need full PR details including source/destination branches, author information, and reviewers. Essential for tools that need to understand PR context before performing operations.
386
+
387
+ ### bitbucket_get_pull_request_diff
388
+ **File**: `src/tools/pull-requests/get_pr_diff.ts`
389
+ **Endpoint**: `GET /projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/diff/{path}`
390
+ **Parameters**:
391
+ - `projectKey` (required): The Bitbucket Server project key
392
+ - `repositorySlug` (required): The repository slug
393
+ - `pullRequestId` (required): The pull request ID
394
+ - `path` (optional): File path (omit or empty string for full PR diff)
395
+ - `contextLines` (optional): Number of context lines around changes (default: 10)
396
+ - `whitespace` (optional): 'show' or 'ignore-all' (default: show)
397
+ - `format` (optional): 'text' or 'json' (default: 'text')
398
+ - `'text'`: Returns raw diff as plain text string (uses `Accept: text/plain` header)
399
+ - `'json'`: Returns structured diff object with hunks/segments (uses `Accept: application/json` header)
400
+
401
+ **Returns**:
402
+ - When `format='text'` (default): Raw diff as plain text in unified diff format (string)
403
+ - When `format='json'`: Structured diff object (DiffResponse) with hunks, segments, and line-by-line data
404
+
405
+ **Purpose**: Get the complete diff for a PR in one call (when `path` is omitted) or for a specific file. The format parameter controls the response type based on the Accept header. Use `format='text'` (default) for raw text suitable for parsing or display - the background-greg service uses this for generating PR review contexts. Use `format='json'` when you need structured data with exact line numbers and segments.
406
+
366
407
  ### bitbucket_add_pr_comment
367
408
  **File**: `src/tools/pull-requests/add_pr_comment.ts`
368
409
  **Endpoint**: `POST /projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/comments`
@@ -371,13 +412,42 @@ export const getAllUsersTool = (server: McpServer) => {
371
412
  - `repositorySlug` (required): The repository slug
372
413
  - `pullRequestId` (required): The pull request ID
373
414
  - `text` (required): The comment text
374
- - `parentId` (optional): Parent comment ID for replies
375
- - `path` (optional): File path for file-specific comments
376
- - `line` (optional): Line number for inline comments
377
- - `lineType` (optional): "ADDED", "REMOVED", or "CONTEXT" (default: CONTEXT)
378
- - `fileType` (optional): "FROM" or "TO" (default: TO)
415
+ - `parentId` (optional): Parent comment ID to reply to an existing comment
416
+
417
+ **Purpose**: Add a general comment to a pull request that is not attached to any specific file or line. Also use this tool for all replies - when you provide `parentId`, the reply automatically inherits the location (file/line) from the parent comment, so you don't need to specify path/line/lineType/fileType. For creating file-specific or line-specific comments, use the specialized tools below.
418
+
419
+ **Returns**: Simple success message with comment ID.
420
+
421
+ ### bitbucket_add_pr_file_comment
422
+ **File**: `src/tools/pull-requests/add_pr_file_comment.ts`
423
+ **Endpoint**: `POST /projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/comments`
424
+ **Parameters**:
425
+ - `projectKey` (required): The Bitbucket Server project key
426
+ - `repositorySlug` (required): The repository slug
427
+ - `pullRequestId` (required): The pull request ID
428
+ - `text` (required): The comment text
429
+ - `path` (required): File path to attach the comment to (e.g., "src/main.ts")
379
430
 
380
- **Note**: This single tool handles general comments, replies, and inline file/line comments through optional parameters.
431
+ **Purpose**: Add a comment attached to a specific file in the PR (file-level comment, not line-specific). The comment will appear at the file level in the PR diff view. For replies to existing comments, use bitbucket_add_pr_comment with parentId.
432
+
433
+ **Returns**: Simple success message with comment ID.
434
+
435
+ ### bitbucket_add_pr_line_comment
436
+ **File**: `src/tools/pull-requests/add_pr_line_comment.ts`
437
+ **Endpoint**: `POST /projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/comments`
438
+ **Parameters**:
439
+ - `projectKey` (required): The Bitbucket Server project key
440
+ - `repositorySlug` (required): The repository slug
441
+ - `pullRequestId` (required): The pull request ID
442
+ - `text` (required): The comment text
443
+ - `path` (required): File path (e.g., "src/main.ts")
444
+ - `line` (required): Line number to comment on (use destination line number from diff)
445
+ - `lineType` (required): Type of line - "ADDED" (green +), "REMOVED" (red -), or "CONTEXT" (unchanged)
446
+ - `fileType` (required): Side of diff - "FROM" (source/old) or "TO" (destination/new)
447
+
448
+ **Purpose**: Add an inline comment to a specific line in the PR diff. Use line numbers from `bitbucket_get_pull_request_file_diff` (destination line for TO side, source line for FROM side). Match the `lineType` to the segment type from the diff. For replies to existing comments, use bitbucket_add_pr_comment with parentId.
449
+
450
+ **Returns**: Simple success message with comment ID.
381
451
 
382
452
  ### bitbucket_get_pull_request_changes
383
453
  **File**: `src/tools/pull-requests/get_pr_changes.ts`
@@ -471,6 +541,25 @@ export const getAllUsersTool = (server: McpServer) => {
471
541
 
472
542
  **Note**: The tool makes a lightweight request to `/application-properties` to extract the authenticated username from the `X-AUSERNAME` response header, eliminating the need for users to provide their own slug.
473
543
 
544
+ ### bitbucket_delete_pr_comment
545
+ **File**: `src/tools/pull-requests/delete_pr_comment.ts`
546
+ **Endpoint**: `DELETE /projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/comments/{commentId}`
547
+ **Parameters**:
548
+ - `projectKey` (required): The Bitbucket Server project key
549
+ - `repositorySlug` (required): The repository slug
550
+ - `pullRequestId` (required): The pull request ID
551
+ - `commentId` (required): The ID of the comment to delete
552
+ - `version` (required): The expected version of the comment (for optimistic locking)
553
+
554
+ **Returns**: Simple success message confirming deletion.
555
+
556
+ **Purpose**: Delete a pull request comment. You can delete your own comments. Only REPO_ADMIN users can delete comments created by others. Comments with replies cannot be deleted. The `version` parameter must be provided to prevent concurrent modification conflicts - get the version from the comment object returned by other tools.
557
+
558
+ **Permissions**:
559
+ - Own comments: Any user can delete their own comments
560
+ - Others' comments: Requires REPO_ADMIN permission
561
+ - Comments with replies: Cannot be deleted (will return error)
562
+
474
563
  ## Pull Request Review Workflow
475
564
 
476
565
  For agents reviewing PRs and leaving comments on specific lines:
@@ -508,7 +597,7 @@ For agents reviewing PRs and leaving comments on specific lines:
508
597
 
509
598
  4. **Comment on specific lines**:
510
599
  ```
511
- bitbucket_add_pr_comment(
600
+ bitbucket_add_pr_line_comment(
512
601
  projectKey, repositorySlug, pullRequestId,
513
602
  text="Consider using const here",
514
603
  path="src/main.ts",
@@ -0,0 +1,71 @@
1
+ import type { AddPullRequestCommentParams, ChangesResponse, DeletePullRequestCommentParams, DiffResponse, GetAllUsersParams, GetInboxPullRequestsParams, GetPullRequestActivitiesParams, GetPullRequestChangesParams, GetPullRequestDiffParams, GetPullRequestFileDiffParams, GetPullRequestParams, GetUserProfileParams, InboxPullRequest, ListProjectsParams, ListRepositoriesParams, PaginatedResponse, RepositoriesResponse, RestComment, RestProject, RestPullRequest, RestPullRequestActivityApiResponse, RestPullRequestParticipant, RestUser, UpdateReviewStatusParams } from './bitbucket.types.js';
2
+ /**
3
+ * Bitbucket Server API client.
4
+ * Provides typed methods for interacting with Bitbucket Server REST API.
5
+ */
6
+ export declare class BitbucketService {
7
+ private client;
8
+ constructor(config: {
9
+ baseUrl: string;
10
+ token: string;
11
+ });
12
+ /**
13
+ * Get a Bitbucket Server user profile by username
14
+ */
15
+ getUserProfile(params: GetUserProfileParams): Promise<RestUser>;
16
+ /**
17
+ * Get all users, optionally filtered by search term
18
+ */
19
+ getAllUsers(params?: GetAllUsersParams): Promise<PaginatedResponse<RestUser>>;
20
+ /**
21
+ * List projects, optionally filtered by name or permission
22
+ */
23
+ listProjects(params?: ListProjectsParams): Promise<PaginatedResponse<RestProject>>;
24
+ /**
25
+ * List all repositories in a project
26
+ */
27
+ listRepositories(params: ListRepositoriesParams): Promise<RepositoriesResponse>;
28
+ /**
29
+ * Get pull requests in the authenticated user's inbox (where they are assigned as reviewer)
30
+ */
31
+ getInboxPullRequests(params?: GetInboxPullRequestsParams): Promise<PaginatedResponse<InboxPullRequest>>;
32
+ /**
33
+ * Get pull request details (title, description, author, branches, etc.)
34
+ */
35
+ getPullRequest(params: GetPullRequestParams): Promise<RestPullRequest>;
36
+ /**
37
+ * Get all changed files in a pull request
38
+ */
39
+ getPullRequestChanges(params: GetPullRequestChangesParams): Promise<ChangesResponse>;
40
+ /**
41
+ * Get structured line-by-line diff for a specific file in a pull request
42
+ */
43
+ getPullRequestFileDiff(params: GetPullRequestFileDiffParams): Promise<DiffResponse>;
44
+ /**
45
+ * Get diff for a pull request (or specific file).
46
+ * When path is empty or undefined, returns the full PR diff.
47
+ * Format controls the response type:
48
+ * - 'text': Raw diff as plain text string
49
+ * - 'json': Structured diff object (DiffResponse)
50
+ */
51
+ getPullRequestDiff(params: GetPullRequestDiffParams): Promise<string | DiffResponse>;
52
+ /**
53
+ * Get activity on a pull request (comments, approvals, merges, reviews, updates)
54
+ */
55
+ getPullRequestActivities(params: GetPullRequestActivitiesParams): Promise<PaginatedResponse<RestPullRequestActivityApiResponse>>;
56
+ /**
57
+ * Add a comment to a pull request (supports general comments, replies, and inline file/line comments)
58
+ */
59
+ addPullRequestComment(params: AddPullRequestCommentParams): Promise<RestComment>;
60
+ /**
61
+ * Delete a pull request comment. Returns void on success (HTTP 204).
62
+ * Anyone can delete their own comment. Only REPO_ADMIN can delete others' comments.
63
+ * Comments with replies cannot be deleted.
64
+ */
65
+ deletePullRequestComment(params: DeletePullRequestCommentParams): Promise<void>;
66
+ /**
67
+ * Update review status for a pull request (approve, request changes, or remove approval)
68
+ */
69
+ updateReviewStatus(params: UpdateReviewStatusParams): Promise<RestPullRequestParticipant>;
70
+ }
71
+ //# sourceMappingURL=bitbucket.client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitbucket.client.d.ts","sourceRoot":"","sources":["../../src/client/bitbucket.client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,2BAA2B,EAC3B,eAAe,EACf,8BAA8B,EAC9B,YAAY,EACZ,iBAAiB,EACjB,0BAA0B,EAC1B,8BAA8B,EAC9B,2BAA2B,EAC3B,wBAAwB,EACxB,4BAA4B,EAC5B,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EACtB,iBAAiB,EACjB,oBAAoB,EACpB,WAAW,EACX,WAAW,EACX,eAAe,EACf,kCAAkC,EAClC,0BAA0B,EAC1B,QAAQ,EACR,wBAAwB,EACzB,MAAM,sBAAsB,CAAC;AAE9B;;;GAGG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAgB;gBAElB,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;IAUtD;;OAEG;IACG,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAKrE;;OAEG;IACG,WAAW,CAAC,MAAM,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAOnF;;OAEG;IACG,YAAY,CAAC,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAOxF;;OAEG;IACG,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAKrF;;OAEG;IACG,oBAAoB,CAAC,MAAM,CAAC,EAAE,0BAA0B,GAAG,OAAO,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;IAK7G;;OAEG;IACG,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,eAAe,CAAC;IAQ5E;;OAEG;IACG,qBAAqB,CAAC,MAAM,EAAE,2BAA2B,GAAG,OAAO,CAAC,eAAe,CAAC;IAS1F;;OAEG;IACG,sBAAsB,CAAC,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,YAAY,CAAC;IASzF;;;;;;OAMG;IACG,kBAAkB,CAAC,MAAM,EAAE,wBAAwB,GAAG,OAAO,CAAC,MAAM,GAAG,YAAY,CAAC;IAiB1F;;OAEG;IACG,wBAAwB,CAC5B,MAAM,EAAE,8BAA8B,GACrC,OAAO,CAAC,iBAAiB,CAAC,kCAAkC,CAAC,CAAC;IASjE;;OAEG;IACG,qBAAqB,CAAC,MAAM,EAAE,2BAA2B,GAAG,OAAO,CAAC,WAAW,CAAC;IAsBtF;;;;OAIG;IACG,wBAAwB,CAAC,MAAM,EAAE,8BAA8B,GAAG,OAAO,CAAC,IAAI,CAAC;IAWrF;;OAEG;IACG,kBAAkB,CAAC,MAAM,EAAE,wBAAwB,GAAG,OAAO,CAAC,0BAA0B,CAAC;CAahG"}
@@ -0,0 +1,151 @@
1
+ import axios from 'axios';
2
+ /**
3
+ * Bitbucket Server API client.
4
+ * Provides typed methods for interacting with Bitbucket Server REST API.
5
+ */
6
+ export class BitbucketService {
7
+ client;
8
+ constructor(config) {
9
+ this.client = axios.create({
10
+ baseURL: `${config.baseUrl}/rest/api/latest`,
11
+ headers: {
12
+ Authorization: `Bearer ${config.token}`,
13
+ 'Content-Type': 'application/json',
14
+ },
15
+ });
16
+ }
17
+ /**
18
+ * Get a Bitbucket Server user profile by username
19
+ */
20
+ async getUserProfile(params) {
21
+ const response = await this.client.get(`/users/${params.username}`);
22
+ return response.data;
23
+ }
24
+ /**
25
+ * Get all users, optionally filtered by search term
26
+ */
27
+ async getAllUsers(params) {
28
+ const response = await this.client.get('/users', {
29
+ params: params?.filter ? { filter: params.filter } : {},
30
+ });
31
+ return response.data;
32
+ }
33
+ /**
34
+ * List projects, optionally filtered by name or permission
35
+ */
36
+ async listProjects(params) {
37
+ const response = await this.client.get('/projects', {
38
+ params,
39
+ });
40
+ return response.data;
41
+ }
42
+ /**
43
+ * List all repositories in a project
44
+ */
45
+ async listRepositories(params) {
46
+ const response = await this.client.get(`/projects/${params.projectKey}/repos`);
47
+ return response.data;
48
+ }
49
+ /**
50
+ * Get pull requests in the authenticated user's inbox (where they are assigned as reviewer)
51
+ */
52
+ async getInboxPullRequests(params) {
53
+ const response = await this.client.get('/inbox/pull-requests', { params });
54
+ return response.data;
55
+ }
56
+ /**
57
+ * Get pull request details (title, description, author, branches, etc.)
58
+ */
59
+ async getPullRequest(params) {
60
+ const { projectKey, repositorySlug, pullRequestId } = params;
61
+ const response = await this.client.get(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}`);
62
+ return response.data;
63
+ }
64
+ /**
65
+ * Get all changed files in a pull request
66
+ */
67
+ async getPullRequestChanges(params) {
68
+ const { projectKey, repositorySlug, pullRequestId, limit } = params;
69
+ const response = await this.client.get(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/changes`, { params: limit ? { limit } : {} });
70
+ return response.data;
71
+ }
72
+ /**
73
+ * Get structured line-by-line diff for a specific file in a pull request
74
+ */
75
+ async getPullRequestFileDiff(params) {
76
+ const { projectKey, repositorySlug, pullRequestId, path, contextLines } = params;
77
+ const response = await this.client.get(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/diff/${path}`, { params: contextLines ? { contextLines } : {} });
78
+ return response.data;
79
+ }
80
+ /**
81
+ * Get diff for a pull request (or specific file).
82
+ * When path is empty or undefined, returns the full PR diff.
83
+ * Format controls the response type:
84
+ * - 'text': Raw diff as plain text string
85
+ * - 'json': Structured diff object (DiffResponse)
86
+ */
87
+ async getPullRequestDiff(params) {
88
+ const { projectKey, repositorySlug, pullRequestId, path, contextLines, whitespace, format = 'text' } = params;
89
+ const queryParams = {};
90
+ if (contextLines !== undefined)
91
+ queryParams.contextLines = contextLines;
92
+ if (whitespace)
93
+ queryParams.whitespace = whitespace;
94
+ const response = await this.client.get(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/diff/${path || ''}`, {
95
+ params: queryParams,
96
+ headers: { Accept: format === 'text' ? 'text/plain' : 'application/json' },
97
+ });
98
+ return response.data;
99
+ }
100
+ /**
101
+ * Get activity on a pull request (comments, approvals, merges, reviews, updates)
102
+ */
103
+ async getPullRequestActivities(params) {
104
+ const { projectKey, repositorySlug, pullRequestId, ...queryParams } = params;
105
+ const response = await this.client.get(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/activities`, { params: queryParams });
106
+ return response.data;
107
+ }
108
+ /**
109
+ * Add a comment to a pull request (supports general comments, replies, and inline file/line comments)
110
+ */
111
+ async addPullRequestComment(params) {
112
+ const { projectKey, repositorySlug, pullRequestId, text, parentId, path, line, lineType, fileType } = params;
113
+ const body = { text };
114
+ if (parentId)
115
+ body.parent = { id: parentId };
116
+ if (path) {
117
+ body.anchor = {
118
+ path,
119
+ diffType: 'EFFECTIVE',
120
+ ...(line !== undefined && { line }),
121
+ ...(lineType && { lineType }),
122
+ ...(fileType && { fileType }),
123
+ };
124
+ }
125
+ const response = await this.client.post(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/comments`, body);
126
+ return response.data;
127
+ }
128
+ /**
129
+ * Delete a pull request comment. Returns void on success (HTTP 204).
130
+ * Anyone can delete their own comment. Only REPO_ADMIN can delete others' comments.
131
+ * Comments with replies cannot be deleted.
132
+ */
133
+ async deletePullRequestComment(params) {
134
+ const { projectKey, repositorySlug, pullRequestId, commentId, version } = params;
135
+ await this.client.delete(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/comments/${commentId}`, {
136
+ params: { version },
137
+ });
138
+ }
139
+ /**
140
+ * Update review status for a pull request (approve, request changes, or remove approval)
141
+ */
142
+ async updateReviewStatus(params) {
143
+ const { projectKey, repositorySlug, pullRequestId, status } = params;
144
+ // Get authenticated user slug from application properties
145
+ const propertiesResponse = await this.client.get('/application-properties');
146
+ const userSlug = propertiesResponse.headers['x-ausername'];
147
+ const response = await this.client.put(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/participants/${userSlug}`, { status });
148
+ return response.data;
149
+ }
150
+ }
151
+ //# sourceMappingURL=bitbucket.client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitbucket.client.js","sourceRoot":"","sources":["../../src/client/bitbucket.client.ts"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAC;AA6BlD;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IACnB,MAAM,CAAgB;IAE9B,YAAY,MAA0C;QACpD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;YACzB,OAAO,EAAE,GAAG,MAAM,CAAC,OAAO,kBAAkB;YAC5C,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,MAAM,CAAC,KAAK,EAAE;gBACvC,cAAc,EAAE,kBAAkB;aACnC;SACF,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,cAAc,CAAC,MAA4B;QAC/C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAW,UAAU,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC9E,OA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