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

Function forkRun

pkg/cmd/repo/fork/fork.go:160–403  ·  view source on GitHub ↗
(opts *ForkOptions)

Source from the content-addressed store, hash-verified

158}
159
160func forkRun(opts *ForkOptions) error {
161 var repoToFork ghrepo.Interface
162 var err error
163 inParent := false // whether or not we're forking the repo we're currently "in"
164 if opts.Repository == "" {
165 baseRepo, err := opts.BaseRepo()
166 if err != nil {
167 return fmt.Errorf("unable to determine base repository: %w", err)
168 }
169 inParent = true
170 repoToFork = baseRepo
171 } else {
172 repoArg := opts.Repository
173
174 if isURL(repoArg) {
175 parsedURL, err := url.Parse(repoArg)
176 if err != nil {
177 return fmt.Errorf("did not understand argument: %w", err)
178 }
179
180 repoToFork, err = ghrepo.FromURL(parsedURL)
181 if err != nil {
182 return fmt.Errorf("did not understand argument: %w", err)
183 }
184
185 } else if strings.HasPrefix(repoArg, "git@") {
186 parsedURL, err := git.ParseURL(repoArg)
187 if err != nil {
188 return fmt.Errorf("did not understand argument: %w", err)
189 }
190 repoToFork, err = ghrepo.FromURL(parsedURL)
191 if err != nil {
192 return fmt.Errorf("did not understand argument: %w", err)
193 }
194 } else {
195 repoToFork, err = ghrepo.FromFullName(repoArg)
196 if err != nil {
197 return fmt.Errorf("argument error: %w", err)
198 }
199 }
200 }
201
202 connectedToTerminal := opts.IO.IsStdoutTTY() && opts.IO.IsStderrTTY() && opts.IO.IsStdinTTY()
203
204 cs := opts.IO.ColorScheme()
205 stderr := opts.IO.ErrOut
206
207 httpClient, err := opts.HttpClient()
208 if err != nil {
209 return fmt.Errorf("unable to create client: %w", err)
210 }
211
212 apiClient := api.NewClientFromHTTP(httpClient)
213
214 opts.IO.StartProgressIndicator()
215 forkedRepo, err := api.ForkRepo(apiClient, repoToFork, opts.Organization, opts.ForkName, opts.DefaultBranchOnly)
216 opts.IO.StopProgressIndicator()
217 if err != nil {

Callers 2

TestRepoForkFunction · 0.85
NewCmdForkFunction · 0.85

Calls 15

RepoNameMethod · 0.95
RepoHostMethod · 0.95
RepoOwnerMethod · 0.95
ExitCodeMethod · 0.95
FromURLFunction · 0.92
ParseURLFunction · 0.92
FromFullNameFunction · 0.92
NewClientFromHTTPFunction · 0.92
ForkRepoFunction · 0.92
FullNameFunction · 0.92
GenerateRepoURLFunction · 0.92
NormalizeRepoNameFunction · 0.92

Tested by 1

TestRepoForkFunction · 0.68