mirror of
https://gitea.com/gitea/gitea-mcp.git
synced 2026-08-29 19:47:44 +00:00
feat(issue): add get_discussion_markdown to issue_read
Adds a new issue_read method that fetches an issue and its comments and renders them as a single Markdown document, instead of a JSON array. Formatting logic lives in a pure, unit-tested helper (formatDiscussionMarkdown) covering comment rendering, empty comment lists, and attachment-inlined bodies. Existing get/get_comments/ get_labels methods are unchanged. Co-Authored-By: Codet <codet@commitgo.dev> (GPT-5-Codex)
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
package issue
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Test_formatDiscussionMarkdown_includesIssueAndComments(t *testing.T) {
|
||||
created := time.Date(2026, 1, 2, 15, 4, 5, 0, time.UTC)
|
||||
commentTime := time.Date(2026, 1, 3, 9, 0, 0, 0, time.UTC)
|
||||
md := formatDiscussionMarkdown(
|
||||
discussionIssue{
|
||||
Number: 42,
|
||||
Title: "bug with screenshot",
|
||||
Author: "octocat",
|
||||
State: "open",
|
||||
Labels: []string{"bug", "help wanted"},
|
||||
Body: "see attached",
|
||||
CreatedAt: created,
|
||||
},
|
||||
[]discussionComment{
|
||||
{Author: "reviewer", CreatedAt: commentTime, Body: "thanks for reporting"},
|
||||
},
|
||||
)
|
||||
|
||||
wantSubstrings := []string{
|
||||
"# bug with screenshot (#42)",
|
||||
"**Author:** octocat",
|
||||
"**State:** open",
|
||||
"**Labels:** bug, help wanted",
|
||||
"**Created:** 2026-01-02T15:04:05Z",
|
||||
"see attached",
|
||||
"## Comments",
|
||||
"### reviewer",
|
||||
"2026-01-03T09:00:00Z",
|
||||
"thanks for reporting",
|
||||
}
|
||||
for _, want := range wantSubstrings {
|
||||
if !strings.Contains(md, want) {
|
||||
t.Fatalf("expected markdown to contain %q, got:\n%s", want, md)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Test_formatDiscussionMarkdown_noComments(t *testing.T) {
|
||||
md := formatDiscussionMarkdown(
|
||||
discussionIssue{
|
||||
Number: 1,
|
||||
Title: "no comments yet",
|
||||
Author: "octocat",
|
||||
State: "open",
|
||||
},
|
||||
nil,
|
||||
)
|
||||
|
||||
if !strings.Contains(md, "## Comments") {
|
||||
t.Fatalf("expected a Comments section, got:\n%s", md)
|
||||
}
|
||||
if !strings.Contains(md, "_No comments yet._") {
|
||||
t.Fatalf("expected placeholder for no comments, got:\n%s", md)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_formatDiscussionMarkdown_attachmentBodyIsInlined(t *testing.T) {
|
||||
md := formatDiscussionMarkdown(
|
||||
discussionIssue{
|
||||
Number: 7,
|
||||
Title: "with attachment",
|
||||
Author: "octocat",
|
||||
State: "open",
|
||||
Body: "see attached\n\n[shot.png](https://example/shot.png)",
|
||||
},
|
||||
[]discussionComment{
|
||||
{Author: "reviewer", Body: "log attached\n\n[log.txt](https://example/log.txt)"},
|
||||
},
|
||||
)
|
||||
|
||||
if !strings.Contains(md, "[shot.png](https://example/shot.png)") {
|
||||
t.Fatalf("expected issue attachment link in markdown, got:\n%s", md)
|
||||
}
|
||||
if !strings.Contains(md, "[log.txt](https://example/log.txt)") {
|
||||
t.Fatalf("expected comment attachment link in markdown, got:\n%s", md)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user