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