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

Function v2Projects

api/queries_repo.go:1554–1614  ·  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

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

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