cli / mcp for bitbucket
1import {
2 getCommentAuthor,
3 getCommentContent,
4 getCommentDate,
5 getCommentInlineInfo,
6 getPullRequestComments,
7} from '@bitbucket-tool/core';
8import { defineCommand, unwrapOrExit } from '../utils/command-builder';
9
10export const registerPrCommentsCommand = defineCommand({
11 name: 'pr:comments',
12 description: 'Get all comments on a pull request',
13 arguments: [{ syntax: '<pr-id>', description: 'Pull request ID', parser: parseInt }],
14 action: async ({ workspace, repoSlug, args }) => {
15 const [prId] = args;
16
17 const comments = unwrapOrExit(await getPullRequestComments({ workspace, repoSlug, prId }));
18
19 if (comments.length === 0) {
20 console.log(`\nNo comments on PR #${prId}\n`);
21 return;
22 }
23
24 console.log(`\nComments on PR #${prId} (${comments.length} total):\n`);
25
26 comments.forEach((comment, index) => {
27 const author = getCommentAuthor(comment);
28 const date = getCommentDate(comment);
29 const content = getCommentContent(comment);
30 const inline = getCommentInlineInfo(comment);
31
32 console.log(`${index + 1}. ${author} (${date})${inline}`);
33 console.log(` ${content}\n`);
34 });
35 },
36});