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

Function interactiveRepoNameAndOwner

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

Source from the content-addressed store, hash-verified

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