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