@@ -586,6 +586,7 @@ func CreatePullRequest(client *Client, repo *Repository, params map[string]inter
586586 mutation CreatePullRequest($input: CreatePullRequestInput!) {
587587 createPullRequest(input: $input) {
588588 pullRequest {
589+ id
589590 url
590591 }
591592 }
@@ -595,7 +596,10 @@ func CreatePullRequest(client *Client, repo *Repository, params map[string]inter
595596 "repositoryId" : repo .ID ,
596597 }
597598 for key , val := range params {
598- inputParams [key ] = val
599+ switch key {
600+ case "title" , "body" , "draft" , "baseRefName" , "headRefName" :
601+ inputParams [key ] = val
602+ }
599603 }
600604 variables := map [string ]interface {}{
601605 "input" : inputParams ,
@@ -611,8 +615,70 @@ func CreatePullRequest(client *Client, repo *Repository, params map[string]inter
611615 if err != nil {
612616 return nil , err
613617 }
618+ pr := & result .CreatePullRequest .PullRequest
619+
620+ // metadata parameters aren't currently available in `createPullRequest`,
621+ // but they are in `updatePullRequest`
622+ updateParams := make (map [string ]interface {})
623+ for key , val := range params {
624+ switch key {
625+ case "assigneeIds" , "labelIds" , "projectIds" , "milestoneId" :
626+ if ! isBlank (val ) {
627+ updateParams [key ] = val
628+ }
629+ }
630+ }
631+ if len (updateParams ) > 0 {
632+ updateQuery := `
633+ mutation UpdatePullRequest($input: UpdatePullRequestInput!) {
634+ updatePullRequest(input: $input) { clientMutationId }
635+ }`
636+ updateParams ["pullRequestId" ] = pr .ID
637+ variables := map [string ]interface {}{
638+ "input" : updateParams ,
639+ }
640+ err := client .GraphQL (updateQuery , variables , & result )
641+ if err != nil {
642+ return nil , err
643+ }
644+ }
614645
615- return & result .CreatePullRequest .PullRequest , nil
646+ // reviewers are requested in yet another additional mutation
647+ reviewParams := make (map [string ]interface {})
648+ if ids , ok := params ["userReviewerIds" ]; ok && ! isBlank (ids ) {
649+ reviewParams ["userIds" ] = ids
650+ }
651+ if ids , ok := params ["teamReviewerIds" ]; ok && ! isBlank (ids ) {
652+ reviewParams ["teamIds" ] = ids
653+ }
654+
655+ if len (reviewParams ) > 0 {
656+ reviewQuery := `
657+ mutation RequestReviews($input: RequestReviewsInput!) {
658+ requestReviews(input: $input) { clientMutationId }
659+ }`
660+ reviewParams ["pullRequestId" ] = pr .ID
661+ variables := map [string ]interface {}{
662+ "input" : reviewParams ,
663+ }
664+ err := client .GraphQL (reviewQuery , variables , & result )
665+ if err != nil {
666+ return nil , err
667+ }
668+ }
669+
670+ return pr , nil
671+ }
672+
673+ func isBlank (v interface {}) bool {
674+ switch vv := v .(type ) {
675+ case string :
676+ return vv == ""
677+ case []string :
678+ return len (vv ) == 0
679+ default :
680+ return true
681+ }
616682}
617683
618684func AddReview (client * Client , pr * PullRequest , input * PullRequestReviewInput ) error {
0 commit comments