CurrentUserProjectsV2 fetches all open projectsV2 for current user.
(client *Client, hostname string)
| 285 | |
| 286 | // CurrentUserProjectsV2 fetches all open projectsV2 for current user. |
| 287 | func CurrentUserProjectsV2(client *Client, hostname string) ([]ProjectV2, error) { |
| 288 | type responseData struct { |
| 289 | Viewer struct { |
| 290 | ProjectsV2 struct { |
| 291 | Nodes []ProjectV2 |
| 292 | PageInfo struct { |
| 293 | HasNextPage bool |
| 294 | EndCursor string |
| 295 | } |
| 296 | } `graphql:"projectsV2(first: 100, orderBy: {field: TITLE, direction: ASC}, after: $endCursor, query: $query)"` |
| 297 | } `graphql:"viewer"` |
| 298 | } |
| 299 | |
| 300 | variables := map[string]interface{}{ |
| 301 | "endCursor": (*githubv4.String)(nil), |
| 302 | "query": githubv4.String("is:open"), |
| 303 | } |
| 304 | |
| 305 | var projectsV2 []ProjectV2 |
| 306 | for { |
| 307 | var query responseData |
| 308 | err := client.Query(hostname, "UserProjectV2List", &query, variables) |
| 309 | if err != nil { |
| 310 | return nil, err |
| 311 | } |
| 312 | |
| 313 | projectsV2 = append(projectsV2, query.Viewer.ProjectsV2.Nodes...) |
| 314 | |
| 315 | if !query.Viewer.ProjectsV2.PageInfo.HasNextPage { |
| 316 | break |
| 317 | } |
| 318 | variables["endCursor"] = githubv4.String(query.Viewer.ProjectsV2.PageInfo.EndCursor) |
| 319 | } |
| 320 | |
| 321 | return projectsV2, nil |
| 322 | } |
| 323 | |
| 324 | // When querying ProjectsV2 fields we generally don't want to show the user |
| 325 | // scope errors, field does not exist errors, or authorization errors. |
no test coverage detected