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

Method Projects

pkg/cmd/project/shared/queries/queries.go:1545–1625  ·  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

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

Callers 3

NewProjectMethod · 0.95
runListFunction · 0.80

Calls 3

StringMethod · 0.65