@atlassian-dc-mcp/bitbucket 0.12.2 → 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.
Files changed (44) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +45 -2
  3. package/build/__tests__/bitbucket-service.test.js +106 -17
  4. package/build/__tests__/bitbucket-service.test.js.map +1 -1
  5. package/build/__tests__/bitbucket-token-optimization.test.d.ts +2 -0
  6. package/build/__tests__/bitbucket-token-optimization.test.d.ts.map +1 -0
  7. package/build/__tests__/bitbucket-token-optimization.test.js +375 -0
  8. package/build/__tests__/bitbucket-token-optimization.test.js.map +1 -0
  9. package/build/__tests__/config.test.d.ts +2 -0
  10. package/build/__tests__/config.test.d.ts.map +1 -0
  11. package/build/__tests__/config.test.js +49 -0
  12. package/build/__tests__/config.test.js.map +1 -0
  13. package/build/__tests__/pr-comment-mapper.test.js +152 -1
  14. package/build/__tests__/pr-comment-mapper.test.js.map +1 -1
  15. package/build/bitbucket-response-mapper.d.ts +8 -0
  16. package/build/bitbucket-response-mapper.d.ts.map +1 -0
  17. package/build/bitbucket-response-mapper.js +96 -0
  18. package/build/bitbucket-response-mapper.js.map +1 -0
  19. package/build/bitbucket-service.d.ts +25 -22
  20. package/build/bitbucket-service.d.ts.map +1 -1
  21. package/build/bitbucket-service.js +89 -54
  22. package/build/bitbucket-service.js.map +1 -1
  23. package/build/config.d.ts +4 -0
  24. package/build/config.d.ts.map +1 -0
  25. package/build/config.js +11 -0
  26. package/build/config.js.map +1 -0
  27. package/build/index.js +15 -15
  28. package/build/index.js.map +1 -1
  29. package/build/pr-comment-mapper.d.ts +6 -2
  30. package/build/pr-comment-mapper.d.ts.map +1 -1
  31. package/build/pr-comment-mapper.js +47 -7
  32. package/build/pr-comment-mapper.js.map +1 -1
  33. package/package.json +3 -3
  34. package/server.json +11 -4
  35. package/src/__tests__/bitbucket-service.test.ts +109 -17
  36. package/src/__tests__/bitbucket-token-optimization.test.ts +412 -0
  37. package/src/__tests__/config.test.ts +64 -0
  38. package/src/__tests__/pr-comment-mapper.test.ts +160 -0
  39. package/src/bitbucket-response-mapper.ts +121 -0
  40. package/src/bitbucket-service.ts +119 -57
  41. package/src/config.ts +13 -0
  42. package/src/index.ts +26 -17
  43. package/src/pr-comment-mapper.ts +66 -7
  44. package/tsconfig.tsbuildinfo +1 -1
@@ -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(response: BitbucketPRApiResponse): SimplifiedPRResponse | BitbucketPRApiResponse {
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 response.values || []) {
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 && (response.values || []).length > 0) {
288
- return response;
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: response.isLastPage ?? true,
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 response.values || []) {
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