mirror of
https://gitea.com/gitea/gitea-mcp.git
synced 2026-08-29 11:37: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,63 @@
|
||||
package issue
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type discussionIssue struct {
|
||||
Number int64
|
||||
Title string
|
||||
Author string
|
||||
State string
|
||||
Labels []string
|
||||
Body string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
type discussionComment struct {
|
||||
Author string
|
||||
CreatedAt time.Time
|
||||
Body string
|
||||
}
|
||||
|
||||
// formatDiscussionMarkdown renders an issue and its comments as a single
|
||||
// Markdown document suitable for display without further parsing.
|
||||
func formatDiscussionMarkdown(issue discussionIssue, comments []discussionComment) string {
|
||||
var b strings.Builder
|
||||
|
||||
fmt.Fprintf(&b, "# %s (#%d)\n\n", issue.Title, issue.Number)
|
||||
fmt.Fprintf(&b, "**Author:** %s\n", issue.Author)
|
||||
fmt.Fprintf(&b, "**State:** %s\n", issue.State)
|
||||
if len(issue.Labels) > 0 {
|
||||
fmt.Fprintf(&b, "**Labels:** %s\n", strings.Join(issue.Labels, ", "))
|
||||
}
|
||||
if !issue.CreatedAt.IsZero() {
|
||||
fmt.Fprintf(&b, "**Created:** %s\n", issue.CreatedAt.UTC().Format(time.RFC3339))
|
||||
}
|
||||
b.WriteString("\n")
|
||||
b.WriteString(strings.TrimSpace(issue.Body))
|
||||
b.WriteString("\n\n---\n\n## Comments\n\n")
|
||||
|
||||
if len(comments) == 0 {
|
||||
b.WriteString("_No comments yet._\n")
|
||||
return b.String()
|
||||
}
|
||||
|
||||
for i, c := range comments {
|
||||
fmt.Fprintf(&b, "### %s", c.Author)
|
||||
if !c.CreatedAt.IsZero() {
|
||||
fmt.Fprintf(&b, " on %s", c.CreatedAt.UTC().Format(time.RFC3339))
|
||||
}
|
||||
b.WriteString("\n\n")
|
||||
b.WriteString(strings.TrimSpace(c.Body))
|
||||
if i < len(comments)-1 {
|
||||
b.WriteString("\n\n---\n\n")
|
||||
} else {
|
||||
b.WriteString("\n")
|
||||
}
|
||||
}
|
||||
|
||||
return b.String()
|
||||
}
|
||||
Reference in New Issue
Block a user