OrganizationTeams fetches all the teams in an organization
(client *Client, repo ghrepo.Interface)
| 75 | |
| 76 | // OrganizationTeams fetches all the teams in an organization |
| 77 | func OrganizationTeams(client *Client, repo ghrepo.Interface) ([]OrgTeam, error) { |
| 78 | type responseData struct { |
| 79 | Organization struct { |
| 80 | Teams struct { |
| 81 | Nodes []OrgTeam |
| 82 | PageInfo struct { |
| 83 | HasNextPage bool |
| 84 | EndCursor string |
| 85 | } |
| 86 | } `graphql:"teams(first: 100, orderBy: {field: NAME, direction: ASC}, after: $endCursor)"` |
| 87 | } `graphql:"organization(login: $owner)"` |
| 88 | } |
| 89 | |
| 90 | variables := map[string]interface{}{ |
| 91 | "owner": githubv4.String(repo.RepoOwner()), |
| 92 | "endCursor": (*githubv4.String)(nil), |
| 93 | } |
| 94 | |
| 95 | var teams []OrgTeam |
| 96 | for { |
| 97 | var query responseData |
| 98 | err := client.Query(repo.RepoHost(), "OrganizationTeamList", &query, variables) |
| 99 | if err != nil { |
| 100 | return nil, err |
| 101 | } |
| 102 | |
| 103 | teams = append(teams, query.Organization.Teams.Nodes...) |
| 104 | if !query.Organization.Teams.PageInfo.HasNextPage { |
| 105 | break |
| 106 | } |
| 107 | variables["endCursor"] = githubv4.String(query.Organization.Teams.PageInfo.EndCursor) |
| 108 | } |
| 109 | |
| 110 | return teams, nil |
| 111 | } |
no test coverage detected