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

Function forkRun

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

Source from the content-addressed store, hash-verified

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