MCPcopy
hub / github.com/cli/cli / interactiveRepoNameAndOwner

Function interactiveRepoNameAndOwner

pkg/cmd/repo/create/create.go:928–966  ·  view source on GitHub ↗
(client *http.Client, hostname string, prompter iprompter, defaultName string)

Source from the content-addressed store, hash-verified

926}
927
928func interactiveRepoNameAndOwner(client *http.Client, hostname string, prompter iprompter, defaultName string) (string, string, error) {
929 name, err := prompter.Input("Repository name", defaultName)
930 if err != nil {
931 return "", "", err
932 }
933
934 name, owner, err := splitNameAndOwner(name)
935 if err != nil {
936 return "", "", err
937 }
938 if owner != "" {
939 // User supplied an explicit owner prefix.
940 return name, owner, nil
941 }
942
943 username, orgs, err := userAndOrgs(client, hostname)
944 if err != nil {
945 return "", "", err
946 }
947 if len(orgs) == 0 {
948 // User doesn't belong to any orgs.
949 // Leave the owner blank to indicate a personal repo.
950 return name, "", nil
951 }
952
953 owners := append(orgs, username)
954 sort.Strings(owners)
955 selected, err := prompter.Select("Repository owner", username, owners)
956 if err != nil {
957 return "", "", err
958 }
959
960 owner = owners[selected]
961 if owner == username {
962 // Leave the owner blank to indicate a personal repo.
963 return name, "", nil
964 }
965 return name, owner, nil
966}
967
968func splitNameAndOwner(name string) (string, string, error) {
969 if !strings.Contains(name, "/") {

Callers 1

interactiveRepoInfoFunction · 0.85

Calls 4

splitNameAndOwnerFunction · 0.85
userAndOrgsFunction · 0.85
InputMethod · 0.65
SelectMethod · 0.65

Tested by

no test coverage detected