MCPcopy
hub / github.com/cli/cli / listOrgs

Function listOrgs

pkg/cmd/org/list/http.go:19–91  ·  view source on GitHub ↗
(httpClient *http.Client, hostname string, limit int)

Source from the content-addressed store, hash-verified

17}
18
19func listOrgs(httpClient *http.Client, hostname string, limit int) (*OrganizationList, error) {
20 type response struct {
21 User struct {
22 Login string
23 Organizations struct {
24 TotalCount int
25 Nodes []Organization
26 PageInfo struct {
27 HasNextPage bool
28 EndCursor string
29 }
30 } `graphql:"organizations(first: $limit, after: $endCursor)"`
31 }
32 }
33
34 query := `query OrganizationList($user: String!, $limit: Int!, $endCursor: String) {
35 user(login: $user) {
36 login
37 organizations(first: $limit, after: $endCursor) {
38 totalCount
39 nodes {
40 login
41 }
42 pageInfo {
43 hasNextPage
44 endCursor
45 }
46 }
47 }
48 }`
49
50 client := api.NewClientFromHTTP(httpClient)
51
52 user, err := api.CurrentLoginName(client, hostname)
53 if err != nil {
54 return nil, err
55 }
56
57 listResult := OrganizationList{}
58 listResult.User = user
59 pageLimit := min(limit, 100)
60 variables := map[string]interface{}{
61 "user": user,
62 }
63
64loop:
65 for {
66 variables["limit"] = pageLimit
67 var data response
68 err := client.GraphQL(hostname, query, variables, &data)
69 if err != nil {
70 return nil, err
71 }
72
73 listResult.TotalCount = data.User.Organizations.TotalCount
74
75 for _, org := range data.User.Organizations.Nodes {
76 listResult.Organizations = append(listResult.Organizations, org)

Callers 2

listRunFunction · 0.85
Test_listOrgsFunction · 0.85

Calls 4

NewClientFromHTTPFunction · 0.92
CurrentLoginNameFunction · 0.92
GraphQLMethod · 0.80
minFunction · 0.70

Tested by 1

Test_listOrgsFunction · 0.68