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

Function ProjectTitlesToPaths

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

Source from the content-addressed store, hash-verified

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

Callers 2

Test_ProjectNamesToPathsFunction · 0.85

Calls 3

v1ProjectsFunction · 0.85
v2ProjectsFunction · 0.85
ErrorfMethod · 0.65

Tested by 1

Test_ProjectNamesToPathsFunction · 0.68