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