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