userOrgLogins gets all the logins of the viewer and the organizations the viewer is a member of.
()
| 1366 | |
| 1367 | // userOrgLogins gets all the logins of the viewer and the organizations the viewer is a member of. |
| 1368 | func (c *Client) userOrgLogins() ([]loginTypes, error) { |
| 1369 | l := make([]loginTypes, 0) |
| 1370 | var v viewerLoginOrgs |
| 1371 | variables := map[string]interface{}{ |
| 1372 | "after": (*githubv4.String)(nil), |
| 1373 | } |
| 1374 | |
| 1375 | err := c.doQueryWithProgressIndicator("ViewerLoginAndOrgs", &v, variables) |
| 1376 | if err != nil { |
| 1377 | return l, err |
| 1378 | } |
| 1379 | |
| 1380 | // add the user |
| 1381 | l = append(l, loginTypes{ |
| 1382 | Login: v.Viewer.Login, |
| 1383 | Type: ViewerOwner, |
| 1384 | ID: v.Viewer.ID, |
| 1385 | }) |
| 1386 | |
| 1387 | // add orgs where the user can create projects |
| 1388 | for _, org := range v.Viewer.Organizations.Nodes { |
| 1389 | if org.ViewerCanCreateProjects { |
| 1390 | l = append(l, loginTypes{ |
| 1391 | Login: org.Login, |
| 1392 | Type: OrgOwner, |
| 1393 | ID: org.ID, |
| 1394 | }) |
| 1395 | } |
| 1396 | } |
| 1397 | |
| 1398 | // this seem unlikely, but if there are more org logins, paginate the rest |
| 1399 | if v.Viewer.Organizations.PageInfo.HasNextPage { |
| 1400 | return c.paginateOrgLogins(l, string(v.Viewer.Organizations.PageInfo.EndCursor)) |
| 1401 | } |
| 1402 | |
| 1403 | return l, nil |
| 1404 | } |
| 1405 | |
| 1406 | // paginateOrgLogins after cursor and append them to the list of logins. |
| 1407 | func (c *Client) paginateOrgLogins(l []loginTypes, cursor string) ([]loginTypes, error) { |
no test coverage detected