Projects returns all the projects for an Owner. If the OwnerType is VIEWER, no login is required. If limit is 0, the default limit is used.
(login string, t OwnerType, limit int, fields bool)
| 1544 | // Projects returns all the projects for an Owner. If the OwnerType is VIEWER, no login is required. |
| 1545 | // If limit is 0, the default limit is used. |
| 1546 | func (c *Client) Projects(login string, t OwnerType, limit int, fields bool) (Projects, error) { |
| 1547 | projects := Projects{ |
| 1548 | Nodes: make([]Project, 0), |
| 1549 | } |
| 1550 | cursor := (*githubv4.String)(nil) |
| 1551 | hasNextPage := false |
| 1552 | |
| 1553 | if limit == 0 { |
| 1554 | limit = LimitDefault |
| 1555 | } |
| 1556 | |
| 1557 | // set first to the min of limit and LimitMax |
| 1558 | first := min(limit, LimitMax) |
| 1559 | |
| 1560 | variables := map[string]any{ |
| 1561 | "first": githubv4.Int(first), |
| 1562 | "after": cursor, |
| 1563 | "firstItems": githubv4.Int(0), |
| 1564 | "afterItems": (*githubv4.String)(nil), |
| 1565 | "firstFields": githubv4.Int(0), |
| 1566 | "afterFields": (*githubv4.String)(nil), |
| 1567 | } |
| 1568 | |
| 1569 | if fields { |
| 1570 | variables["firstFields"] = githubv4.Int(LimitMax) |
| 1571 | } |
| 1572 | |
| 1573 | if t != ViewerOwner { |
| 1574 | variables["login"] = githubv4.String(login) |
| 1575 | } |
| 1576 | // loop until we get all the projects |
| 1577 | for { |
| 1578 | // the code below is very repetitive, the only real difference being the type of the query |
| 1579 | // and the query variables. I couldn't figure out a way to make this cleaner that was worth |
| 1580 | // the cost. |
| 1581 | if t == UserOwner { |
| 1582 | var query userProjects |
| 1583 | if err := c.doQueryWithProgressIndicator("UserProjects", &query, variables); err != nil { |
| 1584 | return projects, err |
| 1585 | } |
| 1586 | for _, p := range query.Owner.Projects.Nodes { |
| 1587 | projects.Nodes = append(projects.Nodes, *newProjectFromQueryWithoutItemsQuery(p)) |
| 1588 | } |
| 1589 | hasNextPage = query.Owner.Projects.PageInfo.HasNextPage |
| 1590 | cursor = &query.Owner.Projects.PageInfo.EndCursor |
| 1591 | projects.TotalCount = query.Owner.Projects.TotalCount |
| 1592 | } else if t == OrgOwner { |
| 1593 | var query orgProjects |
| 1594 | if err := c.doQueryWithProgressIndicator("OrgProjects", &query, variables); err != nil { |
| 1595 | return projects, err |
| 1596 | } |
| 1597 | for _, p := range query.Owner.Projects.Nodes { |
| 1598 | projects.Nodes = append(projects.Nodes, *newProjectFromQueryWithoutItemsQuery(p)) |
| 1599 | } |
| 1600 | hasNextPage = query.Owner.Projects.PageInfo.HasNextPage |
| 1601 | cursor = &query.Owner.Projects.PageInfo.EndCursor |
| 1602 | projects.TotalCount = query.Owner.Projects.TotalCount |
| 1603 | } else if t == ViewerOwner { |