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

Method Search

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

Source from the content-addressed store, hash-verified

285}
286
287func (c *discussionClient) Search(repo ghrepo.Interface, filters SearchFilters, after string, limit int) (*DiscussionListResult, error) {
288 if limit <= 0 {
289 return nil, fmt.Errorf("limit argument must be positive: %v", limit)
290 }
291
292 var query struct {
293 Search struct {
294 DiscussionCount int
295 PageInfo struct {
296 HasNextPage bool
297 EndCursor string
298 }
299 Nodes []struct {
300 Discussion discussionListNode `graphql:"... on Discussion"`
301 }
302 } `graphql:"search(query: $query, type: DISCUSSION, first: $first, after: $after)"`
303 }
304
305 qualifiers := []string{fmt.Sprintf("repo:%s/%s", repo.RepoOwner(), repo.RepoName())}
306
307 if filters.State != nil {
308 switch *filters.State {
309 case FilterStateOpen:
310 qualifiers = append(qualifiers, "is:open")
311 case FilterStateClosed:
312 qualifiers = append(qualifiers, "is:closed")
313 default:
314 return nil, fmt.Errorf("unknown state filter: %q; should be one of %q, %q", *filters.State, FilterStateOpen, FilterStateClosed)
315 }
316 }
317
318 if filters.Author != "" {
319 qualifiers = append(qualifiers, fmt.Sprintf("author:%q", filters.Author))
320 }
321 for _, l := range filters.Labels {
322 qualifiers = append(qualifiers, fmt.Sprintf("label:%q", l))
323 }
324 if filters.Category != "" {
325 qualifiers = append(qualifiers, fmt.Sprintf("category:%q", filters.Category))
326 }
327 if filters.Answered != nil {
328 if *filters.Answered {
329 qualifiers = append(qualifiers, "is:answered")
330 } else {
331 qualifiers = append(qualifiers, "is:unanswered")
332 }
333 }
334
335 orderField := "updated"
336 orderDir := "desc"
337 if filters.OrderBy != "" {
338 switch filters.OrderBy {
339 case OrderByCreated:
340 orderField = "created"
341 case OrderByUpdated:
342 orderField = "updated"
343 default:
344 return nil, fmt.Errorf("unknown order-by field: %q", filters.OrderBy)

Callers

nothing calls this directly

Calls 8

JoinMethod · 0.80
ErrorfMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
StringMethod · 0.65
QueryMethod · 0.65
RepoHostMethod · 0.65

Tested by

no test coverage detected