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

Method Create

pkg/cmd/codespace/create.go:129–352  ·  view source on GitHub ↗

Create creates a new Codespace

(ctx context.Context, opts createOptions)

Source from the content-addressed store, hash-verified

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

Tested by 1

TestApp_CreateFunction · 0.76