MCPcopy Index your code
hub / github.com/cli/cli / CreatePullRequest

Function CreatePullRequest

api/queries_pr.go:465–590  ·  view source on GitHub ↗

CreatePullRequest creates a pull request in a GitHub repository

(client *Client, repo *Repository, params map[string]interface{})

Source from the content-addressed store, hash-verified

463
464// CreatePullRequest creates a pull request in a GitHub repository
465func CreatePullRequest(client *Client, repo *Repository, params map[string]interface{}) (*PullRequest, error) {
466 query := `
467 mutation PullRequestCreate($input: CreatePullRequestInput!) {
468 createPullRequest(input: $input) {
469 pullRequest {
470 id
471 url
472 }
473 }
474 }`
475
476 inputParams := map[string]interface{}{
477 "repositoryId": repo.ID,
478 }
479 for key, val := range params {
480 switch key {
481 case "title", "body", "draft", "baseRefName", "headRefName", "maintainerCanModify":
482 inputParams[key] = val
483 }
484 }
485 variables := map[string]interface{}{
486 "input": inputParams,
487 }
488
489 result := struct {
490 CreatePullRequest struct {
491 PullRequest PullRequest
492 }
493 }{}
494
495 err := client.GraphQL(repo.RepoHost(), query, variables, &result)
496 if err != nil {
497 return nil, err
498 }
499 pr := &result.CreatePullRequest.PullRequest
500
501 // metadata parameters aren't currently available in `createPullRequest`,
502 // but they are in `updatePullRequest`
503 updateParams := make(map[string]interface{})
504 for key, val := range params {
505 switch key {
506 case "assigneeIds", "labelIds", "projectIds", "milestoneId":
507 if !isBlank(val) {
508 updateParams[key] = val
509 }
510 }
511 }
512 if len(updateParams) > 0 {
513 updateQuery := `
514 mutation PullRequestCreateMetadata($input: UpdatePullRequestInput!) {
515 updatePullRequest(input: $input) { clientMutationId }
516 }`
517 updateParams["pullRequestId"] = pr.ID
518 variables := map[string]interface{}{
519 "input": updateParams,
520 }
521 err := client.GraphQL(repo.RepoHost(), updateQuery, variables, &result)
522 if err != nil {

Callers 1

submitPRFunction · 0.92

Calls 6

isBlankFunction · 0.85
RequestReviewsByLoginFunction · 0.85
UpdateProjectV2ItemsFunction · 0.85
GraphQLMethod · 0.80
RepoHostMethod · 0.65

Tested by

no test coverage detected