github.com/ungtb10d/cli/v2@v2.0.0-20221110210412-98537dd9d6a1/api/queries_pr_review.go (about) 1 package api 2 3 import ( 4 "time" 5 6 "github.com/ungtb10d/cli/v2/internal/ghrepo" 7 "github.com/shurcooL/githubv4" 8 ) 9 10 type PullRequestReviewState int 11 12 const ( 13 ReviewApprove PullRequestReviewState = iota 14 ReviewRequestChanges 15 ReviewComment 16 ) 17 18 type PullRequestReviewInput struct { 19 Body string 20 State PullRequestReviewState 21 } 22 23 type PullRequestReviews struct { 24 Nodes []PullRequestReview 25 PageInfo struct { 26 HasNextPage bool 27 EndCursor string 28 } 29 TotalCount int 30 } 31 32 type PullRequestReview struct { 33 ID string `json:"id"` 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 return client.Mutate(repo.RepoHost(), "PullRequestReviewAdd", &mutation, variables) 69 } 70 71 func (prr PullRequestReview) Identifier() string { 72 return prr.ID 73 } 74 75 func (prr PullRequestReview) AuthorLogin() string { 76 return prr.Author.Login 77 } 78 79 func (prr PullRequestReview) Association() string { 80 return prr.AuthorAssociation 81 } 82 83 func (prr PullRequestReview) Content() string { 84 return prr.Body 85 } 86 87 func (prr PullRequestReview) Created() time.Time { 88 if prr.SubmittedAt == nil { 89 return time.Time{} 90 } 91 return *prr.SubmittedAt 92 } 93 94 func (prr PullRequestReview) HiddenReason() string { 95 return "" 96 } 97 98 func (prr PullRequestReview) IsEdited() bool { 99 return prr.IncludesCreatedEdit 100 } 101 102 func (prr PullRequestReview) IsHidden() bool { 103 return false 104 } 105 106 func (prr PullRequestReview) Link() string { 107 return prr.URL 108 } 109 110 func (prr PullRequestReview) Reactions() ReactionGroups { 111 return prr.ReactionGroups 112 } 113 114 func (prr PullRequestReview) Status() string { 115 return prr.State 116 }