github.com/cli/cli@v1.14.1-0.20210902173923-1af6a669e342/api/queries_pr_review.go (about) 1 package api 2 3 import ( 4 "context" 5 "time" 6 7 "github.com/cli/cli/internal/ghrepo" 8 "github.com/shurcooL/githubv4" 9 ) 10 11 type PullRequestReviewState int 12 13 const ( 14 ReviewApprove PullRequestReviewState = iota 15 ReviewRequestChanges 16 ReviewComment 17 ) 18 19 type PullRequestReviewInput struct { 20 Body string 21 State PullRequestReviewState 22 } 23 24 type PullRequestReviews struct { 25 Nodes []PullRequestReview 26 PageInfo struct { 27 HasNextPage bool 28 EndCursor string 29 } 30 TotalCount int 31 } 32 33 type PullRequestReview struct { 34 Author Author `json:"author"` 35 AuthorAssociation string `json:"authorAssociation"` 36 Body string `json:"body"` 37 SubmittedAt *time.Time `json:"submittedAt"` 38 IncludesCreatedEdit bool `json:"includesCreatedEdit"` 39 ReactionGroups ReactionGroups `json:"reactionGroups"` 40 State string `json:"state"` 41 URL string `json:"url,omitempty"` 42 } 43 44 func AddReview(client *Client, repo ghrepo.Interface, pr *PullRequest, input *PullRequestReviewInput) error { 45 var mutation struct { 46 AddPullRequestReview struct { 47 ClientMutationID string 48 } `graphql:"addPullRequestReview(input:$input)"` 49 } 50 51 state := githubv4.PullRequestReviewEventComment 52 switch input.State { 53 case ReviewApprove: 54 state = githubv4.PullRequestReviewEventApprove 55 case ReviewRequestChanges: 56 state = githubv4.PullRequestReviewEventRequestChanges 57 } 58 59 body := githubv4.String(input.Body) 60 variables := map[string]interface{}{ 61 "input": githubv4.AddPullRequestReviewInput{ 62 PullRequestID: pr.ID, 63 Event: &state, 64 Body: &body, 65 }, 66 } 67 68 gql := graphQLClient(client.http, repo.RepoHost()) 69 return gql.MutateNamed(context.Background(), "PullRequestReviewAdd", &mutation, variables) 70 } 71 72 func (prr PullRequestReview) AuthorLogin() string { 73 return prr.Author.Login 74 } 75 76 func (prr PullRequestReview) Association() string { 77 return prr.AuthorAssociation 78 } 79 80 func (prr PullRequestReview) Content() string { 81 return prr.Body 82 } 83 84 func (prr PullRequestReview) Created() time.Time { 85 if prr.SubmittedAt == nil { 86 return time.Time{} 87 } 88 return *prr.SubmittedAt 89 } 90 91 func (prr PullRequestReview) HiddenReason() string { 92 return "" 93 } 94 95 func (prr PullRequestReview) IsEdited() bool { 96 return prr.IncludesCreatedEdit 97 } 98 99 func (prr PullRequestReview) IsHidden() bool { 100 return false 101 } 102 103 func (prr PullRequestReview) Link() string { 104 return prr.URL 105 } 106 107 func (prr PullRequestReview) Reactions() ReactionGroups { 108 return prr.ReactionGroups 109 } 110 111 func (prr PullRequestReview) Status() string { 112 return prr.State 113 }