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

Function createRun

pkg/cmd/pr/create/create.go:427–702  ·  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 opts.Detector = fd.NewCachedDetector(httpClient, ctx.PRRefs.BaseRepo().RepoHost(), time.Hour*24)
446 }
447
448 projectsV1Support := opts.Detector.ProjectsV1()
449
450 client := ctx.Client
451
452 // Detect ApiActorsSupported feature to determine if we can use search-based
453 // reviewer selection (github.com) or need to use legacy ID-based selection (GHES)
454 issueFeatures, err := opts.Detector.IssueFeatures()
455 if err != nil {
456 return err
457 }
458 var reviewerSearchFunc func(string) prompter.MultiSelectSearchResult
459 var assigneeSearchFunc func(string) prompter.MultiSelectSearchResult
460 if issueFeatures.ApiActorsSupported {
461 reviewerSearchFunc = func(query string) prompter.MultiSelectSearchResult {
462 candidates, moreResults, err := api.SuggestedReviewerActorsForRepo(client, ctx.PRRefs.BaseRepo(), query)
463 if err != nil {
464 return prompter.MultiSelectSearchResult{Err: err}
465 }
466 keys := make([]string, len(candidates))
467 labels := make([]string, len(candidates))
468 for i, c := range candidates {
469 keys[i] = c.Login()
470 labels[i] = c.DisplayName()
471 }
472 return prompter.MultiSelectSearchResult{Keys: keys, Labels: labels, MoreResults: moreResults}
473 }
474 assigneeSearchFunc = shared.RepoAssigneeSearchFunc(client, ctx.PRRefs.BaseRepo())
475 }
476
477 state, err := NewIssueState(*ctx, *opts, issueFeatures.ApiActorsSupported)
478 if err != nil {
479 return err
480 }
481
482 // TODO ApiActorsSupported
483 if issueFeatures.ApiActorsSupported {
484 state.ApiActorsSupported = true

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
RepoAssigneeSearchFuncFunction · 0.92
ValidURLFunction · 0.92
NewUploaderFunction · 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