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

Function createRun

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

Source from the content-addressed store, hash-verified

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