feat(pull): add get_comments method to pull_request_read

List regular PR discussion comments via the issue comments endpoint,
since Gitea pull requests are issues internally. Reuses the issue
package's slim comment shape with attachment inlining.

Co-Authored-By: Codet <codet@commitgo.dev> (GPT-5-Codex)
This commit is contained in:
Lunny Xiao
2026-08-23 23:36:53 -07:00
parent 815a0e26aa
commit 2ffb16ba1e
3 changed files with 140 additions and 2 deletions
+41 -2
View File
@@ -20,6 +20,13 @@ import (
var Tool = tool.New("pull_request")
// commentWithAssets wraps the SDK Comment to capture the `assets` field that
// the SDK currently drops on the issue comments endpoint.
type commentWithAssets struct {
gitea_sdk.Comment
Assets []*gitea_sdk.Attachment `json:"assets"`
}
const (
ListRepoPullRequestsToolName = "list_pull_requests"
PullRequestReadToolName = "pull_request_read"
@@ -43,9 +50,9 @@ var (
PullRequestReadTool = tool.NewDefinition(
PullRequestReadToolName,
"Read pull request: details, diff, changed files, head commit status, reviews, review comments.",
"Read pull request: details, diff, changed files, head commit status, reviews, review comments, discussion comments.",
annotation.ReadOnly("Read pull request details"),
tool.String("method", tool.Required(), tool.Enum("get", "get_diff", "get_files", "get_status", "get_reviews", "get_review", "get_review_comments")),
tool.String("method", tool.Required(), tool.Enum("get", "get_diff", "get_files", "get_status", "get_reviews", "get_review", "get_review_comments", "get_comments")),
tool.String("owner", tool.Required(), tool.Description(params.OwnerDesc)),
tool.String("repo", tool.Required(), tool.Description(params.RepoDesc)),
tool.Number("pull_number", tool.Required()),
@@ -151,6 +158,8 @@ func pullRequestReadFn(ctx context.Context, args map[string]any) (*mcp.CallToolR
return getPullRequestReviewFn(ctx, args)
case "get_review_comments":
return listPullRequestReviewCommentsFn(ctx, args)
case "get_comments":
return listPullRequestCommentsFn(ctx, args)
default:
return to.ErrorResult(fmt.Errorf("unknown method: %s", method))
}
@@ -603,6 +612,36 @@ func listPullRequestReviewCommentsFn(ctx context.Context, args map[string]any) (
return to.TextResult(slimReviewComments(comments))
}
func listPullRequestCommentsFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult, error) {
owner, err := params.GetString(args, "owner")
if err != nil {
return to.ErrorResult(err)
}
repo, err := params.GetString(args, "repo")
if err != nil {
return to.ErrorResult(err)
}
index, err := params.GetIndex(args, "pull_number")
if err != nil {
return to.ErrorResult(err)
}
// PRs are issues internally, so the regular discussion comments live on
// the issue comments endpoint rather than a pull-specific one.
var comments []commentWithAssets
path := fmt.Sprintf("repos/%s/%s/issues/%d/comments", url.PathEscape(owner), url.PathEscape(repo), index)
if _, err := gitea.DoJSON(ctx, "GET", path, nil, nil, &comments); err != nil {
return to.ErrorResult(fmt.Errorf("get %v/%v/pr/%v comments err: %v", owner, repo, index, err))
}
out := make([]map[string]any, 0, len(comments))
for i := range comments {
m := slimComment(&comments[i].Comment)
m["body"] = slim.BodyWithAttachments(comments[i].Body, comments[i].Assets)
out = append(out, m)
}
return to.TextResult(out)
}
func createPullRequestReviewFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult, error) {
owner, err := params.GetString(args, "owner")
if err != nil {