Skip to content

Add discussion view command#13093

Closed
maxbeizer wants to merge 2 commits into
cli:feature/discussionfrom
maxbeizer:discussion-view
Closed

Add discussion view command#13093
maxbeizer wants to merge 2 commits into
cli:feature/discussionfrom
maxbeizer:discussion-view

Conversation

@maxbeizer

Copy link
Copy Markdown
Contributor

Summary

Implements gh discussion view — view a single discussion with full metadata, body, and reactions (PR 3 of 11).

Features

  • Argument parsing: Accepts discussion number (123), #123, or full URL (https://github.com/OWNER/REPO/discussions/123)
  • TTY output: Title, metadata line (state · category · author · age · comment count), labels, markdown-rendered body, reactions
  • Context-aware wording: "Asked by" for answerable categories (Q&A), "Started by" for others
  • Non-TTY output: Key-value pairs matching gh issue view format
  • JSON output: Full ExportData support with --json, --jq, --template
  • Web mode: --web opens discussion in browser
  • Not-found handling: Clear error when discussion number does not exist

Flags

  -w, --web               Open in browser
      --json fields        Output JSON with specified fields
  -q, --jq expression     Filter JSON output
  -t, --template string   Format JSON output

Implementation

  • GetByNumber on DiscussionClient — plain text GraphQL, reuses discussionNode/mapDiscussion from list, with null-pointer detection for not-found
  • shared.ParseDiscussionArg — number/URL/#number parser
  • shared.ReactionGroupList — emoji reaction formatter for domain types

Tests

8 test cases: TTY, non-TTY, JSON, web mode, URL argument, answerable vs non-answerable categories, arg parsing. All use DiscussionClientMock.

What's next

PR 4: discussion view --comments (threading)

Ref: #12810

@github-actions github-actions Bot added external pull request originating outside of the CLI core team needs-triage needs to be reviewed labels Apr 3, 2026
@maxbeizer

Copy link
Copy Markdown
Contributor Author

Note: This PR is stacked on #13084 (discussion list). The diff currently includes the list commit because that PR hasn't merged into feature/discussion yet. Once #13084 merges, I'll rebase and the diff will show only the view changes (~712 lines across 6 files).

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>
- 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>
@maxbeizer maxbeizer marked this pull request as ready for review April 16, 2026 22:20
@maxbeizer maxbeizer requested a review from a team as a code owner April 16, 2026 22:20
@maxbeizer maxbeizer requested review from williammartin and removed request for a team April 16, 2026 22:20
@babakks

babakks commented Apr 29, 2026

Copy link
Copy Markdown
Member

Closing this as already completed in #13214

@babakks babakks closed this Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team needs-triage needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants