Skip to content

Commit 3cb803c

Browse files
authored
Add commentType to createComment and createThread methods (#1370)
This pull request updates the way comments are created in pull request threads by explicitly setting the `commentType` field to `1` when creating comments and threads. This ensures that comments are consistently recognized as standard comments by the API. Related tests have also been updated to verify the new behavior. **API integration updates:** * Added `commentType: 1` to the payload when creating comments with `gitApi.createComment` in `src/tools/repositories.ts`, ensuring the comment type is explicitly set. * Added `commentType: 1` to each comment in the payload when creating threads with `gitApi.createThread` in `src/tools/repositories.ts`. **Test updates:** * Updated all relevant tests in `test/src/tools/repositories.test.ts` to expect `commentType: 1` in the payloads for both `createComment` and `createThread` calls, ensuring tests accurately reflect the new API usage. [[1]](diffhunk://#diff-ab08119c40bb674907f4cd70e8c549daaf3bcd559398b0f2eddb463bf8eb160aL5434-R5434) [[2]](diffhunk://#diff-ab08119c40bb674907f4cd70e8c549daaf3bcd559398b0f2eddb463bf8eb160aL5505-R5505) [[3]](diffhunk://#diff-ab08119c40bb674907f4cd70e8c549daaf3bcd559398b0f2eddb463bf8eb160aL5542-R5542) [[4]](diffhunk://#diff-ab08119c40bb674907f4cd70e8c549daaf3bcd559398b0f2eddb463bf8eb160aL5579-R5579) [[5]](diffhunk://#diff-ab08119c40bb674907f4cd70e8c549daaf3bcd559398b0f2eddb463bf8eb160aL5614-R5614) [[6]](diffhunk://#diff-ab08119c40bb674907f4cd70e8c549daaf3bcd559398b0f2eddb463bf8eb160aL7048-R7048) [[7]](diffhunk://#diff-ab08119c40bb674907f4cd70e8c549daaf3bcd559398b0f2eddb463bf8eb160aL7089-R7089) ## GitHub issue number #1368 ## **Associated Risks** N/A ## ✅ **PR Checklist** - [x] **I have read the [contribution guidelines](https://github.com/microsoft/azure-devops-mcp/blob/main/CONTRIBUTING.md)** - [x] **I have read the [code of conduct guidelines](https://github.com/microsoft/azure-devops-mcp/blob/main/CODE_OF_CONDUCT.md)** - [x] Title of the pull request is clear and informative. - [x] 👌 Code hygiene - [x] 🔭 Telemetry added, updated, or N/A - [x] 📄 Documentation added, updated, or N/A - [x] 🛡️ Automated tests added, or N/A ## 🧪 **How did you test it?** updated automated tests, all are passing
1 parent 1892b9d commit 3cb803c

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/tools/repositories.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ function configureRepoTools(server: McpServer, tokenProvider: () => Promise<stri
14951495
try {
14961496
const connection = await connectionProvider();
14971497
const gitApi = await connection.getGitApi();
1498-
const comment = await gitApi.createComment({ content }, repositoryId, pullRequestId, threadId, project);
1498+
const comment = await gitApi.createComment({ content, commentType: 1 }, repositoryId, pullRequestId, threadId, project);
14991499

15001500
// Check if the comment was successfully created
15011501
if (!comment) {
@@ -1657,7 +1657,7 @@ function configureRepoTools(server: McpServer, tokenProvider: () => Promise<stri
16571657
}
16581658

16591659
const thread = await gitApi.createThread(
1660-
{ comments: [{ content: content }], threadContext: threadContext, status: CommentThreadStatus[status as keyof typeof CommentThreadStatus] },
1660+
{ comments: [{ content: content, commentType: 1 }], threadContext: threadContext, status: CommentThreadStatus[status as keyof typeof CommentThreadStatus] },
16611661
repositoryId,
16621662
pullRequestId,
16631663
project

test/src/tools/repositories.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5431,7 +5431,7 @@ describe("repos tools", () => {
54315431

54325432
const result = await handler(params);
54335433

5434-
expect(mockGitApi.createComment).toHaveBeenCalledWith({ content: "Reply content" }, "repo123", 456, 789, undefined);
5434+
expect(mockGitApi.createComment).toHaveBeenCalledWith({ content: "Reply content", commentType: 1 }, "repo123", 456, 789, undefined);
54355435
expect(result.content[0].text).toBe("Comment successfully added to thread 789.");
54365436
});
54375437

@@ -5502,7 +5502,7 @@ describe("repos tools", () => {
55025502

55035503
expect(mockGitApi.createThread).toHaveBeenCalledWith(
55045504
{
5505-
comments: [{ content: "New thread content" }],
5505+
comments: [{ content: "New thread content", commentType: 1 }],
55065506
threadContext: { filePath: undefined },
55075507
status: undefined, // Default status would be handled by CommentThreadStatus enum lookup
55085508
},
@@ -5539,7 +5539,7 @@ describe("repos tools", () => {
55395539

55405540
expect(mockGitApi.createThread).toHaveBeenCalledWith(
55415541
{
5542-
comments: [{ content: "Thread with position" }],
5542+
comments: [{ content: "Thread with position", commentType: 1 }],
55435543
threadContext: {
55445544
filePath: "/src/test.ts",
55455545
rightFileStart: { line: 10, offset: 5 },
@@ -5576,7 +5576,7 @@ describe("repos tools", () => {
55765576

55775577
expect(mockGitApi.createThread).toHaveBeenCalledWith(
55785578
{
5579-
comments: [{ content: "Thread with normalized path" }],
5579+
comments: [{ content: "Thread with normalized path", commentType: 1 }],
55805580
threadContext: {
55815581
filePath: "/src/file-without-slash.ts", // Should have leading slash added
55825582
},
@@ -5611,7 +5611,7 @@ describe("repos tools", () => {
56115611

56125612
expect(mockGitApi.createThread).toHaveBeenCalledWith(
56135613
{
5614-
comments: [{ content: "Thread with existing slash" }],
5614+
comments: [{ content: "Thread with existing slash", commentType: 1 }],
56155615
threadContext: {
56165616
filePath: "/src/file-with-slash.ts", // Should remain unchanged
56175617
},
@@ -7045,7 +7045,7 @@ describe("repos tools", () => {
70457045

70467046
expect(mockGitApi.createThread).toHaveBeenCalledWith(
70477047
{
7048-
comments: [{ content: "Test comment" }],
7048+
comments: [{ content: "Test comment", commentType: 1 }],
70497049
threadContext: {
70507050
filePath: "/test/file.js",
70517051
rightFileStart: { line: 5, offset: 10 },
@@ -7086,7 +7086,7 @@ describe("repos tools", () => {
70867086

70877087
expect(mockGitApi.createThread).toHaveBeenCalledWith(
70887088
{
7089-
comments: [{ content: "Test comment" }],
7089+
comments: [{ content: "Test comment", commentType: 1 }],
70907090
threadContext: {
70917091
filePath: "/test/file.js",
70927092
rightFileStart: { line: 5 },

0 commit comments

Comments
 (0)