MCPcopy
hub / github.com/cli/cli / forkRun

Function forkRun

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

Source from the content-addressed store, hash-verified

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