cli/pkg/cmd/discussion/shared/display.go
Max Beizer d9e9751823
Add discussion view command
Implement `gh discussion view` for viewing a single discussion with:

- Number or URL argument via shared.ParseDiscussionArg
- TTY output: title, metadata (state, category, author, age, comment
  count), labels, markdown-rendered body, reactions
- Context-aware author attribution: "Asked by" for answerable
  categories (Q&A), "Started by" for others
- Non-TTY output: key-value pairs matching `gh issue view` format
- JSON output via Exporter (Discussion.ExportData)
- --web flag to open in browser
- Pager support for TTY output

Also adds:
- GetByNumber client method with not-found detection
- shared.ParseDiscussionArg for number/URL/#number parsing
- shared.ReactionGroupList for emoji reaction display

Comment threading (--comments) is deferred to the next PR.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-24 21:24:25 +01:00

35 lines
781 B
Go

package shared
import (
"fmt"
"strings"
"github.com/cli/cli/v2/pkg/cmd/discussion/client"
)
var reactionEmoji = map[string]string{
"THUMBS_UP": "\U0001f44d",
"THUMBS_DOWN": "\U0001f44e",
"LAUGH": "\U0001f604",
"HOORAY": "\U0001f389",
"CONFUSED": "\U0001f615",
"HEART": "\u2764\ufe0f",
"ROCKET": "\U0001f680",
"EYES": "\U0001f440",
}
// ReactionGroupList formats reaction groups for display.
func ReactionGroupList(groups []client.ReactionGroup) string {
var parts []string
for _, g := range groups {
if g.TotalCount == 0 {
continue
}
emoji := reactionEmoji[g.Content]
if emoji == "" {
emoji = g.Content
}
parts = append(parts, fmt.Sprintf("%s %d", emoji, g.TotalCount))
}
return strings.Join(parts, " • ")
}