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

Method Create

pkg/cmd/codespace/create.go:128–351  ·  view source on GitHub ↗

Create creates a new Codespace

(ctx context.Context, opts createOptions)

Source from the content-addressed store, hash-verified

126
127// Create creates a new Codespace
128func (a *App) Create(ctx context.Context, opts createOptions) error {
129 // Overrides for Codespace developers to target test environments
130 vscsLocation := os.Getenv("VSCS_LOCATION")
131 vscsTarget := os.Getenv("VSCS_TARGET")
132 vscsTargetUrl := os.Getenv("VSCS_TARGET_URL")
133
134 userInputs := struct {
135 Repository string
136 Branch string
137 Location string
138 }{
139 Repository: opts.repo,
140 Branch: opts.branch,
141 Location: opts.location,
142 }
143
144 if opts.useWeb && userInputs.Repository == "" {
145 return a.browser.Browse(fmt.Sprintf("%s/codespaces/new", a.apiClient.ServerURL()))
146 }
147
148 prompter := &Prompter{}
149 promptForRepoAndBranch := userInputs.Repository == "" && !opts.useWeb
150 if promptForRepoAndBranch {
151 var defaultRepo string
152 if remotes, _ := a.remotes(); remotes != nil {
153 if defaultRemote, _ := remotes.ResolvedRemote(); defaultRemote != nil {
154 // this is a remote explicitly chosen via `repo set-default`
155 defaultRepo = ghrepo.FullName(defaultRemote)
156 } else if len(remotes) > 0 {
157 // as a fallback, just pick the first remote
158 defaultRepo = ghrepo.FullName(remotes[0])
159 }
160 }
161
162 repoQuestions := []*survey.Question{
163 {
164 Name: "repository",
165 Prompt: &survey.Input{
166 Message: "Repository:",
167 Help: "Search for repos by name. To search within an org or user, or to see private repos, enter at least ':user/'.",
168 Default: defaultRepo,
169 Suggest: func(toComplete string) []string {
170 return getRepoSuggestions(ctx, a.apiClient, toComplete)
171 },
172 },
173 Validate: survey.Required,
174 },
175 }
176 if err := prompter.Ask(repoQuestions, &userInputs); err != nil {
177 return fmt.Errorf("failed to prompt: %w", err)
178 }
179 }
180
181 if userInputs.Location == "" && vscsLocation != "" {
182 userInputs.Location = vscsLocation
183 }
184
185 var repository *api.Repository

Callers 1

TestApp_CreateFunction · 0.95

Calls 15

AskMethod · 0.95
RunWithProgressMethod · 0.95
showStatusMethod · 0.95
FullNameFunction · 0.92
getRepoSuggestionsFunction · 0.85
stringInSliceFunction · 0.85
getMachineNameFunction · 0.85
ResolvedRemoteMethod · 0.80
ColorSchemeMethod · 0.80
BlueMethod · 0.80
MinutesMethod · 0.80

Tested by 1

TestApp_CreateFunction · 0.76