MCPcopy
hub / github.com/cli/cli / ProjectTitlesToPaths

Function ProjectTitlesToPaths

api/queries_repo.go:867–932  ·  view source on GitHub ↗
(client *Client, repo ghrepo.Interface, titles []string, projectsV1Support gh.ProjectsV1Support)

Source from the content-addressed store, hash-verified

865}
866
867func ProjectTitlesToPaths(client *Client, repo ghrepo.Interface, titles []string, projectsV1Support gh.ProjectsV1Support) ([]string, error) {
868 paths := make([]string, 0, len(titles))
869 matchedPaths := map[string]struct{}{}
870
871 // TODO: ProjectsV1Cleanup
872 // At this point, we only know the names that the user has provided, so we can't push this conditional up the stack.
873 // First we'll try to match against v1 projects, if supported
874 if projectsV1Support == gh.ProjectsV1Supported {
875 v1Projects, err := v1Projects(client, repo)
876 if err != nil {
877 return nil, err
878 }
879
880 for _, title := range titles {
881 for _, p := range v1Projects {
882 if strings.EqualFold(title, p.Name) {
883 pathParts := strings.Split(p.ResourcePath, "/")
884 var path string
885 if pathParts[1] == "orgs" || pathParts[1] == "users" {
886 path = fmt.Sprintf("%s/%s", pathParts[2], pathParts[4])
887 } else {
888 path = fmt.Sprintf("%s/%s/%s", pathParts[1], pathParts[2], pathParts[4])
889 }
890 paths = append(paths, path)
891 matchedPaths[title] = struct{}{}
892 break
893 }
894 }
895 }
896 }
897
898 // Then we'll try to match against v2 projects
899 v2Projects, err := v2Projects(client, repo)
900 if err != nil {
901 return nil, err
902 }
903
904 for _, title := range titles {
905 // If we already found a v1 project with this name, skip it
906 if _, ok := matchedPaths[title]; ok {
907 continue
908 }
909
910 found := false
911 for _, p := range v2Projects {
912 if strings.EqualFold(title, p.Title) {
913 pathParts := strings.Split(p.ResourcePath, "/")
914 var path string
915 if pathParts[1] == "orgs" || pathParts[1] == "users" {
916 path = fmt.Sprintf("%s/%s", pathParts[2], pathParts[4])
917 } else {
918 path = fmt.Sprintf("%s/%s/%s", pathParts[1], pathParts[2], pathParts[4])
919 }
920 paths = append(paths, path)
921 found = true
922 break
923 }
924 }

Callers 2

Test_ProjectNamesToPathsFunction · 0.85

Calls 3

v1ProjectsFunction · 0.85
v2ProjectsFunction · 0.85
ErrorfMethod · 0.65

Tested by 1

Test_ProjectNamesToPathsFunction · 0.68