@atlassian-dc-mcp/bitbucket 0.13.0 → 0.14.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.
- package/CHANGELOG.md +11 -0
- package/build/__tests__/bitbucket-token-optimization.test.js +95 -1
- package/build/__tests__/bitbucket-token-optimization.test.js.map +1 -1
- package/build/__tests__/pr-comment-mapper.test.js +152 -1
- package/build/__tests__/pr-comment-mapper.test.js.map +1 -1
- package/build/bitbucket-response-mapper.d.ts +2 -2
- package/build/bitbucket-response-mapper.d.ts.map +1 -1
- package/build/bitbucket-response-mapper.js +9 -8
- package/build/bitbucket-response-mapper.js.map +1 -1
- package/build/bitbucket-service.d.ts +2 -1
- package/build/bitbucket-service.d.ts.map +1 -1
- package/build/bitbucket-service.js +4 -3
- package/build/bitbucket-service.js.map +1 -1
- package/build/index.js +2 -2
- package/build/index.js.map +1 -1
- package/build/pr-comment-mapper.d.ts +6 -2
- package/build/pr-comment-mapper.d.ts.map +1 -1
- package/build/pr-comment-mapper.js +47 -7
- package/build/pr-comment-mapper.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/bitbucket-token-optimization.test.ts +99 -1
- package/src/__tests__/pr-comment-mapper.test.ts +160 -0
- package/src/bitbucket-response-mapper.ts +16 -7
- package/src/bitbucket-service.ts +5 -3
- package/src/index.ts +10 -2
- package/src/pr-comment-mapper.ts +66 -7
- package/tsconfig.tsbuildinfo +1 -1
package/src/bitbucket-service.ts
CHANGED
|
@@ -205,7 +205,8 @@ export class BitbucketService {
|
|
|
205
205
|
pullRequestId: string,
|
|
206
206
|
start?: number,
|
|
207
207
|
limit?: number,
|
|
208
|
-
output: BitbucketOutputMode = 'compact'
|
|
208
|
+
output: BitbucketOutputMode = 'compact',
|
|
209
|
+
includeResolved = false
|
|
209
210
|
) {
|
|
210
211
|
const result = await handleApiOperation(
|
|
211
212
|
() => PullRequestsService.getActivities(
|
|
@@ -223,7 +224,7 @@ export class BitbucketService {
|
|
|
223
224
|
if (result.success && result.data) {
|
|
224
225
|
return {
|
|
225
226
|
success: true,
|
|
226
|
-
data: shapePullRequestCommentsResponse(result.data, output)
|
|
227
|
+
data: shapePullRequestCommentsResponse(result.data, output, { includeResolved })
|
|
227
228
|
};
|
|
228
229
|
}
|
|
229
230
|
|
|
@@ -761,7 +762,8 @@ export const bitbucketToolSchemas = {
|
|
|
761
762
|
pullRequestId: z.string().describe("The pull request ID"),
|
|
762
763
|
start: z.number().optional().describe("Start number for pagination"),
|
|
763
764
|
limit: z.number().optional().describe("Number of items to return. If not passed, the package default page size is used."),
|
|
764
|
-
output: z.enum(['summary', 'compact', 'full']).optional().describe("Choose between summary lines, compact structured output, or the full API payload. Defaults to compact.")
|
|
765
|
+
output: z.enum(['summary', 'compact', 'full']).optional().describe("Choose between summary lines, compact structured output, or the full API payload. Defaults to compact."),
|
|
766
|
+
includeResolved: z.boolean().optional().describe("Include resolved comment threads and their replies. Defaults to false, so resolved threads are omitted.")
|
|
765
767
|
},
|
|
766
768
|
getPullRequestChanges: {
|
|
767
769
|
projectKey: z.string().describe("The project key"),
|
package/src/index.ts
CHANGED
|
@@ -97,8 +97,16 @@ server.tool(
|
|
|
97
97
|
"bitbucket_getPR_CommentsAndAction",
|
|
98
98
|
"Get comments for a Bitbucket pull request and other actions, like approvals",
|
|
99
99
|
bitbucketToolSchemas.getPullRequestComments,
|
|
100
|
-
async ({ projectKey, repositorySlug, pullRequestId, start, limit, output }) => {
|
|
101
|
-
const result = await bitbucketService.getPullRequestCommentsAndActions(
|
|
100
|
+
async ({ projectKey, repositorySlug, pullRequestId, start, limit, output, includeResolved }) => {
|
|
101
|
+
const result = await bitbucketService.getPullRequestCommentsAndActions(
|
|
102
|
+
projectKey,
|
|
103
|
+
repositorySlug,
|
|
104
|
+
pullRequestId,
|
|
105
|
+
start,
|
|
106
|
+
limit,
|
|
107
|
+
output,
|
|
108
|
+
includeResolved
|
|
109
|
+
);
|
|
102
110
|
return formatToolResponse(result);
|
|
103
111
|
}
|
|
104
112
|
);
|
package/src/pr-comment-mapper.ts
CHANGED
|
@@ -164,6 +164,10 @@ export interface SimplifiedPRResponse {
|
|
|
164
164
|
};
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
+
export interface PullRequestCommentOptions {
|
|
168
|
+
includeResolved?: boolean;
|
|
169
|
+
}
|
|
170
|
+
|
|
167
171
|
// Type guard functions to validate object structure
|
|
168
172
|
function isBitbucketUser(obj: unknown): obj is BitbucketUser {
|
|
169
173
|
return (
|
|
@@ -259,6 +263,56 @@ function simplifyComment(comment: Comment, ancestorIds: Set<number> = new Set())
|
|
|
259
263
|
};
|
|
260
264
|
}
|
|
261
265
|
|
|
266
|
+
function filterComment(comment: Comment, includeResolved: boolean, ancestorIds: Set<number> = new Set()): Comment | null {
|
|
267
|
+
if (!includeResolved && comment.threadResolved) {
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const nextAncestorIds = new Set(ancestorIds);
|
|
272
|
+
nextAncestorIds.add(comment.id);
|
|
273
|
+
|
|
274
|
+
const comments = comment.comments
|
|
275
|
+
.filter(isComment)
|
|
276
|
+
.filter(childComment => !nextAncestorIds.has(childComment.id))
|
|
277
|
+
.map(childComment => filterComment(childComment, includeResolved, nextAncestorIds))
|
|
278
|
+
.filter((childComment): childComment is Comment => childComment !== null);
|
|
279
|
+
|
|
280
|
+
return {
|
|
281
|
+
...comment,
|
|
282
|
+
comments,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function filterPullRequestComments(
|
|
287
|
+
response: BitbucketPRApiResponse,
|
|
288
|
+
options: PullRequestCommentOptions = {}
|
|
289
|
+
): BitbucketPRApiResponse {
|
|
290
|
+
const includeResolved = options.includeResolved ?? false;
|
|
291
|
+
|
|
292
|
+
if (includeResolved) {
|
|
293
|
+
return response;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return {
|
|
297
|
+
...response,
|
|
298
|
+
values: (response.values || []).flatMap(activity => {
|
|
299
|
+
if (!isPRActivity(activity) || activity.action !== 'COMMENTED' || !activity.comment || !isComment(activity.comment)) {
|
|
300
|
+
return [activity];
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const filteredComment = filterComment(activity.comment, includeResolved);
|
|
304
|
+
if (!filteredComment) {
|
|
305
|
+
return [];
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return [{
|
|
309
|
+
...activity,
|
|
310
|
+
comment: filteredComment,
|
|
311
|
+
}];
|
|
312
|
+
})
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
|
|
262
316
|
function simplifyActivity(activity: PRActivity): SimplifiedActivity {
|
|
263
317
|
return {
|
|
264
318
|
id: activity.id,
|
|
@@ -272,11 +326,15 @@ function simplifyActivity(activity: PRActivity): SimplifiedActivity {
|
|
|
272
326
|
};
|
|
273
327
|
}
|
|
274
328
|
|
|
275
|
-
export function simplifyBitbucketPRComments(
|
|
329
|
+
export function simplifyBitbucketPRComments(
|
|
330
|
+
response: BitbucketPRApiResponse,
|
|
331
|
+
options: PullRequestCommentOptions = {}
|
|
332
|
+
): SimplifiedPRResponse | BitbucketPRApiResponse {
|
|
333
|
+
const filteredResponse = filterPullRequestComments(response, options);
|
|
276
334
|
const activities: SimplifiedActivity[] = [];
|
|
277
335
|
|
|
278
336
|
// Process each activity with type guard validation
|
|
279
|
-
for (const activity of
|
|
337
|
+
for (const activity of filteredResponse.values || []) {
|
|
280
338
|
if (isPRActivity(activity)) {
|
|
281
339
|
activities.push(simplifyActivity(activity));
|
|
282
340
|
}
|
|
@@ -284,8 +342,8 @@ export function simplifyBitbucketPRComments(response: BitbucketPRApiResponse): S
|
|
|
284
342
|
}
|
|
285
343
|
|
|
286
344
|
// If no valid activities were found, return the original response
|
|
287
|
-
if (activities.length === 0 && (
|
|
288
|
-
return
|
|
345
|
+
if (activities.length === 0 && (filteredResponse.values || []).length > 0) {
|
|
346
|
+
return filteredResponse;
|
|
289
347
|
}
|
|
290
348
|
|
|
291
349
|
// Find PR author (usually the one who OPENED the PR)
|
|
@@ -296,7 +354,7 @@ export function simplifyBitbucketPRComments(response: BitbucketPRApiResponse): S
|
|
|
296
354
|
const unresolvedCount = comments.filter(a => a.comment && !a.comment.threadResolved).length;
|
|
297
355
|
|
|
298
356
|
return {
|
|
299
|
-
isLastPage:
|
|
357
|
+
isLastPage: filteredResponse.isLastPage ?? true,
|
|
300
358
|
activities,
|
|
301
359
|
summary: {
|
|
302
360
|
totalActivities: activities.length,
|
|
@@ -307,10 +365,11 @@ export function simplifyBitbucketPRComments(response: BitbucketPRApiResponse): S
|
|
|
307
365
|
};
|
|
308
366
|
}
|
|
309
367
|
|
|
310
|
-
export function getCommentSummary(response: BitbucketPRApiResponse): string[] {
|
|
368
|
+
export function getCommentSummary(response: BitbucketPRApiResponse, options: PullRequestCommentOptions = {}): string[] {
|
|
369
|
+
const filteredResponse = filterPullRequestComments(response, options);
|
|
311
370
|
const commentSummaries: string[] = [];
|
|
312
371
|
|
|
313
|
-
for (const activity of
|
|
372
|
+
for (const activity of filteredResponse.values || []) {
|
|
314
373
|
// Use type guard to validate activity structure
|
|
315
374
|
if (isPRActivity(activity) && activity.action === 'COMMENTED' && activity.comment) {
|
|
316
375
|
// Additional validation for comment structure
|