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

Function createRun

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

Source from the content-addressed store, hash-verified

425}
426
427func createRun(opts *CreateOptions) error {
428 ctx, err := NewCreateContext(opts)
429 if err != nil {
430 return err
431 }
432
433 if isSameRef(ctx.PRRefs) {
434 return fmt.Errorf("head branch %q is the same as base branch %q, cannot create a pull request", ctx.PRRefs.UnqualifiedHeadRef(), ctx.PRRefs.BaseRef())
435 }
436
437 httpClient, err := opts.HttpClient()
438 if err != nil {
439 return err
440 }
441
442 // TODO projectsV1Deprecation
443 // Remove this section as we should no longer need to detect
444 if opts.Detector == nil {
445 cachedClient := api.NewCachedHTTPClient(httpClient, time.Hour*24)
446 opts.Detector = fd.NewDetector(cachedClient, ctx.PRRefs.BaseRepo().RepoHost())
447 }
448
449 projectsV1Support := opts.Detector.ProjectsV1()
450
451 client := ctx.Client
452
453 // Detect ApiActorsSupported feature to determine if we can use search-based
454 // reviewer selection (github.com) or need to use legacy ID-based selection (GHES)
455 issueFeatures, err := opts.Detector.IssueFeatures()
456 if err != nil {
457 return err
458 }
459 var reviewerSearchFunc func(string) prompter.MultiSelectSearchResult
460 var assigneeSearchFunc func(string) prompter.MultiSelectSearchResult
461 if issueFeatures.ApiActorsSupported {
462 reviewerSearchFunc = func(query string) prompter.MultiSelectSearchResult {
463 candidates, moreResults, err := api.SuggestedReviewerActorsForRepo(client, ctx.PRRefs.BaseRepo(), query)
464 if err != nil {
465 return prompter.MultiSelectSearchResult{Err: err}
466 }
467 keys := make([]string, len(candidates))
468 labels := make([]string, len(candidates))
469 for i, c := range candidates {
470 keys[i] = c.Login()
471 labels[i] = c.DisplayName()
472 }
473 return prompter.MultiSelectSearchResult{Keys: keys, Labels: labels, MoreResults: moreResults}
474 }
475 assigneeSearchFunc = shared.RepoAssigneeSearchFunc(client, ctx.PRRefs.BaseRepo())
476 }
477
478 state, err := NewIssueState(*ctx, *opts, issueFeatures.ApiActorsSupported)
479 if err != nil {
480 return err
481 }
482
483 // TODO ApiActorsSupported
484 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
NewUploaderFunction · 0.92
FullNameFunction · 0.92
FillFromJSONFunction · 0.92
NewTemplateManagerFunction · 0.92
TitleSurveyFunction · 0.92
PreserveInputFunction · 0.92

Tested by 5

Test_createRunFunction · 0.56
Test_createRun_GHESFunction · 0.56
TestRemoteGuessingFunction · 0.56