mirror of
https://gitea.com/gitea/gitea-mcp.git
synced 2026-08-27 10:37:44 +00:00
3c6d2ecd6b
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)
86 lines
2.1 KiB
Go
86 lines
2.1 KiB
Go
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)
|
|
}
|
|
}
|