MCPcopy
hub / github.com/cli/cli / createRun

Function createRun

pkg/cmd/pr/create/create.go:376–641  ·  view source on GitHub ↗
(opts *CreateOptions)

Source from the content-addressed store, hash-verified

374}
375
376func createRun(opts *CreateOptions) error {
377 ctx, err := NewCreateContext(opts)
378 if err != nil {
379 return err
380 }
381
382 if isSameRef(ctx.PRRefs) {
383 return fmt.Errorf("head branch %q is the same as base branch %q, cannot create a pull request", ctx.PRRefs.UnqualifiedHeadRef(), ctx.PRRefs.BaseRef())
384 }
385
386 httpClient, err := opts.HttpClient()
387 if err != nil {
388 return err
389 }
390
391 // TODO projectsV1Deprecation
392 // Remove this section as we should no longer need to detect
393 if opts.Detector == nil {
394 cachedClient := api.NewCachedHTTPClient(httpClient, time.Hour*24)
395 opts.Detector = fd.NewDetector(cachedClient, ctx.PRRefs.BaseRepo().RepoHost())
396 }
397
398 projectsV1Support := opts.Detector.ProjectsV1()
399
400 client := ctx.Client
401
402 // Detect ApiActorsSupported feature to determine if we can use search-based
403 // reviewer selection (github.com) or need to use legacy ID-based selection (GHES)
404 issueFeatures, err := opts.Detector.IssueFeatures()
405 if err != nil {
406 return err
407 }
408 var reviewerSearchFunc func(string) prompter.MultiSelectSearchResult
409 var assigneeSearchFunc func(string) prompter.MultiSelectSearchResult
410 if issueFeatures.ApiActorsSupported {
411 reviewerSearchFunc = func(query string) prompter.MultiSelectSearchResult {
412 candidates, moreResults, err := api.SuggestedReviewerActorsForRepo(client, ctx.PRRefs.BaseRepo(), query)
413 if err != nil {
414 return prompter.MultiSelectSearchResult{Err: err}
415 }
416 keys := make([]string, len(candidates))
417 labels := make([]string, len(candidates))
418 for i, c := range candidates {
419 keys[i] = c.Login()
420 labels[i] = c.DisplayName()
421 }
422 return prompter.MultiSelectSearchResult{Keys: keys, Labels: labels, MoreResults: moreResults}
423 }
424 assigneeSearchFunc = shared.RepoAssigneeSearchFunc(client, ctx.PRRefs.BaseRepo())
425 }
426
427 state, err := NewIssueState(*ctx, *opts, issueFeatures.ApiActorsSupported)
428 if err != nil {
429 return err
430 }
431
432 // TODO ApiActorsSupported
433 if issueFeatures.ApiActorsSupported {

Callers 6

Test_createRunFunction · 0.70
Test_createRun_GHESFunction · 0.70
TestRemoteGuessingFunction · 0.70
NewCmdCreateFunction · 0.70

Calls 15

TitleMethod · 0.95
BodyMethod · 0.95
NewCachedHTTPClientFunction · 0.92
RepoAssigneeSearchFuncFunction · 0.92
ValidURLFunction · 0.92
FullNameFunction · 0.92
FillFromJSONFunction · 0.92
NewTemplateManagerFunction · 0.92
TitleSurveyFunction · 0.92
PreserveInputFunction · 0.92
BodySurveyFunction · 0.92

Tested by 5

Test_createRunFunction · 0.56
Test_createRun_GHESFunction · 0.56
TestRemoteGuessingFunction · 0.56