diff --git a/README.md b/README.md index 07169c4c16..64b16ce8e1 100644 --- a/README.md +++ b/README.md @@ -1073,14 +1073,6 @@ The following sets of tools are available: - `startSide`: For multi-line comments, the starting side of the diff that the comment applies to. LEFT indicates the previous state, RIGHT indicates the new state (string, optional) - `subjectType`: The level at which the comment is targeted (string, required) -- **add_reply_to_pull_request_comment** - Add reply to pull request comment - - **Required OAuth Scopes**: `repo` - - `body`: The text of the reply (string, required) - - `commentId`: The ID of the comment to reply to (number, required) - - `owner`: Repository owner (string, required) - - `pullNumber`: Pull request number (number, required) - - `repo`: Repository name (string, required) - - **create_pull_request** - Open new pull request - **Required OAuth Scopes**: `repo` - `base`: Branch to merge into (string, required) @@ -1113,6 +1105,20 @@ The following sets of tools are available: - `pullNumber`: Pull request number (number, required) - `repo`: Repository name (string, required) +- **pull_request_comment_write** - Write operations (reply, update, delete) on pull request review comments + - **Required OAuth Scopes**: `repo` + - `body`: Comment text (required for 'reply' and 'update' methods) (string, optional) + - `commentId`: The ID of the review comment to operate on. For 'reply', this is the comment to reply to. (number, required) + - `method`: Write operation to perform on a pull request review comment. + Options are: + - 'reply' - add a reply to an existing review comment. This creates a new comment that is linked as a reply to the specified comment. Requires "pullNumber" and "body". + - 'update' - replace the body of an existing review comment. Requires "body". Only comments authored by the authenticated user can be updated. + - 'delete' - delete an existing review comment. Only comments authored by the authenticated user can be deleted. + (string, required) + - `owner`: Repository owner (string, required) + - `pullNumber`: Pull request number (required for 'reply' method) (number, optional) + - `repo`: Repository name (string, required) + - **pull_request_read** - Get details for a single pull request - **Required OAuth Scopes**: `repo` - `after`: Cursor for pagination, used only by the get_review_comments method. Pass the endCursor from the previous page's PageInfo to fetch the next page. (string, optional) diff --git a/docs/tool-renaming.md b/docs/tool-renaming.md index 050ac9b77a..907c3b7d42 100644 --- a/docs/tool-renaming.md +++ b/docs/tool-renaming.md @@ -47,6 +47,7 @@ Will get `issue_read` and `get_file_contents` tools registered, with no errors. | Old Name | New Name | |----------|----------| | `add_project_item` | `projects_write` | +| `add_reply_to_pull_request_comment` | `pull_request_comment_write` | | `cancel_workflow_run` | `actions_run_trigger` | | `delete_project_item` | `projects_write` | | `delete_workflow_run_logs` | `actions_run_trigger` | diff --git a/pkg/github/__toolsnaps__/add_reply_to_pull_request_comment.snap b/pkg/github/__toolsnaps__/add_reply_to_pull_request_comment.snap deleted file mode 100644 index e2187478e8..0000000000 --- a/pkg/github/__toolsnaps__/add_reply_to_pull_request_comment.snap +++ /dev/null @@ -1,39 +0,0 @@ -{ - "annotations": { - "title": "Add reply to pull request comment" - }, - "description": "Add a reply to an existing pull request comment. This creates a new comment that is linked as a reply to the specified comment.", - "inputSchema": { - "properties": { - "body": { - "description": "The text of the reply", - "type": "string" - }, - "commentId": { - "description": "The ID of the comment to reply to", - "type": "number" - }, - "owner": { - "description": "Repository owner", - "type": "string" - }, - "pullNumber": { - "description": "Pull request number", - "type": "number" - }, - "repo": { - "description": "Repository name", - "type": "string" - } - }, - "required": [ - "owner", - "repo", - "pullNumber", - "commentId", - "body" - ], - "type": "object" - }, - "name": "add_reply_to_pull_request_comment" -} \ No newline at end of file diff --git a/pkg/github/__toolsnaps__/pull_request_comment_write.snap b/pkg/github/__toolsnaps__/pull_request_comment_write.snap new file mode 100644 index 0000000000..a13a0aa23e --- /dev/null +++ b/pkg/github/__toolsnaps__/pull_request_comment_write.snap @@ -0,0 +1,48 @@ +{ + "annotations": { + "destructiveHint": true, + "title": "Write operations (reply, update, delete) on pull request review comments" + }, + "description": "Write operations for pull request review comments.\n\nAvailable methods:\n- reply: Add a reply to an existing review comment. This creates a new comment that is linked as a reply to the specified comment.\n- update: Replace the body of an existing review comment. Only comments authored by the authenticated user can be updated.\n- delete: Delete an existing review comment. Only comments authored by the authenticated user can be deleted.\n", + "inputSchema": { + "properties": { + "body": { + "description": "Comment text (required for 'reply' and 'update' methods)", + "type": "string" + }, + "commentId": { + "description": "The ID of the review comment to operate on. For 'reply', this is the comment to reply to.", + "type": "number" + }, + "method": { + "description": "Write operation to perform on a pull request review comment.\nOptions are:\n- 'reply' - add a reply to an existing review comment. This creates a new comment that is linked as a reply to the specified comment. Requires \"pullNumber\" and \"body\".\n- 'update' - replace the body of an existing review comment. Requires \"body\". Only comments authored by the authenticated user can be updated.\n- 'delete' - delete an existing review comment. Only comments authored by the authenticated user can be deleted.\n", + "enum": [ + "reply", + "update", + "delete" + ], + "type": "string" + }, + "owner": { + "description": "Repository owner", + "type": "string" + }, + "pullNumber": { + "description": "Pull request number (required for 'reply' method)", + "type": "number" + }, + "repo": { + "description": "Repository name", + "type": "string" + } + }, + "required": [ + "method", + "owner", + "repo", + "commentId" + ], + "type": "object" + }, + "name": "pull_request_comment_write" +} \ No newline at end of file diff --git a/pkg/github/deprecated_tool_aliases.go b/pkg/github/deprecated_tool_aliases.go index 4415731fbe..db3acdd4c8 100644 --- a/pkg/github/deprecated_tool_aliases.go +++ b/pkg/github/deprecated_tool_aliases.go @@ -39,4 +39,7 @@ var DeprecatedToolAliases = map[string]string{ "add_project_item": "projects_write", "update_project_item": "projects_write", "delete_project_item": "projects_write", + + // Pull request comment tools consolidated + "add_reply_to_pull_request_comment": "pull_request_comment_write", } diff --git a/pkg/github/helper_test.go b/pkg/github/helper_test.go index 7f86c8b989..431005e736 100644 --- a/pkg/github/helper_test.go +++ b/pkg/github/helper_test.go @@ -78,6 +78,8 @@ const ( PutReposPullsUpdateBranchByOwnerByRepoByPullNumber = "PUT /repos/{owner}/{repo}/pulls/{pull_number}/update-branch" PostReposPullsRequestedReviewersByOwnerByRepoByPullNumber = "POST /repos/{owner}/{repo}/pulls/{pull_number}/requested_reviewers" PostReposPullsCommentsByOwnerByRepoByPullNumber = "POST /repos/{owner}/{repo}/pulls/{pull_number}/comments" + PatchReposPullsCommentsByOwnerByRepoByCommentID = "PATCH /repos/{owner}/{repo}/pulls/comments/{comment_id}" + DeleteReposPullsCommentsByOwnerByRepoByCommentID = "DELETE /repos/{owner}/{repo}/pulls/comments/{comment_id}" // Notifications endpoints GetNotifications = "GET /notifications" diff --git a/pkg/github/pullrequests.go b/pkg/github/pullrequests.go index ae7d04331d..f9846257be 100644 --- a/pkg/github/pullrequests.go +++ b/pkg/github/pullrequests.go @@ -1082,11 +1082,22 @@ func UpdatePullRequest(t translations.TranslationHelperFunc) inventory.ServerToo return st } -// AddReplyToPullRequestComment creates a tool to add a reply to an existing pull request comment. -func AddReplyToPullRequestComment(t translations.TranslationHelperFunc) inventory.ServerTool { +// PullRequestCommentWrite creates a consolidated tool for write operations on +// pull request review comments: replying to, updating, and deleting them. +func PullRequestCommentWrite(t translations.TranslationHelperFunc) inventory.ServerTool { schema := &jsonschema.Schema{ Type: "object", Properties: map[string]*jsonschema.Schema{ + "method": { + Type: "string", + Description: `Write operation to perform on a pull request review comment. +Options are: +- 'reply' - add a reply to an existing review comment. This creates a new comment that is linked as a reply to the specified comment. Requires "pullNumber" and "body". +- 'update' - replace the body of an existing review comment. Requires "body". Only comments authored by the authenticated user can be updated. +- 'delete' - delete an existing review comment. Only comments authored by the authenticated user can be deleted. +`, + Enum: []any{"reply", "update", "delete"}, + }, "owner": { Type: "string", Description: "Repository owner", @@ -1097,42 +1108,49 @@ func AddReplyToPullRequestComment(t translations.TranslationHelperFunc) inventor }, "pullNumber": { Type: "number", - Description: "Pull request number", + Description: "Pull request number (required for 'reply' method)", }, "commentId": { Type: "number", - Description: "The ID of the comment to reply to", + Description: "The ID of the review comment to operate on. For 'reply', this is the comment to reply to.", }, "body": { Type: "string", - Description: "The text of the reply", + Description: "Comment text (required for 'reply' and 'update' methods)", }, }, - Required: []string{"owner", "repo", "pullNumber", "commentId", "body"}, + Required: []string{"method", "owner", "repo", "commentId"}, } return NewTool( ToolsetMetadataPullRequests, mcp.Tool{ - Name: "add_reply_to_pull_request_comment", - Description: t("TOOL_ADD_REPLY_TO_PULL_REQUEST_COMMENT_DESCRIPTION", "Add a reply to an existing pull request comment. This creates a new comment that is linked as a reply to the specified comment."), + Name: "pull_request_comment_write", + Description: t("TOOL_PULL_REQUEST_COMMENT_WRITE_DESCRIPTION", `Write operations for pull request review comments. + +Available methods: +- reply: Add a reply to an existing review comment. This creates a new comment that is linked as a reply to the specified comment. +- update: Replace the body of an existing review comment. Only comments authored by the authenticated user can be updated. +- delete: Delete an existing review comment. Only comments authored by the authenticated user can be deleted. +`), Annotations: &mcp.ToolAnnotations{ - Title: t("TOOL_ADD_REPLY_TO_PULL_REQUEST_COMMENT_USER_TITLE", "Add reply to pull request comment"), - ReadOnlyHint: false, + Title: t("TOOL_PULL_REQUEST_COMMENT_WRITE_USER_TITLE", "Write operations (reply, update, delete) on pull request review comments"), + ReadOnlyHint: false, + DestructiveHint: jsonschema.Ptr(true), }, InputSchema: schema, }, []scopes.Scope{scopes.Repo}, func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) { - owner, err := RequiredParam[string](args, "owner") + method, err := RequiredParam[string](args, "method") if err != nil { return utils.NewToolResultError(err.Error()), nil, nil } - repo, err := RequiredParam[string](args, "repo") + owner, err := RequiredParam[string](args, "owner") if err != nil { return utils.NewToolResultError(err.Error()), nil, nil } - pullNumber, err := RequiredInt(args, "pullNumber") + repo, err := RequiredParam[string](args, "repo") if err != nil { return utils.NewToolResultError(err.Error()), nil, nil } @@ -1140,37 +1158,106 @@ func AddReplyToPullRequestComment(t translations.TranslationHelperFunc) inventor if err != nil { return utils.NewToolResultError(err.Error()), nil, nil } - body, err := RequiredParam[string](args, "body") - if err != nil { - return utils.NewToolResultError(err.Error()), nil, nil - } client, err := deps.GetClient(ctx) if err != nil { return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, nil } - comment, resp, err := client.PullRequests.CreateCommentInReplyTo(ctx, owner, repo, pullNumber, body, int64(commentID)) - if err != nil { - return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to add reply to pull request comment", resp, err), nil, nil + switch method { + case "reply": + return replyToPullRequestComment(ctx, client, args, owner, repo, int64(commentID)) + case "update": + return updatePullRequestComment(ctx, client, args, owner, repo, int64(commentID)) + case "delete": + return deletePullRequestComment(ctx, client, owner, repo, int64(commentID)) + default: + return utils.NewToolResultError("invalid method, must be one of: 'reply', 'update', 'delete'"), nil, nil } - defer func() { _ = resp.Body.Close() }() + }) +} - if resp.StatusCode != http.StatusCreated { - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return utils.NewToolResultErrorFromErr("failed to read response body", err), nil, nil - } - return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to add reply to pull request comment", resp, bodyBytes), nil, nil - } +func replyToPullRequestComment(ctx context.Context, client *github.Client, args map[string]any, owner, repo string, commentID int64) (*mcp.CallToolResult, any, error) { + pullNumber, err := RequiredInt(args, "pullNumber") + if err != nil { + return utils.NewToolResultError(err.Error()), nil, nil + } + body, err := RequiredParam[string](args, "body") + if err != nil { + return utils.NewToolResultError(err.Error()), nil, nil + } - r, err := json.Marshal(comment) - if err != nil { - return utils.NewToolResultErrorFromErr("failed to marshal response", err), nil, nil - } + comment, resp, err := client.PullRequests.CreateCommentInReplyTo(ctx, owner, repo, pullNumber, body, commentID) + if err != nil { + return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to add reply to pull request comment", resp, err), nil, nil + } + defer func() { _ = resp.Body.Close() }() - return utils.NewToolResultText(string(r)), nil, nil - }) + if resp.StatusCode != http.StatusCreated { + bodyBytes, err := io.ReadAll(resp.Body) + if err != nil { + return utils.NewToolResultErrorFromErr("failed to read response body", err), nil, nil + } + return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to add reply to pull request comment", resp, bodyBytes), nil, nil + } + + r, err := json.Marshal(comment) + if err != nil { + return utils.NewToolResultErrorFromErr("failed to marshal response", err), nil, nil + } + + return utils.NewToolResultText(string(r)), nil, nil +} + +func updatePullRequestComment(ctx context.Context, client *github.Client, args map[string]any, owner, repo string, commentID int64) (*mcp.CallToolResult, any, error) { + body, err := RequiredParam[string](args, "body") + if err != nil { + return utils.NewToolResultError(err.Error()), nil, nil + } + + comment, resp, err := client.PullRequests.EditComment(ctx, owner, repo, commentID, &github.PullRequestComment{ + Body: github.Ptr(body), + }) + if err != nil { + return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to update pull request comment", resp, err), nil, nil + } + defer func() { _ = resp.Body.Close() }() + + if resp.StatusCode != http.StatusOK { + bodyBytes, err := io.ReadAll(resp.Body) + if err != nil { + return utils.NewToolResultErrorFromErr("failed to read response body", err), nil, nil + } + return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to update pull request comment", resp, bodyBytes), nil, nil + } + + r, err := json.Marshal(MinimalResponse{ + ID: fmt.Sprintf("%d", comment.GetID()), + URL: comment.GetHTMLURL(), + }) + if err != nil { + return utils.NewToolResultErrorFromErr("failed to marshal response", err), nil, nil + } + + return utils.NewToolResultText(string(r)), nil, nil +} + +func deletePullRequestComment(ctx context.Context, client *github.Client, owner, repo string, commentID int64) (*mcp.CallToolResult, any, error) { + resp, err := client.PullRequests.DeleteComment(ctx, owner, repo, commentID) + if err != nil { + return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to delete pull request comment", resp, err), nil, nil + } + defer func() { _ = resp.Body.Close() }() + + if resp.StatusCode != http.StatusNoContent { + bodyBytes, err := io.ReadAll(resp.Body) + if err != nil { + return utils.NewToolResultErrorFromErr("failed to read response body", err), nil, nil + } + return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to delete pull request comment", resp, bodyBytes), nil, nil + } + + return utils.NewToolResultText(fmt.Sprintf("pull request comment %d deleted successfully", commentID)), nil, nil } // ListPullRequests creates a tool to list and filter repository pull requests. diff --git a/pkg/github/pullrequests_test.go b/pkg/github/pullrequests_test.go index 2b911636a9..4acd696fec 100644 --- a/pkg/github/pullrequests_test.go +++ b/pkg/github/pullrequests_test.go @@ -3767,23 +3767,24 @@ func getLatestPendingReviewQuery(p getLatestPendingReviewQueryParams) githubv4mo ) } -func TestAddReplyToPullRequestComment(t *testing.T) { +func TestPullRequestCommentWrite(t *testing.T) { t.Parallel() // Verify tool definition once - serverTool := AddReplyToPullRequestComment(translations.NullTranslationHelper) + serverTool := PullRequestCommentWrite(translations.NullTranslationHelper) tool := serverTool.Tool require.NoError(t, toolsnaps.Test(tool.Name, tool)) - assert.Equal(t, "add_reply_to_pull_request_comment", tool.Name) + assert.Equal(t, "pull_request_comment_write", tool.Name) assert.NotEmpty(t, tool.Description) schema := tool.InputSchema.(*jsonschema.Schema) + assert.Contains(t, schema.Properties, "method") assert.Contains(t, schema.Properties, "owner") assert.Contains(t, schema.Properties, "repo") assert.Contains(t, schema.Properties, "pullNumber") assert.Contains(t, schema.Properties, "commentId") assert.Contains(t, schema.Properties, "body") - assert.ElementsMatch(t, schema.Required, []string{"owner", "repo", "pullNumber", "commentId", "body"}) + assert.ElementsMatch(t, schema.Required, []string{"method", "owner", "repo", "commentId"}) // Setup mock reply comment for success case mockReplyComment := &github.PullRequestComment{ @@ -3798,16 +3799,30 @@ func TestAddReplyToPullRequestComment(t *testing.T) { UpdatedAt: &github.Timestamp{Time: time.Now()}, } + // Setup mock updated comment for success case + mockUpdatedComment := &github.PullRequestComment{ + ID: github.Ptr(int64(123)), + Body: github.Ptr("Updated comment text"), + HTMLURL: github.Ptr("https://github.com/owner/repo/pull/42#discussion_r123"), + User: &github.User{ + Login: github.Ptr("author"), + }, + CreatedAt: &github.Timestamp{Time: time.Now()}, + UpdatedAt: &github.Timestamp{Time: time.Now()}, + } + tests := []struct { name string mockedClient *http.Client requestArgs map[string]any expectToolError bool expectedToolErrMsg string + expectedInResult string }{ { name: "successful reply to pull request comment", requestArgs: map[string]any{ + "method": "reply", "owner": "owner", "repo": "repo", "pullNumber": float64(42), @@ -3821,10 +3836,66 @@ func TestAddReplyToPullRequestComment(t *testing.T) { _, _ = w.Write(responseData) }, }), + expectedInResult: "This is a reply to the comment", + }, + { + name: "successful update of pull request comment", + requestArgs: map[string]any{ + "method": "update", + "owner": "owner", + "repo": "repo", + "commentId": float64(123), + "body": "Updated comment text", + }, + mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ + PatchReposPullsCommentsByOwnerByRepoByCommentID: func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + responseData, _ := json.Marshal(mockUpdatedComment) + _, _ = w.Write(responseData) + }, + }), + expectedInResult: "https://github.com/owner/repo/pull/42#discussion_r123", + }, + { + name: "successful delete of pull request comment", + requestArgs: map[string]any{ + "method": "delete", + "owner": "owner", + "repo": "repo", + "commentId": float64(123), + }, + mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ + DeleteReposPullsCommentsByOwnerByRepoByCommentID: func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusNoContent) + }, + }), + expectedInResult: "pull request comment 123 deleted successfully", + }, + { + name: "missing required parameter method", + requestArgs: map[string]any{ + "owner": "owner", + "repo": "repo", + "commentId": float64(123), + }, + expectToolError: true, + expectedToolErrMsg: "missing required parameter: method", + }, + { + name: "invalid method", + requestArgs: map[string]any{ + "method": "resolve", + "owner": "owner", + "repo": "repo", + "commentId": float64(123), + }, + expectToolError: true, + expectedToolErrMsg: "invalid method, must be one of: 'reply', 'update', 'delete'", }, { name: "missing required parameter owner", requestArgs: map[string]any{ + "method": "reply", "repo": "repo", "pullNumber": float64(42), "commentId": float64(123), @@ -3836,6 +3907,7 @@ func TestAddReplyToPullRequestComment(t *testing.T) { { name: "missing required parameter repo", requestArgs: map[string]any{ + "method": "reply", "owner": "owner", "pullNumber": float64(42), "commentId": float64(123), @@ -3845,8 +3917,9 @@ func TestAddReplyToPullRequestComment(t *testing.T) { expectedToolErrMsg: "missing required parameter: repo", }, { - name: "missing required parameter pullNumber", + name: "missing required parameter pullNumber for reply", requestArgs: map[string]any{ + "method": "reply", "owner": "owner", "repo": "repo", "commentId": float64(123), @@ -3858,6 +3931,7 @@ func TestAddReplyToPullRequestComment(t *testing.T) { { name: "missing required parameter commentId", requestArgs: map[string]any{ + "method": "reply", "owner": "owner", "repo": "repo", "pullNumber": float64(42), @@ -3867,8 +3941,9 @@ func TestAddReplyToPullRequestComment(t *testing.T) { expectedToolErrMsg: "missing required parameter: commentId", }, { - name: "missing required parameter body", + name: "missing required parameter body for reply", requestArgs: map[string]any{ + "method": "reply", "owner": "owner", "repo": "repo", "pullNumber": float64(42), @@ -3877,6 +3952,17 @@ func TestAddReplyToPullRequestComment(t *testing.T) { expectToolError: true, expectedToolErrMsg: "missing required parameter: body", }, + { + name: "missing required parameter body for update", + requestArgs: map[string]any{ + "method": "update", + "owner": "owner", + "repo": "repo", + "commentId": float64(123), + }, + expectToolError: true, + expectedToolErrMsg: "missing required parameter: body", + }, { name: "API error when adding reply", mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ @@ -3886,6 +3972,7 @@ func TestAddReplyToPullRequestComment(t *testing.T) { }, }), requestArgs: map[string]any{ + "method": "reply", "owner": "owner", "repo": "repo", "pullNumber": float64(42), @@ -3895,6 +3982,41 @@ func TestAddReplyToPullRequestComment(t *testing.T) { expectToolError: true, expectedToolErrMsg: "failed to add reply to pull request comment", }, + { + name: "API error when updating comment authored by another user", + mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ + PatchReposPullsCommentsByOwnerByRepoByCommentID: func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusForbidden) + _, _ = w.Write([]byte(`{"message": "Forbidden"}`)) + }, + }), + requestArgs: map[string]any{ + "method": "update", + "owner": "owner", + "repo": "repo", + "commentId": float64(123), + "body": "Updated comment text", + }, + expectToolError: true, + expectedToolErrMsg: "failed to update pull request comment", + }, + { + name: "API error when deleting non-existent comment", + mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ + DeleteReposPullsCommentsByOwnerByRepoByCommentID: func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusNotFound) + _, _ = w.Write([]byte(`{"message": "Not Found"}`)) + }, + }), + requestArgs: map[string]any{ + "method": "delete", + "owner": "owner", + "repo": "repo", + "commentId": float64(999), + }, + expectToolError: true, + expectedToolErrMsg: "failed to delete pull request comment", + }, } for _, tc := range tests { @@ -3903,7 +4025,7 @@ func TestAddReplyToPullRequestComment(t *testing.T) { // Setup client with mock client := mustNewGHClient(t, tc.mockedClient) - serverTool := AddReplyToPullRequestComment(translations.NullTranslationHelper) + serverTool := PullRequestCommentWrite(translations.NullTranslationHelper) deps := BaseDeps{ Client: client, } @@ -3926,7 +4048,7 @@ func TestAddReplyToPullRequestComment(t *testing.T) { // Parse the result and verify it's not an error require.False(t, result.IsError) textContent := getTextResult(t, result) - assert.Contains(t, textContent.Text, "This is a reply to the comment") + assert.Contains(t, textContent.Text, tc.expectedInResult) }) } } diff --git a/pkg/github/tools.go b/pkg/github/tools.go index d1d585b3fa..bade39a524 100644 --- a/pkg/github/tools.go +++ b/pkg/github/tools.go @@ -228,7 +228,7 @@ func AllTools(t translations.TranslationHelperFunc) []inventory.ServerTool { UpdatePullRequest(t), PullRequestReviewWrite(t), AddCommentToPendingReview(t), - AddReplyToPullRequestComment(t), + PullRequestCommentWrite(t), // Copilot tools AssignCopilotToIssue(t),