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

Function v2Projects

api/queries_repo.go:1558–1618  ·  view source on GitHub ↗

v2Projects retrieves set of ProjectV2 relevant to given repository: - ProjectsV2 owned by current user - ProjectsV2 linked to repository - ProjectsV2 owned by repository organization, if it belongs to one

(client *Client, repo ghrepo.Interface)

Source from the content-addressed store, hash-verified

1556// - ProjectsV2 linked to repository
1557// - ProjectsV2 owned by repository organization, if it belongs to one
1558func v2Projects(client *Client, repo ghrepo.Interface) ([]ProjectV2, error) {
1559 var userProjectsV2 []ProjectV2
1560 var repoProjectsV2 []ProjectV2
1561 var orgProjectsV2 []ProjectV2
1562
1563 g, _ := errgroup.WithContext(context.Background())
1564
1565 g.Go(func() error {
1566 var err error
1567 userProjectsV2, err = CurrentUserProjectsV2(client, repo.RepoHost())
1568 if err != nil && !ProjectsV2IgnorableError(err) {
1569 err = fmt.Errorf("error fetching user projects: %w", err)
1570 return err
1571 }
1572 return nil
1573 })
1574
1575 g.Go(func() error {
1576 var err error
1577 repoProjectsV2, err = RepoProjectsV2(client, repo)
1578 if err != nil && !ProjectsV2IgnorableError(err) {
1579 err = fmt.Errorf("error fetching repo projects: %w", err)
1580 return err
1581 }
1582 return nil
1583 })
1584
1585 g.Go(func() error {
1586 var err error
1587 orgProjectsV2, err = OrganizationProjectsV2(client, repo)
1588 if err != nil &&
1589 !ProjectsV2IgnorableError(err) &&
1590 !strings.Contains(err.Error(), errorResolvingOrganization) {
1591 err = fmt.Errorf("error fetching organization projects: %w", err)
1592 return err
1593 }
1594 return nil
1595 })
1596
1597 if err := g.Wait(); err != nil {
1598 return nil, err
1599 }
1600
1601 // ProjectV2 might appear across multiple queries so use a map to keep them deduplicated.
1602 m := make(map[string]ProjectV2, len(userProjectsV2)+len(repoProjectsV2)+len(orgProjectsV2))
1603 for _, p := range userProjectsV2 {
1604 m[p.ID] = p
1605 }
1606 for _, p := range repoProjectsV2 {
1607 m[p.ID] = p
1608 }
1609 for _, p := range orgProjectsV2 {
1610 m[p.ID] = p
1611 }
1612 projectsV2 := make([]ProjectV2, 0, len(m))
1613 for _, p := range m {
1614 projectsV2 = append(projectsV2, p)
1615 }

Callers 2

ProjectTitlesToPathsFunction · 0.85
RepoMetadataFunction · 0.85

Calls 9

CurrentUserProjectsV2Function · 0.85
ProjectsV2IgnorableErrorFunction · 0.85
RepoProjectsV2Function · 0.85
OrganizationProjectsV2Function · 0.85
ContainsMethod · 0.80
RepoHostMethod · 0.65
ErrorfMethod · 0.65
WaitMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected