Commit graph

15 commits

Author SHA1 Message Date
Babak K. Shandiz
52f219a5ac
test(discussion view): consolidate view run tests
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-29 13:05:21 +01:00
Babak K. Shandiz
54ddede12f
test(discussion/view): consolidate NewCmdView flag parsing tests
Replace scattered standalone test functions with a single table-driven
TestNewCmdView covering all arg/flag parsing: number, hash, URL, web,
comments, replies, limit, after, order, mutual exclusivity, and invalid
inputs. Uses shlex.Split for arg parsing and asserts opts fields
individually per case.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-28 11:03:55 +01:00
Max Beizer
11130fd6be
test(discussion view): add tests for view command client methods and --replies mode
Add table-driven tests for:

Client (client_impl_test.go):
- TestGetByNumber: field mapping, discussions disabled
- TestGetWithComments: field mapping, forward/backward pagination,
  reply reversal in newest mode, discussions disabled
- TestGetCommentReplies: field mapping, forward/backward pagination,
  reply reversal, discussions disabled, nil node, wrong node type

Command (view_test.go):
- TestNewCmdView_repliesFlags: mutual exclusivity with --comments/--web,
  --order/--limit/--after require --comments or --replies, pagination
  flags work with --replies
- TestViewRun_replies: TTY/non-TTY/JSON output, pagination hints,
  routing assertion (GetCommentReplies called, not GetByNumber or
  GetWithComments)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-27 15:42:36 -05:00
Babak K. Shandiz
59701725d0
fix(discussion view): guard against empty comment slice in replies mode
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-27 18:46:14 +01:00
Babak K. Shandiz
56db9ee6e9
feat(gh discussion view): add --replies flag for paginated reply viewing
Add --replies <COMMENT-ID> flag to view paginated replies on a specific
discussion comment. Mutually exclusive with --comments and --web. Works
with --limit, --after, and --order for pagination control. Supports TTY,
raw, and JSON output modes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-27 10:58:06 +01:00
Babak K. Shandiz
72a6c98d37
refactor(discussion view): simplify mode check
Signed-off-by: Babak K. Shandiz <babakks@github.com>
2026-04-27 08:46:56 +01:00
Babak K. Shandiz
49a846aa1a
docs(discussion view): use non-default behaviour in example
Signed-off-by: Babak K. Shandiz <babakks@github.com>
2026-04-27 08:45:50 +01:00
Max Beizer
9f3a31ddb3
fix(discussion view): use GraphQL variables for cursor, fix --json comments
Fix two issues in the discussion view command:

1. GraphQL injection via cursor interpolation: The --after cursor value
   was interpolated directly into the raw GraphQL query string using
   fmt.Sprintf, which is unsafe since cursor values come from user input.
   Now uses GraphQL variables ($cursor: String) instead, matching the
   pattern used by issue list, pr list, and other commands.

2. Incomplete --json comments output: Running `gh discussion view N
   --json comments` silently returned only totalCount with no comment
   nodes, because the data fetch was gated solely on the --comments flag.
   Now checks if the JSON exporter requests the comments field and
   fetches full comment data accordingly, matching how issue view and
   pr view drive data loading from exporter fields.

Also fixes example text that said "newest" but showed --order oldest.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-25 12:19:04 -05:00
Babak K. Shandiz
d2e081bce1
feat(discussion view): add cursor-based pagination to comments
Add --limit and --after flags for paginating through discussion comments.
Cursor output is shown in TTY (hint message), raw (next: field), and JSON.

Change GetWithComments to accept 'after' cursor and 'newest' bool instead
of order string. Implement forward/backward cursor-based pagination in
GraphQL queries depending on comment order.

Change Replies from []DiscussionComment to DiscussionCommentList with
Direction field. Display direction-aware messages (newer/older) for both
comments and replies.

Move DiscussionFields and reactionGroupList from shared to view package.
Delete shared/display.go.

Add 7 new pagination tests and update existing test fixtures.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-24 23:50:04 +01:00
Babak K. Shandiz
75b71505c8
refactor(discussion view): use slices package for label sorting
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-24 22:19:59 +01:00
Babak K. Shandiz
6bd96abd6a
fix(gh discussion view): wrap arg parse error as flag error
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-24 22:02:44 +01:00
Babak K. Shandiz
cd3b23bf36
docs(discussion view): add preview remark
Signed-off-by: Babak K. Shandiz <babakks@github.com>
2026-04-24 21:37:58 +01:00
Max Beizer
ca84d4c6a3
Add discussion view --comments with threaded display
Implement the --comments flag for discussion view, showing threaded
comments with replies.

Features:
- --comments flag fetches and displays discussion comments
- --order flag (oldest/newest) controls comment ordering
- Answer badge (✓ Answer) on marked answer comments
- Threaded replies with indentation
- Truncation messages when more replies exist than fetched
- TTY: markdown-rendered comments with author/timestamp/reactions
- Non-TTY: stable tab-delimited format for scripting
- JSON: populated comment nodes via ExportData

Implementation:
- GetWithComments uses raw GraphQL to dynamically switch between
  first/last based on ordering. Fetches 30 comments with 4 replies
  each. Explicitly reverses for newest-first ordering.
- --order without --comments returns a flag error
- Reuses existing shared.ReactionGroupList for reaction display

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-24 21:24:30 +01:00
Max Beizer
d6e63f63d3
fix(discussion view): align with post-review list changes
- Rewrite GetByNumber to use strongly-typed GraphQL query instead of
  removed raw string interpolation (discussionFields/discussionNode)
- Fix State string references to use Closed bool throughout view.go
- Fix DiscussionAuthor → DiscussionActor type rename in tests
- Add ReactionGroups field to Discussion domain type and ExportData
- Add computed "state" field to ExportData for JSON output
- Add shared.DiscussionFields for view command's --json flag
- Regenerate client mock

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-24 21:24:30 +01:00
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