MCPcopy Create free account
hub / github.com/cli/cli / Projects

Method Projects

pkg/cmd/project/shared/queries/queries.go:1552–1635  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 3

NewProjectMethod · 0.95
runListFunction · 0.80

Calls 3

StringMethod · 0.65