1package api
2
3import (
4	"context"
5	"time"
6
7	graphql "github.com/cli/shurcooL-graphql"
8	"github.com/shurcooL/githubv4"
9)
10
11type Comments struct {
12	Nodes      []Comment
13	TotalCount int
14	PageInfo   struct {
15		HasNextPage bool
16		EndCursor   string
17	}
18}
19
20type 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
31type CommentCreateInput struct {
32	Body      string
33	SubjectId string
34}
35
36func 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
63func (c Comment) AuthorLogin() string {
64	return c.Author.Login
65}
66
67func (c Comment) Association() string {
68	return c.AuthorAssociation
69}
70
71func (c Comment) Content() string {
72	return c.Body
73}
74
75func (c Comment) Created() time.Time {
76	return c.CreatedAt
77}
78
79func (c Comment) HiddenReason() string {
80	return c.MinimizedReason
81}
82
83func (c Comment) IsEdited() bool {
84	return c.IncludesCreatedEdit
85}
86
87func (c Comment) IsHidden() bool {
88	return c.IsMinimized
89}
90
91func (c Comment) Link() string {
92	return ""
93}
94
95func (c Comment) Reactions() ReactionGroups {
96	return c.ReactionGroups
97}
98
99func (c Comment) Status() string {
100	return ""
101}
102