1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 "time"
12 )
13
14
15 type IssueComment struct {
16 ID *int64 `json:"id,omitempty"`
17 NodeID *string `json:"node_id,omitempty"`
18 Body *string `json:"body,omitempty"`
19 User *User `json:"user,omitempty"`
20 Reactions *Reactions `json:"reactions,omitempty"`
21 CreatedAt *Timestamp `json:"created_at,omitempty"`
22 UpdatedAt *Timestamp `json:"updated_at,omitempty"`
23
24
25 AuthorAssociation *string `json:"author_association,omitempty"`
26 URL *string `json:"url,omitempty"`
27 HTMLURL *string `json:"html_url,omitempty"`
28 IssueURL *string `json:"issue_url,omitempty"`
29 }
30
31 func (i IssueComment) String() string {
32 return Stringify(i)
33 }
34
35
36
37 type IssueListCommentsOptions struct {
38
39 Sort *string `url:"sort,omitempty"`
40
41
42 Direction *string `url:"direction,omitempty"`
43
44
45 Since *time.Time `url:"since,omitempty"`
46
47 ListOptions
48 }
49
50
51
52
53
54
55 func (s *IssuesService) ListComments(ctx context.Context, owner string, repo string, number int, opts *IssueListCommentsOptions) ([]*IssueComment, *Response, error) {
56 var u string
57 if number == 0 {
58 u = fmt.Sprintf("repos/%v/%v/issues/comments", owner, repo)
59 } else {
60 u = fmt.Sprintf("repos/%v/%v/issues/%d/comments", owner, repo, number)
61 }
62 u, err := addOptions(u, opts)
63 if err != nil {
64 return nil, nil, err
65 }
66
67 req, err := s.client.NewRequest("GET", u, nil)
68 if err != nil {
69 return nil, nil, err
70 }
71
72
73 req.Header.Set("Accept", mediaTypeReactionsPreview)
74
75 var comments []*IssueComment
76 resp, err := s.client.Do(ctx, req, &comments)
77 if err != nil {
78 return nil, resp, err
79 }
80
81 return comments, resp, nil
82 }
83
84
85
86
87 func (s *IssuesService) GetComment(ctx context.Context, owner string, repo string, commentID int64) (*IssueComment, *Response, error) {
88 u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, commentID)
89
90 req, err := s.client.NewRequest("GET", u, nil)
91 if err != nil {
92 return nil, nil, err
93 }
94
95
96 req.Header.Set("Accept", mediaTypeReactionsPreview)
97
98 comment := new(IssueComment)
99 resp, err := s.client.Do(ctx, req, comment)
100 if err != nil {
101 return nil, resp, err
102 }
103
104 return comment, resp, nil
105 }
106
107
108
109
110 func (s *IssuesService) CreateComment(ctx context.Context, owner string, repo string, number int, comment *IssueComment) (*IssueComment, *Response, error) {
111 u := fmt.Sprintf("repos/%v/%v/issues/%d/comments", owner, repo, number)
112 req, err := s.client.NewRequest("POST", u, comment)
113 if err != nil {
114 return nil, nil, err
115 }
116 c := new(IssueComment)
117 resp, err := s.client.Do(ctx, req, c)
118 if err != nil {
119 return nil, resp, err
120 }
121
122 return c, resp, nil
123 }
124
125
126
127
128
129 func (s *IssuesService) EditComment(ctx context.Context, owner string, repo string, commentID int64, comment *IssueComment) (*IssueComment, *Response, error) {
130 u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, commentID)
131 req, err := s.client.NewRequest("PATCH", u, comment)
132 if err != nil {
133 return nil, nil, err
134 }
135 c := new(IssueComment)
136 resp, err := s.client.Do(ctx, req, c)
137 if err != nil {
138 return nil, resp, err
139 }
140
141 return c, resp, nil
142 }
143
144
145
146
147 func (s *IssuesService) DeleteComment(ctx context.Context, owner string, repo string, commentID int64) (*Response, error) {
148 u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, commentID)
149 req, err := s.client.NewRequest("DELETE", u, nil)
150 if err != nil {
151 return nil, err
152 }
153 return s.client.Do(ctx, req, nil)
154 }
155
View as plain text