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 *time.Time `json:"created_at,omitempty"`
22 UpdatedAt *time.Time `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 Since *time.Time `url:"since,omitempty"`
40
41 ListOptions
42 }
43
44
45
46
47
48
49 func (s *IssuesService) ListComments(ctx context.Context, owner string, repo string, number int, opts *IssueListCommentsOptions) ([]*IssueComment, *Response, error) {
50 var u string
51 if number == 0 {
52 u = fmt.Sprintf("repos/%v/%v/issues/comments", owner, repo)
53 } else {
54 u = fmt.Sprintf("repos/%v/%v/issues/%d/comments", owner, repo, number)
55 }
56 u, err := addOptions(u, opts)
57 if err != nil {
58 return nil, nil, err
59 }
60
61 req, err := s.client.NewRequest("GET", u, nil)
62 if err != nil {
63 return nil, nil, err
64 }
65
66
67 req.Header.Set("Accept", mediaTypeReactionsPreview)
68
69 var comments []*IssueComment
70 resp, err := s.client.Do(ctx, req, &comments)
71 if err != nil {
72 return nil, resp, err
73 }
74
75 return comments, resp, nil
76 }
77
78
79
80
81 func (s *IssuesService) GetComment(ctx context.Context, owner string, repo string, commentID int64) (*IssueComment, *Response, error) {
82 u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, commentID)
83
84 req, err := s.client.NewRequest("GET", u, nil)
85 if err != nil {
86 return nil, nil, err
87 }
88
89
90 req.Header.Set("Accept", mediaTypeReactionsPreview)
91
92 comment := new(IssueComment)
93 resp, err := s.client.Do(ctx, req, comment)
94 if err != nil {
95 return nil, resp, err
96 }
97
98 return comment, resp, nil
99 }
100
101
102
103
104 func (s *IssuesService) CreateComment(ctx context.Context, owner string, repo string, number int, comment *IssueComment) (*IssueComment, *Response, error) {
105 u := fmt.Sprintf("repos/%v/%v/issues/%d/comments", owner, repo, number)
106 req, err := s.client.NewRequest("POST", u, comment)
107 if err != nil {
108 return nil, nil, err
109 }
110 c := new(IssueComment)
111 resp, err := s.client.Do(ctx, req, c)
112 if err != nil {
113 return nil, resp, err
114 }
115
116 return c, resp, nil
117 }
118
119
120
121
122
123 func (s *IssuesService) EditComment(ctx context.Context, owner string, repo string, commentID int64, comment *IssueComment) (*IssueComment, *Response, error) {
124 u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, commentID)
125 req, err := s.client.NewRequest("PATCH", u, comment)
126 if err != nil {
127 return nil, nil, err
128 }
129 c := new(IssueComment)
130 resp, err := s.client.Do(ctx, req, c)
131 if err != nil {
132 return nil, resp, err
133 }
134
135 return c, resp, nil
136 }
137
138
139
140
141 func (s *IssuesService) DeleteComment(ctx context.Context, owner string, repo string, commentID int64) (*Response, error) {
142 u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, commentID)
143 req, err := s.client.NewRequest("DELETE", u, nil)
144 if err != nil {
145 return nil, err
146 }
147 return s.client.Do(ctx, req, nil)
148 }
149
View as plain text