OrganizationProjects fetches all open projects for an organization.
(client *Client, repo ghrepo.Interface)
| 8 | |
| 9 | // OrganizationProjects fetches all open projects for an organization. |
| 10 | func OrganizationProjects(client *Client, repo ghrepo.Interface) ([]RepoProject, error) { |
| 11 | type responseData struct { |
| 12 | Organization struct { |
| 13 | Projects struct { |
| 14 | Nodes []RepoProject |
| 15 | PageInfo struct { |
| 16 | HasNextPage bool |
| 17 | EndCursor string |
| 18 | } |
| 19 | } `graphql:"projects(states: [OPEN], first: 100, orderBy: {field: NAME, direction: ASC}, after: $endCursor)"` |
| 20 | } `graphql:"organization(login: $owner)"` |
| 21 | } |
| 22 | |
| 23 | variables := map[string]interface{}{ |
| 24 | "owner": githubv4.String(repo.RepoOwner()), |
| 25 | "endCursor": (*githubv4.String)(nil), |
| 26 | } |
| 27 | |
| 28 | var projects []RepoProject |
| 29 | for { |
| 30 | var query responseData |
| 31 | err := client.Query(repo.RepoHost(), "OrganizationProjectList", &query, variables) |
| 32 | if err != nil { |
| 33 | return nil, err |
| 34 | } |
| 35 | |
| 36 | projects = append(projects, query.Organization.Projects.Nodes...) |
| 37 | if !query.Organization.Projects.PageInfo.HasNextPage { |
| 38 | break |
| 39 | } |
| 40 | variables["endCursor"] = githubv4.String(query.Organization.Projects.PageInfo.EndCursor) |
| 41 | } |
| 42 | |
| 43 | return projects, nil |
| 44 | } |
| 45 | |
| 46 | type OrgTeam struct { |
| 47 | ID string |
no test coverage detected