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