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

Function ProjectTitlesToPaths

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

Source from the content-addressed store, hash-verified

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

Callers 2

Test_ProjectNamesToPathsFunction · 0.85

Calls 3

v1ProjectsFunction · 0.85
v2ProjectsFunction · 0.85
ErrorfMethod · 0.65

Tested by 1

Test_ProjectNamesToPathsFunction · 0.68