1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 "net/http"
12 )
13
14
15
16
17
18 type ReactionsService service
19
20
21 type Reaction struct {
22
23 ID *int64 `json:"id,omitempty"`
24 User *User `json:"user,omitempty"`
25 NodeID *string `json:"node_id,omitempty"`
26
27
28
29 Content *string `json:"content,omitempty"`
30 }
31
32
33 type Reactions struct {
34 TotalCount *int `json:"total_count,omitempty"`
35 PlusOne *int `json:"+1,omitempty"`
36 MinusOne *int `json:"-1,omitempty"`
37 Laugh *int `json:"laugh,omitempty"`
38 Confused *int `json:"confused,omitempty"`
39 Heart *int `json:"heart,omitempty"`
40 Hooray *int `json:"hooray,omitempty"`
41 Rocket *int `json:"rocket,omitempty"`
42 Eyes *int `json:"eyes,omitempty"`
43 URL *string `json:"url,omitempty"`
44 }
45
46 func (r Reaction) String() string {
47 return Stringify(r)
48 }
49
50
51
52 type ListCommentReactionOptions struct {
53
54
55
56 Content string `url:"content,omitempty"`
57
58 ListOptions
59 }
60
61
62
63
64 func (s *ReactionsService) ListCommentReactions(ctx context.Context, owner, repo string, id int64, opts *ListCommentReactionOptions) ([]*Reaction, *Response, error) {
65 u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions", owner, repo, id)
66 u, err := addOptions(u, opts)
67 if err != nil {
68 return nil, nil, err
69 }
70
71 req, err := s.client.NewRequest("GET", u, nil)
72 if err != nil {
73 return nil, nil, err
74 }
75
76
77 req.Header.Set("Accept", mediaTypeReactionsPreview)
78
79 var m []*Reaction
80 resp, err := s.client.Do(ctx, req, &m)
81 if err != nil {
82 return nil, resp, err
83 }
84
85 return m, resp, nil
86 }
87
88
89
90
91
92
93
94 func (s *ReactionsService) CreateCommentReaction(ctx context.Context, owner, repo string, id int64, content string) (*Reaction, *Response, error) {
95 u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions", owner, repo, id)
96
97 body := &Reaction{Content: String(content)}
98 req, err := s.client.NewRequest("POST", u, body)
99 if err != nil {
100 return nil, nil, err
101 }
102
103
104 req.Header.Set("Accept", mediaTypeReactionsPreview)
105
106 m := &Reaction{}
107 resp, err := s.client.Do(ctx, req, m)
108 if err != nil {
109 return nil, resp, err
110 }
111
112 return m, resp, nil
113 }
114
115
116
117
118 func (s *ReactionsService) DeleteCommentReaction(ctx context.Context, owner, repo string, commentID, reactionID int64) (*Response, error) {
119 u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions/%v", owner, repo, commentID, reactionID)
120
121 return s.deleteReaction(ctx, u)
122 }
123
124
125
126
127 func (s *ReactionsService) DeleteCommentReactionByID(ctx context.Context, repoID, commentID, reactionID int64) (*Response, error) {
128 u := fmt.Sprintf("repositories/%v/comments/%v/reactions/%v", repoID, commentID, reactionID)
129
130 return s.deleteReaction(ctx, u)
131 }
132
133
134
135
136 func (s *ReactionsService) ListIssueReactions(ctx context.Context, owner, repo string, number int, opts *ListOptions) ([]*Reaction, *Response, error) {
137 u := fmt.Sprintf("repos/%v/%v/issues/%v/reactions", owner, repo, number)
138 u, err := addOptions(u, opts)
139 if err != nil {
140 return nil, nil, err
141 }
142
143 req, err := s.client.NewRequest("GET", u, nil)
144 if err != nil {
145 return nil, nil, err
146 }
147
148
149 req.Header.Set("Accept", mediaTypeReactionsPreview)
150
151 var m []*Reaction
152 resp, err := s.client.Do(ctx, req, &m)
153 if err != nil {
154 return nil, resp, err
155 }
156
157 return m, resp, nil
158 }
159
160
161
162
163
164
165
166 func (s *ReactionsService) CreateIssueReaction(ctx context.Context, owner, repo string, number int, content string) (*Reaction, *Response, error) {
167 u := fmt.Sprintf("repos/%v/%v/issues/%v/reactions", owner, repo, number)
168
169 body := &Reaction{Content: String(content)}
170 req, err := s.client.NewRequest("POST", u, body)
171 if err != nil {
172 return nil, nil, err
173 }
174
175
176 req.Header.Set("Accept", mediaTypeReactionsPreview)
177
178 m := &Reaction{}
179 resp, err := s.client.Do(ctx, req, m)
180 if err != nil {
181 return nil, resp, err
182 }
183
184 return m, resp, nil
185 }
186
187
188
189
190 func (s *ReactionsService) DeleteIssueReaction(ctx context.Context, owner, repo string, issueNumber int, reactionID int64) (*Response, error) {
191 url := fmt.Sprintf("repos/%v/%v/issues/%v/reactions/%v", owner, repo, issueNumber, reactionID)
192
193 return s.deleteReaction(ctx, url)
194 }
195
196
197
198
199 func (s *ReactionsService) DeleteIssueReactionByID(ctx context.Context, repoID, issueNumber int, reactionID int64) (*Response, error) {
200 url := fmt.Sprintf("repositories/%v/issues/%v/reactions/%v", repoID, issueNumber, reactionID)
201
202 return s.deleteReaction(ctx, url)
203 }
204
205
206
207
208 func (s *ReactionsService) ListIssueCommentReactions(ctx context.Context, owner, repo string, id int64, opts *ListOptions) ([]*Reaction, *Response, error) {
209 u := fmt.Sprintf("repos/%v/%v/issues/comments/%v/reactions", owner, repo, id)
210 u, err := addOptions(u, opts)
211 if err != nil {
212 return nil, nil, err
213 }
214
215 req, err := s.client.NewRequest("GET", u, nil)
216 if err != nil {
217 return nil, nil, err
218 }
219
220
221 req.Header.Set("Accept", mediaTypeReactionsPreview)
222
223 var m []*Reaction
224 resp, err := s.client.Do(ctx, req, &m)
225 if err != nil {
226 return nil, resp, err
227 }
228
229 return m, resp, nil
230 }
231
232
233
234
235
236
237
238 func (s *ReactionsService) CreateIssueCommentReaction(ctx context.Context, owner, repo string, id int64, content string) (*Reaction, *Response, error) {
239 u := fmt.Sprintf("repos/%v/%v/issues/comments/%v/reactions", owner, repo, id)
240
241 body := &Reaction{Content: String(content)}
242 req, err := s.client.NewRequest("POST", u, body)
243 if err != nil {
244 return nil, nil, err
245 }
246
247
248 req.Header.Set("Accept", mediaTypeReactionsPreview)
249
250 m := &Reaction{}
251 resp, err := s.client.Do(ctx, req, m)
252 if err != nil {
253 return nil, resp, err
254 }
255
256 return m, resp, nil
257 }
258
259
260
261
262 func (s *ReactionsService) DeleteIssueCommentReaction(ctx context.Context, owner, repo string, commentID, reactionID int64) (*Response, error) {
263 url := fmt.Sprintf("repos/%v/%v/issues/comments/%v/reactions/%v", owner, repo, commentID, reactionID)
264
265 return s.deleteReaction(ctx, url)
266 }
267
268
269
270
271 func (s *ReactionsService) DeleteIssueCommentReactionByID(ctx context.Context, repoID, commentID, reactionID int64) (*Response, error) {
272 url := fmt.Sprintf("repositories/%v/issues/comments/%v/reactions/%v", repoID, commentID, reactionID)
273
274 return s.deleteReaction(ctx, url)
275 }
276
277
278
279
280 func (s *ReactionsService) ListPullRequestCommentReactions(ctx context.Context, owner, repo string, id int64, opts *ListOptions) ([]*Reaction, *Response, error) {
281 u := fmt.Sprintf("repos/%v/%v/pulls/comments/%v/reactions", owner, repo, id)
282 u, err := addOptions(u, opts)
283 if err != nil {
284 return nil, nil, err
285 }
286
287 req, err := s.client.NewRequest("GET", u, nil)
288 if err != nil {
289 return nil, nil, err
290 }
291
292
293 req.Header.Set("Accept", mediaTypeReactionsPreview)
294
295 var m []*Reaction
296 resp, err := s.client.Do(ctx, req, &m)
297 if err != nil {
298 return nil, resp, err
299 }
300
301 return m, resp, nil
302 }
303
304
305
306
307
308
309
310 func (s *ReactionsService) CreatePullRequestCommentReaction(ctx context.Context, owner, repo string, id int64, content string) (*Reaction, *Response, error) {
311 u := fmt.Sprintf("repos/%v/%v/pulls/comments/%v/reactions", owner, repo, id)
312
313 body := &Reaction{Content: String(content)}
314 req, err := s.client.NewRequest("POST", u, body)
315 if err != nil {
316 return nil, nil, err
317 }
318
319
320 req.Header.Set("Accept", mediaTypeReactionsPreview)
321
322 m := &Reaction{}
323 resp, err := s.client.Do(ctx, req, m)
324 if err != nil {
325 return nil, resp, err
326 }
327
328 return m, resp, nil
329 }
330
331
332
333
334 func (s *ReactionsService) DeletePullRequestCommentReaction(ctx context.Context, owner, repo string, commentID, reactionID int64) (*Response, error) {
335 url := fmt.Sprintf("repos/%v/%v/pulls/comments/%v/reactions/%v", owner, repo, commentID, reactionID)
336
337 return s.deleteReaction(ctx, url)
338 }
339
340
341
342
343 func (s *ReactionsService) DeletePullRequestCommentReactionByID(ctx context.Context, repoID, commentID, reactionID int64) (*Response, error) {
344 url := fmt.Sprintf("repositories/%v/pulls/comments/%v/reactions/%v", repoID, commentID, reactionID)
345
346 return s.deleteReaction(ctx, url)
347 }
348
349
350
351
352 func (s *ReactionsService) ListTeamDiscussionReactions(ctx context.Context, teamID int64, discussionNumber int, opts *ListOptions) ([]*Reaction, *Response, error) {
353 u := fmt.Sprintf("teams/%v/discussions/%v/reactions", teamID, discussionNumber)
354 u, err := addOptions(u, opts)
355 if err != nil {
356 return nil, nil, err
357 }
358
359 req, err := s.client.NewRequest("GET", u, nil)
360 if err != nil {
361 return nil, nil, err
362 }
363
364 req.Header.Set("Accept", mediaTypeReactionsPreview)
365
366 var m []*Reaction
367 resp, err := s.client.Do(ctx, req, &m)
368 if err != nil {
369 return nil, resp, err
370 }
371
372 return m, resp, nil
373 }
374
375
376
377
378
379 func (s *ReactionsService) CreateTeamDiscussionReaction(ctx context.Context, teamID int64, discussionNumber int, content string) (*Reaction, *Response, error) {
380 u := fmt.Sprintf("teams/%v/discussions/%v/reactions", teamID, discussionNumber)
381
382 body := &Reaction{Content: String(content)}
383 req, err := s.client.NewRequest("POST", u, body)
384 if err != nil {
385 return nil, nil, err
386 }
387
388 req.Header.Set("Accept", mediaTypeReactionsPreview)
389
390 m := &Reaction{}
391 resp, err := s.client.Do(ctx, req, m)
392 if err != nil {
393 return nil, resp, err
394 }
395
396 return m, resp, nil
397 }
398
399
400
401
402 func (s *ReactionsService) DeleteTeamDiscussionReaction(ctx context.Context, org, teamSlug string, discussionNumber int, reactionID int64) (*Response, error) {
403 url := fmt.Sprintf("orgs/%v/teams/%v/discussions/%v/reactions/%v", org, teamSlug, discussionNumber, reactionID)
404
405 return s.deleteReaction(ctx, url)
406 }
407
408
409
410
411 func (s *ReactionsService) DeleteTeamDiscussionReactionByOrgIDAndTeamID(ctx context.Context, orgID, teamID, discussionNumber int, reactionID int64) (*Response, error) {
412 url := fmt.Sprintf("organizations/%v/team/%v/discussions/%v/reactions/%v", orgID, teamID, discussionNumber, reactionID)
413
414 return s.deleteReaction(ctx, url)
415 }
416
417
418
419
420 func (s *ReactionsService) ListTeamDiscussionCommentReactions(ctx context.Context, teamID int64, discussionNumber, commentNumber int, opts *ListOptions) ([]*Reaction, *Response, error) {
421 u := fmt.Sprintf("teams/%v/discussions/%v/comments/%v/reactions", teamID, discussionNumber, commentNumber)
422 u, err := addOptions(u, opts)
423 if err != nil {
424 return nil, nil, err
425 }
426
427 req, err := s.client.NewRequest("GET", u, nil)
428 if err != nil {
429 return nil, nil, err
430 }
431
432 req.Header.Set("Accept", mediaTypeReactionsPreview)
433
434 var m []*Reaction
435 resp, err := s.client.Do(ctx, req, &m)
436 if err != nil {
437 return nil, resp, err
438 }
439 return m, resp, nil
440 }
441
442
443
444
445
446 func (s *ReactionsService) CreateTeamDiscussionCommentReaction(ctx context.Context, teamID int64, discussionNumber, commentNumber int, content string) (*Reaction, *Response, error) {
447 u := fmt.Sprintf("teams/%v/discussions/%v/comments/%v/reactions", teamID, discussionNumber, commentNumber)
448
449 body := &Reaction{Content: String(content)}
450 req, err := s.client.NewRequest("POST", u, body)
451 if err != nil {
452 return nil, nil, err
453 }
454
455 req.Header.Set("Accept", mediaTypeReactionsPreview)
456
457 m := &Reaction{}
458 resp, err := s.client.Do(ctx, req, m)
459 if err != nil {
460 return nil, resp, err
461 }
462
463 return m, resp, nil
464 }
465
466
467
468
469 func (s *ReactionsService) DeleteTeamDiscussionCommentReaction(ctx context.Context, org, teamSlug string, discussionNumber, commentNumber int, reactionID int64) (*Response, error) {
470 url := fmt.Sprintf("orgs/%v/teams/%v/discussions/%v/comments/%v/reactions/%v", org, teamSlug, discussionNumber, commentNumber, reactionID)
471
472 return s.deleteReaction(ctx, url)
473 }
474
475
476
477
478 func (s *ReactionsService) DeleteTeamDiscussionCommentReactionByOrgIDAndTeamID(ctx context.Context, orgID, teamID, discussionNumber, commentNumber int, reactionID int64) (*Response, error) {
479 url := fmt.Sprintf("organizations/%v/team/%v/discussions/%v/comments/%v/reactions/%v", orgID, teamID, discussionNumber, commentNumber, reactionID)
480
481 return s.deleteReaction(ctx, url)
482 }
483
484 func (s *ReactionsService) deleteReaction(ctx context.Context, url string) (*Response, error) {
485 req, err := s.client.NewRequest(http.MethodDelete, url, nil)
486 if err != nil {
487 return nil, err
488 }
489
490
491 req.Header.Set("Accept", mediaTypeReactionsPreview)
492
493 return s.client.Do(ctx, req, nil)
494 }
495
496
497
498
499
500
501
502 func (s *ReactionsService) CreateReleaseReaction(ctx context.Context, owner, repo string, releaseID int64, content string) (*Reaction, *Response, error) {
503 u := fmt.Sprintf("repos/%v/%v/releases/%v/reactions", owner, repo, releaseID)
504
505 body := &Reaction{Content: String(content)}
506 req, err := s.client.NewRequest("POST", u, body)
507 if err != nil {
508 return nil, nil, err
509 }
510
511 req.Header.Set("Accept", mediaTypeReactionsPreview)
512
513 m := &Reaction{}
514 resp, err := s.client.Do(ctx, req, m)
515 if err != nil {
516 return nil, resp, err
517 }
518
519 return m, resp, nil
520 }
521
View as plain text