MCPcopy Create free account
hub / github.com/cli/cli / List

Method List

pkg/cmd/discussion/client/client.go:178–285  ·  view source on GitHub ↗
(repo ghrepo.Interface, filters ListFilters, after string, limit int)

Source from the content-addressed store, hash-verified

176}
177
178func (c *discussionClient) List(repo ghrepo.Interface, filters ListFilters, after string, limit int) (*DiscussionListResult, error) {
179 if limit <= 0 {
180 return nil, fmt.Errorf("limit argument must be positive: %v", limit)
181 }
182
183 var query struct {
184 Repository struct {
185 HasDiscussionsEnabled bool
186 Discussions struct {
187 TotalCount int
188 PageInfo struct {
189 HasNextPage bool
190 EndCursor string
191 }
192 Nodes []discussionListNode
193 } `graphql:"discussions(first: $first, after: $after, orderBy: $orderBy, categoryId: $categoryId, states: $states, answered: $answered)"`
194 } `graphql:"repository(owner: $owner, name: $name)"`
195 }
196
197 orderField := githubv4.DiscussionOrderFieldUpdatedAt
198 orderDir := githubv4.OrderDirectionDesc
199 if filters.OrderBy != "" {
200 switch filters.OrderBy {
201 case OrderByCreated:
202 orderField = githubv4.DiscussionOrderFieldCreatedAt
203 case OrderByUpdated:
204 orderField = githubv4.DiscussionOrderFieldUpdatedAt
205 default:
206 return nil, fmt.Errorf("unknown order-by field: %q", filters.OrderBy)
207 }
208 }
209 if filters.Direction != "" {
210 switch filters.Direction {
211 case OrderDirectionAsc:
212 orderDir = githubv4.OrderDirectionAsc
213 case OrderDirectionDesc:
214 orderDir = githubv4.OrderDirectionDesc
215 default:
216 return nil, fmt.Errorf("unknown order direction: %q", filters.Direction)
217 }
218 }
219
220 variables := map[string]any{
221 "owner": githubv4.String(repo.RepoOwner()),
222 "name": githubv4.String(repo.RepoName()),
223 "after": (*githubv4.String)(nil),
224 "orderBy": githubv4.DiscussionOrder{Field: orderField, Direction: orderDir},
225 "categoryId": (*githubv4.ID)(nil),
226 "states": (*[]githubv4.DiscussionState)(nil),
227 "answered": (*githubv4.Boolean)(nil),
228 }
229
230 if after != "" {
231 variables["after"] = githubv4.String(after)
232 }
233
234 if filters.CategoryID != "" {
235 variables["categoryId"] = githubv4.ID(filters.CategoryID)

Callers

nothing calls this directly

Calls 8

ErrorfMethod · 0.65
StringMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
IDMethod · 0.65
QueryMethod · 0.65
RepoHostMethod · 0.65

Tested by

no test coverage detected