Commit graph

15 commits

Author SHA1 Message Date
Max Beizer
aa080ad28a
refactor(discussion): convert client tests to table-driven
Addresses babakks' review on PR #13252:
- Convert 18 individual test functions to 3 table-driven functions
- Replace ptr helper with new(value) syntax throughout
- Assert all Discussion struct fields in success cases
- Add after-cursor test cases for pagination
- Fold pagination tests into table structure

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-22 15:04:59 -05:00
Max Beizer
35e8cc93cf
test(discussion): add httpmock unit tests for DiscussionClient
Add comprehensive httpmock-based unit tests for the client package covering:
- List: success path, discussions disabled, limit/filter validation, pagination
- Search: success path, filter validation, pagination
- ListCategories: success path, discussions disabled

Tests use httpmock.Registry with defer Verify(t) to ensure all stubs
are exercised, following the established testing pattern in this repo.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-21 09:12:31 -05:00
Babak K. Shandiz
835d7f3a48
fix(discussion/client): remove reaction groups from list/search types
Signed-off-by: Babak K. Shandiz <babakks@github.com>
2026-04-14 14:50:40 +01:00
Babak K. Shandiz
e403e82633
refactor(discussion/client): use strongly-typed query for list function
Signed-off-by: Babak K. Shandiz <babakks@github.com>
2026-04-14 14:30:21 +01:00
Babak K. Shandiz
9afbd61c5f
refactor(discussion/client): use strongly-typed query for search function
Signed-off-by: Babak K. Shandiz <babakks@github.com>
2026-04-14 13:25:42 +01:00
Babak K. Shandiz
2a46a9d733
fix(discussion/client): change list return type to pointer
Signed-off-by: Babak K. Shandiz <babakks@github.com>
2026-04-14 12:24:08 +01:00
Babak K. Shandiz
e6befd5efd
fix(discussion/client): simplify list query
Signed-off-by: Babak K. Shandiz <babakks@github.com>
2026-04-14 12:16:23 +01:00
Babak K. Shandiz
034e38f0e7
fix(discussion/client): fetch author/answerChosenBy fields
Signed-off-by: Babak K. Shandiz <babakks@github.com>
2026-04-14 12:11:00 +01:00
Babak K. Shandiz
15d3eeae06
fix(discussion/client): fetch body in list/search
Signed-off-by: Babak K. Shandiz <babakks@github.com>
2026-04-14 11:53:36 +01:00
Babak K. Shandiz
236224dc44
fix(discussion list): replace state with closed in domain types
Signed-off-by: Babak K. Shandiz <babakks@github.com>
2026-04-14 11:52:52 +01:00
Max Beizer
0687a29e51
Fix GQL schema: Discussion uses closed bool, not state string
The GraphQL Discussion type has a `closed` boolean field, not a
`state` string. Updated the API response struct and GQL fragment
to query `closed` instead of `state`, and derive the domain-level
State string ("OPEN"/"CLOSED") from the boolean in mapDiscussion.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-13 11:51:22 -05:00
Max Beizer
17238050d7
Check hasDiscussionsEnabled in ListCategories
When --category is used, ListCategories runs before the List query.
On repos with discussions disabled, it silently returns empty categories,
leading to a confusing "must be one of []" error. Now it checks
hasDiscussionsEnabled and returns the standard "discussions disabled"
error, matching the behavior of List and Search.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-13 10:38:51 -05:00
Max Beizer
e84ecb1585
Address review feedback on discussion list PR
- Export domain consts (FilterStateOpen/Closed, OrderByCreated/Updated,
  OrderDirectionAsc/Desc) in types.go
- Change State fields to *string (nil = all states)
- Add DiscussionListResult type with NextCursor for pagination
- Update List/Search signatures: add after param, return result type
- Add limit <= 0 guard clauses in client methods
- Replace strings.ToUpper/ToLower with switch statements + default errors
- Rename pageLimit to remaining, hoist hasDiscussionsEnabled check
- Use qualifier/keyword terminology in search query building
- Quote author values with %q for whitespace safety
- Add Keywords string field (single string, not []string)
- Split --order into --sort {created|updated} and --order {asc|desc}
- Add --search/-S and --after flags
- Add next field in JSON output envelope
- Extract defaultLimit const
- Add toFilterState helper for CLI-to-domain mapping
- Move matchCategory to shared/categories.go with godoc
- Use single-line error messages with sorted slugs
- Add (preview) annotations to Short docs
- Update Use to "list [flags]"
- Add examples for --answered=false, --state all, multi-label
- Update tests for new signatures and new flags

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-13 10:20:09 -05:00
Max Beizer
90449b5197
Implement gh discussion list command
Add the discussion list command with full support for:
- Listing discussions with state, category, answered, and order filters
- Searching discussions by author and labels (uses Search API)
- Category resolution by slug or name (case-insensitive)
- TTY and non-TTY table output with colored IDs and labels
- JSON output with totalCount envelope
- Web mode (--web) to open discussions in browser
- Pagination for large result sets

Implement List, Search, and ListCategories methods on the
DiscussionClient. List and Search use plain text GraphQL for
flexible variable handling. ListCategories uses safely typed
GraphQL via shurcooL/githubv4.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-03 12:46:28 -05:00
Max Beizer
45c68b48da
Add discussion command group scaffolding
Introduce the pkg/cmd/discussion/ package with:

- DiscussionClient interface and domain types (client/)
- Generated mock via moq (client/)
- Factory function for lazy client creation (shared/)
- JSON field definitions for --json output (shared/)
- Root 'discussion' command registered in the core group

The interface defines all planned operations (list, search, get, create,
update, close, reopen, comment, lock, unlock, mark-answer, unmark-answer)
with stub implementations that will be replaced as each subcommand is
added in subsequent PRs.

Domain types are intentionally separate from API types per review guidance.
No JSON struct tags are used; serialization is handled by ExportData methods.

Refs: cli/cli#12810, github/gh-cli-and-desktop#115

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-02 10:55:48 -05:00