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

Function ProjectTitlesToPaths

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

Source from the content-addressed store, hash-verified

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

Callers 2

Test_ProjectNamesToPathsFunction · 0.85

Calls 3

v1ProjectsFunction · 0.85
v2ProjectsFunction · 0.85
ErrorfMethod · 0.65

Tested by 1

Test_ProjectNamesToPathsFunction · 0.68