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
+85
View File
@@ -943,6 +943,91 @@ func Test_closePullRequestFn(t *testing.T) {
}
}
func Test_listPullRequestCommentsFn_missingArgs(t *testing.T) {
result, err := listPullRequestCommentsFn(context.Background(), map[string]any{
"owner": "octo",
"repo": "demo",
})
if err != nil {
t.Fatalf("listPullRequestCommentsFn() error = %v", err)
}
if result == nil || !result.IsError {
t.Fatalf("listPullRequestCommentsFn() result = %#v, want an error result for missing pull_number", result)
}
}
func Test_listPullRequestCommentsFn_apiError(t *testing.T) {
const (
owner = "octo"
repo = "demo"
index = 7
)
serveStub(t, func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/comments", owner, repo, index) {
t.Errorf("unexpected request: %s %s", r.Method, r.URL.Path)
w.WriteHeader(http.StatusNotFound)
return
}
http.Error(w, "boom", http.StatusInternalServerError)
})
args := map[string]any{
"owner": owner, "repo": repo, "pull_number": float64(index),
}
result, err := listPullRequestCommentsFn(context.Background(), args)
if err != nil {
t.Fatalf("listPullRequestCommentsFn() error = %v", err)
}
if result == nil || !result.IsError {
t.Fatalf("listPullRequestCommentsFn() result = %#v, want an error result on API failure", result)
}
}
func Test_listPullRequestCommentsFn_decodesComments(t *testing.T) {
const (
owner = "octo"
repo = "demo"
index = 7
)
serveStub(t, func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/comments", owner, repo, index) {
t.Errorf("unexpected request: %s %s", r.Method, r.URL.Path)
w.WriteHeader(http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`[
{"id": 1, "body": "see this", "assets": [
{"id": 9, "name": "log.txt", "size": 200, "browser_download_url": "https://example/log.txt"}
]},
{"id": 2, "body": "no attachment", "assets": []}
]`))
})
args := map[string]any{
"method": "get_comments", "owner": owner, "repo": repo, "pull_number": float64(index),
}
result, err := pullRequestReadFn(context.Background(), args)
if err != nil {
t.Fatalf("pullRequestReadFn() error = %v", err)
}
if result.IsError {
t.Fatalf("unexpected error result: %v", result.Content)
}
body := result.Content[0].(*mcp.TextContent).Text
if !strings.Contains(body, `[log.txt](https://example/log.txt)`) {
t.Fatalf("expected attachment markdown inlined in body, got: %s", body)
}
if !strings.Contains(body, `"no attachment"`) {
t.Fatalf("expected second comment body preserved, got: %s", body)
}
if strings.Contains(body, `"assets"`) {
t.Fatalf("assets should be inlined into body, not a separate field: %s", body)
}
}
func Test_reopenPullRequestFn(t *testing.T) {
const (
owner = "octo"