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

Function createRun

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

Source from the content-addressed store, hash-verified

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