github.com/cli/cli@v1.14.1-0.20210902173923-1af6a669e342/api/queries_comments.go (about) 1 package api 2 3 import ( 4 "context" 5 "time" 6 7 "github.com/shurcooL/githubv4" 8 "github.com/shurcooL/graphql" 9 ) 10 11 type Comments struct { 12 Nodes []Comment 13 TotalCount int 14 PageInfo struct { 15 HasNextPage bool 16 EndCursor string 17 } 18 } 19 20 type Comment struct { 21 Author Author `json:"author"` 22 AuthorAssociation string `json:"authorAssociation"` 23 Body string `json:"body"` 24 CreatedAt time.Time `json:"createdAt"` 25 IncludesCreatedEdit bool `json:"includesCreatedEdit"` 26 IsMinimized bool `json:"isMinimized"` 27 MinimizedReason string `json:"minimizedReason"` 28 ReactionGroups ReactionGroups `json:"reactionGroups"` 29 } 30 31 type CommentCreateInput struct { 32 Body string 33 SubjectId string 34 } 35 36 func CommentCreate(client *Client, repoHost string, params CommentCreateInput) (string, error) { 37 var mutation struct { 38 AddComment struct { 39 CommentEdge struct { 40 Node struct { 41 URL string 42 } 43 } 44 } `graphql:"addComment(input: $input)"` 45 } 46 47 variables := map[string]interface{}{ 48 "input": githubv4.AddCommentInput{ 49 Body: githubv4.String(params.Body), 50 SubjectID: graphql.ID(params.SubjectId), 51 }, 52 } 53 54 gql := graphQLClient(client.http, repoHost) 55 err := gql.MutateNamed(context.Background(), "CommentCreate", &mutation, variables) 56 if err != nil { 57 return "", err 58 } 59 60 return mutation.AddComment.CommentEdge.Node.URL, nil 61 } 62 63 func (c Comment) AuthorLogin() string { 64 return c.Author.Login 65 } 66 67 func (c Comment) Association() string { 68 return c.AuthorAssociation 69 } 70 71 func (c Comment) Content() string { 72 return c.Body 73 } 74 75 func (c Comment) Created() time.Time { 76 return c.CreatedAt 77 } 78 79 func (c Comment) HiddenReason() string { 80 return c.MinimizedReason 81 } 82 83 func (c Comment) IsEdited() bool { 84 return c.IncludesCreatedEdit 85 } 86 87 func (c Comment) IsHidden() bool { 88 return c.IsMinimized 89 } 90 91 func (c Comment) Link() string { 92 return "" 93 } 94 95 func (c Comment) Reactions() ReactionGroups { 96 return c.ReactionGroups 97 } 98 99 func (c Comment) Status() string { 100 return "" 101 }