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

Function createRun

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

Source from the content-addressed store, hash-verified

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