Skip to content

Commit 6e14e0b

Browse files
authored
Merge pull request #1833 from entireio/fix/trail-comment-show-message-ids
fix(trail): surface message IDs in comment show
2 parents d79a200 + d966d3f commit 6e14e0b

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

cmd/entire/cli/trail_collaboration_cmd_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
11
package cli
22

33
import (
4+
"bytes"
45
"strings"
56
"testing"
7+
8+
"github.com/entireio/cli/cmd/entire/cli/api"
69
)
710

11+
func TestPrintTrailThreadDetail_ShowsMessageIDs(t *testing.T) {
12+
t.Parallel()
13+
// edit/delete take <thread-id> <message-id>; the text output must surface
14+
// the message and reply IDs so they are discoverable without --json.
15+
out := api.TrailThreadDetailResponse{
16+
Thread: api.TrailThreadSummary{ID: "th1", Title: "Design"},
17+
Messages: []api.TrailThreadMessage{{
18+
ID: "msg-abc",
19+
Author: "alice",
20+
Body: "top message",
21+
Replies: []api.TrailThreadReply{{
22+
ID: "rep-xyz",
23+
Author: "bob",
24+
Body: "a reply",
25+
}},
26+
}},
27+
}
28+
var buf bytes.Buffer
29+
if err := printTrailThreadDetail(&buf, out, false); err != nil {
30+
t.Fatalf("printTrailThreadDetail: %v", err)
31+
}
32+
got := buf.String()
33+
if !strings.Contains(got, "msg-abc") {
34+
t.Errorf("output missing message ID %q:\n%s", "msg-abc", got)
35+
}
36+
if !strings.Contains(got, "rep-xyz") {
37+
t.Errorf("output missing reply ID %q:\n%s", "rep-xyz", got)
38+
}
39+
}
40+
841
func TestTrailThreadPathBuilders(t *testing.T) {
942
t.Parallel()
1043
if got := trailThreadsPath("gh", "acme", "widgets", 7); !strings.HasSuffix(got, "/7/threads") {

cmd/entire/cli/trail_comment_cmd.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,11 @@ func printTrailThreadDetail(w io.Writer, out api.TrailThreadDetailResponse, json
195195
}
196196
fmt.Fprintf(w, "Thread %s [%s]: %s\n\n", t.ID, marker, t.Title)
197197
for _, m := range out.Messages {
198-
fmt.Fprintf(w, "%s %s\n%s\n", m.Author, m.CreatedAt.Format(time.RFC3339), m.Body)
198+
// The message ID is the argument `comment edit`/`delete` take, so it
199+
// must be visible here (the only plain-text read that shows messages).
200+
fmt.Fprintf(w, "%s %s %s\n%s\n", m.ID, m.Author, m.CreatedAt.Format(time.RFC3339), m.Body)
199201
for _, r := range m.Replies {
200-
fmt.Fprintf(w, " ↳ %s %s\n %s\n", r.Author, r.CreatedAt.Format(time.RFC3339), r.Body)
202+
fmt.Fprintf(w, " ↳ %s %s %s\n %s\n", r.ID, r.Author, r.CreatedAt.Format(time.RFC3339), r.Body)
201203
}
202204
fmt.Fprintln(w)
203205
}
@@ -284,6 +286,7 @@ func newTrailCommentEditCmd() *cobra.Command {
284286
cmd := &cobra.Command{
285287
Use: "edit <thread-id> <message-id>",
286288
Short: "Edit a message in a discussion thread",
289+
Long: "Edit a message in a discussion thread.\n\nFind <thread-id> with 'entire trail comment list' and <message-id> with 'entire trail comment show <thread-id>'.",
287290
Args: cobra.ExactArgs(2),
288291
RunE: func(cmd *cobra.Command, args []string) error {
289292
threadID, messageID := args[0], args[1]
@@ -318,6 +321,7 @@ func newTrailCommentDeleteCmd() *cobra.Command {
318321
cmd := &cobra.Command{
319322
Use: "delete <thread-id> <message-id>",
320323
Short: "Delete a message from a discussion thread",
324+
Long: "Delete a message from a discussion thread.\n\nFind <thread-id> with 'entire trail comment list' and <message-id> with 'entire trail comment show <thread-id>'.",
321325
Args: cobra.ExactArgs(2),
322326
RunE: func(cmd *cobra.Command, args []string) error {
323327
threadID, messageID := args[0], args[1]

0 commit comments

Comments
 (0)