| 1 |
// Copyright 2016 The go-github AUTHORS. All rights reserved. |
| 2 |
// |
| 3 |
// Use of this source code is governed by a BSD-style |
| 4 |
// license that can be found in the LICENSE file. |
| 5 |
|
| 6 |
package github |
| 7 |
|
| 8 |
import ( |
| 9 |
"context" |
| 10 |
"fmt" |
| 11 |
"net/http" |
| 12 |
) |
| 13 |
|
| 14 |
// ReactionsService provides access to the reactions-related functions in the |
| 15 |
// GitHub API. |
| 16 |
// |
| 17 |
// GitHub API docs: https://docs.github.com/rest/reactions |
| 18 |
type ReactionsService service |
| 19 |
|
| 20 |
// Reaction represents a GitHub reaction. |
| 21 |
type Reaction struct { |
| 22 |
// ID is the Reaction ID. |
| 23 |
ID *int64 `json:"id,omitempty"` |
| 24 |
User *User `json:"user,omitempty"` |
| 25 |
NodeID *string `json:"node_id,omitempty"` |
| 26 |
// Content is the type of reaction. |
| 27 |
// Possible values are: |
| 28 |
// "+1", "-1", "laugh", "confused", "heart", "hooray", "rocket", or "eyes". |
| 29 |
Content *string `json:"content,omitempty"` |
| 30 |
} |
| 31 |
|
| 32 |
// Reactions represents a summary of GitHub reactions. |
| 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 |
// ListCommentReactionOptions specifies the optional parameters to the |
| 51 |
// ReactionsService.ListCommentReactions method. |
| 52 |
type ListCommentReactionOptions struct { |
| 53 |
// Content restricts the returned comment reactions to only those with the given type. |
| 54 |
// Omit this parameter to list all reactions to a commit comment. |
| 55 |
// Possible values are: "+1", "-1", "laugh", "confused", "heart", "hooray", "rocket", or "eyes". |
| 56 |
Content string `url:"content,omitempty"` |
| 57 |
|
| 58 |
ListOptions |
| 59 |
} |
| 60 |
|
| 61 |
// ListCommentReactions lists the reactions for a commit comment. |
| 62 |
// |
| 63 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#list-reactions-for-a-commit-comment |
| 64 |
// |
| 65 |
//meta:operation GET /repos/{owner}/{repo}/comments/{comment_id}/reactions |
| 66 |
func (s *ReactionsService) ListCommentReactions(ctx context.Context, owner, repo string, id int64, opts *ListCommentReactionOptions) ([]*Reaction, *Response, error) { |
| 67 |
u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions", owner, repo, id) |
| 68 |
u, err := addOptions(u, opts) |
| 69 |
if err != nil { |
| 70 |
return nil, nil, err |
| 71 |
} |
| 72 |
|
| 73 |
req, err := s.client.NewRequest("GET", u, nil) |
| 74 |
if err != nil { |
| 75 |
return nil, nil, err |
| 76 |
} |
| 77 |
|
| 78 |
// TODO: remove custom Accept headers when APIs fully launch. |
| 79 |
req.Header.Set("Accept", mediaTypeReactionsPreview) |
| 80 |
|
| 81 |
var m []*Reaction |
| 82 |
resp, err := s.client.Do(ctx, req, &m) |
| 83 |
if err != nil { |
| 84 |
return nil, resp, err |
| 85 |
} |
| 86 |
|
| 87 |
return m, resp, nil |
| 88 |
} |
| 89 |
|
| 90 |
// CreateCommentReaction creates a reaction for a commit comment. |
| 91 |
// Note that if you have already created a reaction of type content, the |
| 92 |
// previously created reaction will be returned with Status: 200 OK. |
| 93 |
// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray", "rocket", or "eyes". |
| 94 |
// |
| 95 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#create-reaction-for-a-commit-comment |
| 96 |
// |
| 97 |
//meta:operation POST /repos/{owner}/{repo}/comments/{comment_id}/reactions |
| 98 |
func (s *ReactionsService) CreateCommentReaction(ctx context.Context, owner, repo string, id int64, content string) (*Reaction, *Response, error) { |
| 99 |
u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions", owner, repo, id) |
| 100 |
|
| 101 |
body := &Reaction{Content: String(content)} |
| 102 |
req, err := s.client.NewRequest("POST", u, body) |
| 103 |
if err != nil { |
| 104 |
return nil, nil, err |
| 105 |
} |
| 106 |
|
| 107 |
// TODO: remove custom Accept headers when APIs fully launch. |
| 108 |
req.Header.Set("Accept", mediaTypeReactionsPreview) |
| 109 |
|
| 110 |
m := &Reaction{} |
| 111 |
resp, err := s.client.Do(ctx, req, m) |
| 112 |
if err != nil { |
| 113 |
return nil, resp, err |
| 114 |
} |
| 115 |
|
| 116 |
return m, resp, nil |
| 117 |
} |
| 118 |
|
| 119 |
// DeleteCommentReaction deletes the reaction for a commit comment. |
| 120 |
// |
| 121 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#delete-a-commit-comment-reaction |
| 122 |
// |
| 123 |
//meta:operation DELETE /repos/{owner}/{repo}/comments/{comment_id}/reactions/{reaction_id} |
| 124 |
func (s *ReactionsService) DeleteCommentReaction(ctx context.Context, owner, repo string, commentID, reactionID int64) (*Response, error) { |
| 125 |
u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions/%v", owner, repo, commentID, reactionID) |
| 126 |
|
| 127 |
return s.deleteReaction(ctx, u) |
| 128 |
} |
| 129 |
|
| 130 |
// DeleteCommentReactionByID deletes the reaction for a commit comment by repository ID. |
| 131 |
// |
| 132 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#delete-a-commit-comment-reaction |
| 133 |
// |
| 134 |
//meta:operation DELETE /repos/{owner}/{repo}/comments/{comment_id}/reactions/{reaction_id} |
| 135 |
func (s *ReactionsService) DeleteCommentReactionByID(ctx context.Context, repoID, commentID, reactionID int64) (*Response, error) { |
| 136 |
u := fmt.Sprintf("repositories/%v/comments/%v/reactions/%v", repoID, commentID, reactionID) |
| 137 |
|
| 138 |
return s.deleteReaction(ctx, u) |
| 139 |
} |
| 140 |
|
| 141 |
// ListIssueReactions lists the reactions for an issue. |
| 142 |
// |
| 143 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#list-reactions-for-an-issue |
| 144 |
// |
| 145 |
//meta:operation GET /repos/{owner}/{repo}/issues/{issue_number}/reactions |
| 146 |
func (s *ReactionsService) ListIssueReactions(ctx context.Context, owner, repo string, number int, opts *ListOptions) ([]*Reaction, *Response, error) { |
| 147 |
u := fmt.Sprintf("repos/%v/%v/issues/%v/reactions", owner, repo, number) |
| 148 |
u, err := addOptions(u, opts) |
| 149 |
if err != nil { |
| 150 |
return nil, nil, err |
| 151 |
} |
| 152 |
|
| 153 |
req, err := s.client.NewRequest("GET", u, nil) |
| 154 |
if err != nil { |
| 155 |
return nil, nil, err |
| 156 |
} |
| 157 |
|
| 158 |
// TODO: remove custom Accept headers when APIs fully launch. |
| 159 |
req.Header.Set("Accept", mediaTypeReactionsPreview) |
| 160 |
|
| 161 |
var m []*Reaction |
| 162 |
resp, err := s.client.Do(ctx, req, &m) |
| 163 |
if err != nil { |
| 164 |
return nil, resp, err |
| 165 |
} |
| 166 |
|
| 167 |
return m, resp, nil |
| 168 |
} |
| 169 |
|
| 170 |
// CreateIssueReaction creates a reaction for an issue. |
| 171 |
// Note that if you have already created a reaction of type content, the |
| 172 |
// previously created reaction will be returned with Status: 200 OK. |
| 173 |
// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray", "rocket", or "eyes". |
| 174 |
// |
| 175 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#create-reaction-for-an-issue |
| 176 |
// |
| 177 |
//meta:operation POST /repos/{owner}/{repo}/issues/{issue_number}/reactions |
| 178 |
func (s *ReactionsService) CreateIssueReaction(ctx context.Context, owner, repo string, number int, content string) (*Reaction, *Response, error) { |
| 179 |
u := fmt.Sprintf("repos/%v/%v/issues/%v/reactions", owner, repo, number) |
| 180 |
|
| 181 |
body := &Reaction{Content: String(content)} |
| 182 |
req, err := s.client.NewRequest("POST", u, body) |
| 183 |
if err != nil { |
| 184 |
return nil, nil, err |
| 185 |
} |
| 186 |
|
| 187 |
// TODO: remove custom Accept headers when APIs fully launch. |
| 188 |
req.Header.Set("Accept", mediaTypeReactionsPreview) |
| 189 |
|
| 190 |
m := &Reaction{} |
| 191 |
resp, err := s.client.Do(ctx, req, m) |
| 192 |
if err != nil { |
| 193 |
return nil, resp, err |
| 194 |
} |
| 195 |
|
| 196 |
return m, resp, nil |
| 197 |
} |
| 198 |
|
| 199 |
// DeleteIssueReaction deletes the reaction to an issue. |
| 200 |
// |
| 201 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#delete-an-issue-reaction |
| 202 |
// |
| 203 |
//meta:operation DELETE /repos/{owner}/{repo}/issues/{issue_number}/reactions/{reaction_id} |
| 204 |
func (s *ReactionsService) DeleteIssueReaction(ctx context.Context, owner, repo string, issueNumber int, reactionID int64) (*Response, error) { |
| 205 |
url := fmt.Sprintf("repos/%v/%v/issues/%v/reactions/%v", owner, repo, issueNumber, reactionID) |
| 206 |
|
| 207 |
return s.deleteReaction(ctx, url) |
| 208 |
} |
| 209 |
|
| 210 |
// DeleteIssueReactionByID deletes the reaction to an issue by repository ID. |
| 211 |
// |
| 212 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#delete-an-issue-reaction |
| 213 |
// |
| 214 |
//meta:operation DELETE /repos/{owner}/{repo}/issues/{issue_number}/reactions/{reaction_id} |
| 215 |
func (s *ReactionsService) DeleteIssueReactionByID(ctx context.Context, repoID, issueNumber int, reactionID int64) (*Response, error) { |
| 216 |
url := fmt.Sprintf("repositories/%v/issues/%v/reactions/%v", repoID, issueNumber, reactionID) |
| 217 |
|
| 218 |
return s.deleteReaction(ctx, url) |
| 219 |
} |
| 220 |
|
| 221 |
// ListIssueCommentReactions lists the reactions for an issue comment. |
| 222 |
// |
| 223 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#list-reactions-for-an-issue-comment |
| 224 |
// |
| 225 |
//meta:operation GET /repos/{owner}/{repo}/issues/comments/{comment_id}/reactions |
| 226 |
func (s *ReactionsService) ListIssueCommentReactions(ctx context.Context, owner, repo string, id int64, opts *ListOptions) ([]*Reaction, *Response, error) { |
| 227 |
u := fmt.Sprintf("repos/%v/%v/issues/comments/%v/reactions", owner, repo, id) |
| 228 |
u, err := addOptions(u, opts) |
| 229 |
if err != nil { |
| 230 |
return nil, nil, err |
| 231 |
} |
| 232 |
|
| 233 |
req, err := s.client.NewRequest("GET", u, nil) |
| 234 |
if err != nil { |
| 235 |
return nil, nil, err |
| 236 |
} |
| 237 |
|
| 238 |
// TODO: remove custom Accept headers when APIs fully launch. |
| 239 |
req.Header.Set("Accept", mediaTypeReactionsPreview) |
| 240 |
|
| 241 |
var m []*Reaction |
| 242 |
resp, err := s.client.Do(ctx, req, &m) |
| 243 |
if err != nil { |
| 244 |
return nil, resp, err |
| 245 |
} |
| 246 |
|
| 247 |
return m, resp, nil |
| 248 |
} |
| 249 |
|
| 250 |
// CreateIssueCommentReaction creates a reaction for an issue comment. |
| 251 |
// Note that if you have already created a reaction of type content, the |
| 252 |
// previously created reaction will be returned with Status: 200 OK. |
| 253 |
// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray", "rocket", or "eyes". |
| 254 |
// |
| 255 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#create-reaction-for-an-issue-comment |
| 256 |
// |
| 257 |
//meta:operation POST /repos/{owner}/{repo}/issues/comments/{comment_id}/reactions |
| 258 |
func (s *ReactionsService) CreateIssueCommentReaction(ctx context.Context, owner, repo string, id int64, content string) (*Reaction, *Response, error) { |
| 259 |
u := fmt.Sprintf("repos/%v/%v/issues/comments/%v/reactions", owner, repo, id) |
| 260 |
|
| 261 |
body := &Reaction{Content: String(content)} |
| 262 |
req, err := s.client.NewRequest("POST", u, body) |
| 263 |
if err != nil { |
| 264 |
return nil, nil, err |
| 265 |
} |
| 266 |
|
| 267 |
// TODO: remove custom Accept headers when APIs fully launch. |
| 268 |
req.Header.Set("Accept", mediaTypeReactionsPreview) |
| 269 |
|
| 270 |
m := &Reaction{} |
| 271 |
resp, err := s.client.Do(ctx, req, m) |
| 272 |
if err != nil { |
| 273 |
return nil, resp, err |
| 274 |
} |
| 275 |
|
| 276 |
return m, resp, nil |
| 277 |
} |
| 278 |
|
| 279 |
// DeleteIssueCommentReaction deletes the reaction to an issue comment. |
| 280 |
// |
| 281 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#delete-an-issue-comment-reaction |
| 282 |
// |
| 283 |
//meta:operation DELETE /repos/{owner}/{repo}/issues/comments/{comment_id}/reactions/{reaction_id} |
| 284 |
func (s *ReactionsService) DeleteIssueCommentReaction(ctx context.Context, owner, repo string, commentID, reactionID int64) (*Response, error) { |
| 285 |
url := fmt.Sprintf("repos/%v/%v/issues/comments/%v/reactions/%v", owner, repo, commentID, reactionID) |
| 286 |
|
| 287 |
return s.deleteReaction(ctx, url) |
| 288 |
} |
| 289 |
|
| 290 |
// DeleteIssueCommentReactionByID deletes the reaction to an issue comment by repository ID. |
| 291 |
// |
| 292 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#delete-an-issue-comment-reaction |
| 293 |
// |
| 294 |
//meta:operation DELETE /repos/{owner}/{repo}/issues/comments/{comment_id}/reactions/{reaction_id} |
| 295 |
func (s *ReactionsService) DeleteIssueCommentReactionByID(ctx context.Context, repoID, commentID, reactionID int64) (*Response, error) { |
| 296 |
url := fmt.Sprintf("repositories/%v/issues/comments/%v/reactions/%v", repoID, commentID, reactionID) |
| 297 |
|
| 298 |
return s.deleteReaction(ctx, url) |
| 299 |
} |
| 300 |
|
| 301 |
// ListPullRequestCommentReactions lists the reactions for a pull request review comment. |
| 302 |
// |
| 303 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#list-reactions-for-a-pull-request-review-comment |
| 304 |
// |
| 305 |
//meta:operation GET /repos/{owner}/{repo}/pulls/comments/{comment_id}/reactions |
| 306 |
func (s *ReactionsService) ListPullRequestCommentReactions(ctx context.Context, owner, repo string, id int64, opts *ListOptions) ([]*Reaction, *Response, error) { |
| 307 |
u := fmt.Sprintf("repos/%v/%v/pulls/comments/%v/reactions", owner, repo, id) |
| 308 |
u, err := addOptions(u, opts) |
| 309 |
if err != nil { |
| 310 |
return nil, nil, err |
| 311 |
} |
| 312 |
|
| 313 |
req, err := s.client.NewRequest("GET", u, nil) |
| 314 |
if err != nil { |
| 315 |
return nil, nil, err |
| 316 |
} |
| 317 |
|
| 318 |
// TODO: remove custom Accept headers when APIs fully launch. |
| 319 |
req.Header.Set("Accept", mediaTypeReactionsPreview) |
| 320 |
|
| 321 |
var m []*Reaction |
| 322 |
resp, err := s.client.Do(ctx, req, &m) |
| 323 |
if err != nil { |
| 324 |
return nil, resp, err |
| 325 |
} |
| 326 |
|
| 327 |
return m, resp, nil |
| 328 |
} |
| 329 |
|
| 330 |
// CreatePullRequestCommentReaction creates a reaction for a pull request review comment. |
| 331 |
// Note that if you have already created a reaction of type content, the |
| 332 |
// previously created reaction will be returned with Status: 200 OK. |
| 333 |
// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray", "rocket", or "eyes". |
| 334 |
// |
| 335 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#create-reaction-for-a-pull-request-review-comment |
| 336 |
// |
| 337 |
//meta:operation POST /repos/{owner}/{repo}/pulls/comments/{comment_id}/reactions |
| 338 |
func (s *ReactionsService) CreatePullRequestCommentReaction(ctx context.Context, owner, repo string, id int64, content string) (*Reaction, *Response, error) { |
| 339 |
u := fmt.Sprintf("repos/%v/%v/pulls/comments/%v/reactions", owner, repo, id) |
| 340 |
|
| 341 |
body := &Reaction{Content: String(content)} |
| 342 |
req, err := s.client.NewRequest("POST", u, body) |
| 343 |
if err != nil { |
| 344 |
return nil, nil, err |
| 345 |
} |
| 346 |
|
| 347 |
// TODO: remove custom Accept headers when APIs fully launch. |
| 348 |
req.Header.Set("Accept", mediaTypeReactionsPreview) |
| 349 |
|
| 350 |
m := &Reaction{} |
| 351 |
resp, err := s.client.Do(ctx, req, m) |
| 352 |
if err != nil { |
| 353 |
return nil, resp, err |
| 354 |
} |
| 355 |
|
| 356 |
return m, resp, nil |
| 357 |
} |
| 358 |
|
| 359 |
// DeletePullRequestCommentReaction deletes the reaction to a pull request review comment. |
| 360 |
// |
| 361 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#delete-a-pull-request-comment-reaction |
| 362 |
// |
| 363 |
//meta:operation DELETE /repos/{owner}/{repo}/pulls/comments/{comment_id}/reactions/{reaction_id} |
| 364 |
func (s *ReactionsService) DeletePullRequestCommentReaction(ctx context.Context, owner, repo string, commentID, reactionID int64) (*Response, error) { |
| 365 |
url := fmt.Sprintf("repos/%v/%v/pulls/comments/%v/reactions/%v", owner, repo, commentID, reactionID) |
| 366 |
|
| 367 |
return s.deleteReaction(ctx, url) |
| 368 |
} |
| 369 |
|
| 370 |
// DeletePullRequestCommentReactionByID deletes the reaction to a pull request review comment by repository ID. |
| 371 |
// |
| 372 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#delete-a-pull-request-comment-reaction |
| 373 |
// |
| 374 |
//meta:operation DELETE /repos/{owner}/{repo}/pulls/comments/{comment_id}/reactions/{reaction_id} |
| 375 |
func (s *ReactionsService) DeletePullRequestCommentReactionByID(ctx context.Context, repoID, commentID, reactionID int64) (*Response, error) { |
| 376 |
url := fmt.Sprintf("repositories/%v/pulls/comments/%v/reactions/%v", repoID, commentID, reactionID) |
| 377 |
|
| 378 |
return s.deleteReaction(ctx, url) |
| 379 |
} |
| 380 |
|
| 381 |
// ListTeamDiscussionReactions lists the reactions for a team discussion. |
| 382 |
// |
| 383 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#list-reactions-for-a-team-discussion-legacy |
| 384 |
// |
| 385 |
//meta:operation GET /teams/{team_id}/discussions/{discussion_number}/reactions |
| 386 |
func (s *ReactionsService) ListTeamDiscussionReactions(ctx context.Context, teamID int64, discussionNumber int, opts *ListOptions) ([]*Reaction, *Response, error) { |
| 387 |
u := fmt.Sprintf("teams/%v/discussions/%v/reactions", teamID, discussionNumber) |
| 388 |
u, err := addOptions(u, opts) |
| 389 |
if err != nil { |
| 390 |
return nil, nil, err |
| 391 |
} |
| 392 |
|
| 393 |
req, err := s.client.NewRequest("GET", u, nil) |
| 394 |
if err != nil { |
| 395 |
return nil, nil, err |
| 396 |
} |
| 397 |
|
| 398 |
req.Header.Set("Accept", mediaTypeReactionsPreview) |
| 399 |
|
| 400 |
var m []*Reaction |
| 401 |
resp, err := s.client.Do(ctx, req, &m) |
| 402 |
if err != nil { |
| 403 |
return nil, resp, err |
| 404 |
} |
| 405 |
|
| 406 |
return m, resp, nil |
| 407 |
} |
| 408 |
|
| 409 |
// CreateTeamDiscussionReaction creates a reaction for a team discussion. |
| 410 |
// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray", "rocket", or "eyes". |
| 411 |
// |
| 412 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#create-reaction-for-a-team-discussion-legacy |
| 413 |
// |
| 414 |
//meta:operation POST /teams/{team_id}/discussions/{discussion_number}/reactions |
| 415 |
func (s *ReactionsService) CreateTeamDiscussionReaction(ctx context.Context, teamID int64, discussionNumber int, content string) (*Reaction, *Response, error) { |
| 416 |
u := fmt.Sprintf("teams/%v/discussions/%v/reactions", teamID, discussionNumber) |
| 417 |
|
| 418 |
body := &Reaction{Content: String(content)} |
| 419 |
req, err := s.client.NewRequest("POST", u, body) |
| 420 |
if err != nil { |
| 421 |
return nil, nil, err |
| 422 |
} |
| 423 |
|
| 424 |
req.Header.Set("Accept", mediaTypeReactionsPreview) |
| 425 |
|
| 426 |
m := &Reaction{} |
| 427 |
resp, err := s.client.Do(ctx, req, m) |
| 428 |
if err != nil { |
| 429 |
return nil, resp, err |
| 430 |
} |
| 431 |
|
| 432 |
return m, resp, nil |
| 433 |
} |
| 434 |
|
| 435 |
// DeleteTeamDiscussionReaction deletes the reaction to a team discussion. |
| 436 |
// |
| 437 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#delete-team-discussion-reaction |
| 438 |
// |
| 439 |
//meta:operation DELETE /orgs/{org}/teams/{team_slug}/discussions/{discussion_number}/reactions/{reaction_id} |
| 440 |
func (s *ReactionsService) DeleteTeamDiscussionReaction(ctx context.Context, org, teamSlug string, discussionNumber int, reactionID int64) (*Response, error) { |
| 441 |
url := fmt.Sprintf("orgs/%v/teams/%v/discussions/%v/reactions/%v", org, teamSlug, discussionNumber, reactionID) |
| 442 |
|
| 443 |
return s.deleteReaction(ctx, url) |
| 444 |
} |
| 445 |
|
| 446 |
// DeleteTeamDiscussionReactionByOrgIDAndTeamID deletes the reaction to a team discussion by organization ID and team ID. |
| 447 |
// |
| 448 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#create-reaction-for-a-team-discussion |
| 449 |
// |
| 450 |
//meta:operation POST /orgs/{org}/teams/{team_slug}/discussions/{discussion_number}/reactions |
| 451 |
func (s *ReactionsService) DeleteTeamDiscussionReactionByOrgIDAndTeamID(ctx context.Context, orgID, teamID, discussionNumber int, reactionID int64) (*Response, error) { |
| 452 |
url := fmt.Sprintf("organizations/%v/team/%v/discussions/%v/reactions/%v", orgID, teamID, discussionNumber, reactionID) |
| 453 |
|
| 454 |
return s.deleteReaction(ctx, url) |
| 455 |
} |
| 456 |
|
| 457 |
// ListTeamDiscussionCommentReactions lists the reactions for a team discussion comment. |
| 458 |
// |
| 459 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#list-reactions-for-a-team-discussion-comment-legacy |
| 460 |
// |
| 461 |
//meta:operation GET /teams/{team_id}/discussions/{discussion_number}/comments/{comment_number}/reactions |
| 462 |
func (s *ReactionsService) ListTeamDiscussionCommentReactions(ctx context.Context, teamID int64, discussionNumber, commentNumber int, opts *ListOptions) ([]*Reaction, *Response, error) { |
| 463 |
u := fmt.Sprintf("teams/%v/discussions/%v/comments/%v/reactions", teamID, discussionNumber, commentNumber) |
| 464 |
u, err := addOptions(u, opts) |
| 465 |
if err != nil { |
| 466 |
return nil, nil, err |
| 467 |
} |
| 468 |
|
| 469 |
req, err := s.client.NewRequest("GET", u, nil) |
| 470 |
if err != nil { |
| 471 |
return nil, nil, err |
| 472 |
} |
| 473 |
|
| 474 |
req.Header.Set("Accept", mediaTypeReactionsPreview) |
| 475 |
|
| 476 |
var m []*Reaction |
| 477 |
resp, err := s.client.Do(ctx, req, &m) |
| 478 |
if err != nil { |
| 479 |
return nil, resp, err |
| 480 |
} |
| 481 |
return m, resp, nil |
| 482 |
} |
| 483 |
|
| 484 |
// CreateTeamDiscussionCommentReaction creates a reaction for a team discussion comment. |
| 485 |
// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray", "rocket", or "eyes". |
| 486 |
// |
| 487 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#create-reaction-for-a-team-discussion-comment-legacy |
| 488 |
// |
| 489 |
//meta:operation POST /teams/{team_id}/discussions/{discussion_number}/comments/{comment_number}/reactions |
| 490 |
func (s *ReactionsService) CreateTeamDiscussionCommentReaction(ctx context.Context, teamID int64, discussionNumber, commentNumber int, content string) (*Reaction, *Response, error) { |
| 491 |
u := fmt.Sprintf("teams/%v/discussions/%v/comments/%v/reactions", teamID, discussionNumber, commentNumber) |
| 492 |
|
| 493 |
body := &Reaction{Content: String(content)} |
| 494 |
req, err := s.client.NewRequest("POST", u, body) |
| 495 |
if err != nil { |
| 496 |
return nil, nil, err |
| 497 |
} |
| 498 |
|
| 499 |
req.Header.Set("Accept", mediaTypeReactionsPreview) |
| 500 |
|
| 501 |
m := &Reaction{} |
| 502 |
resp, err := s.client.Do(ctx, req, m) |
| 503 |
if err != nil { |
| 504 |
return nil, resp, err |
| 505 |
} |
| 506 |
|
| 507 |
return m, resp, nil |
| 508 |
} |
| 509 |
|
| 510 |
// DeleteTeamDiscussionCommentReaction deletes the reaction to a team discussion comment. |
| 511 |
// |
| 512 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#delete-team-discussion-comment-reaction |
| 513 |
// |
| 514 |
//meta:operation DELETE /orgs/{org}/teams/{team_slug}/discussions/{discussion_number}/comments/{comment_number}/reactions/{reaction_id} |
| 515 |
func (s *ReactionsService) DeleteTeamDiscussionCommentReaction(ctx context.Context, org, teamSlug string, discussionNumber, commentNumber int, reactionID int64) (*Response, error) { |
| 516 |
url := fmt.Sprintf("orgs/%v/teams/%v/discussions/%v/comments/%v/reactions/%v", org, teamSlug, discussionNumber, commentNumber, reactionID) |
| 517 |
|
| 518 |
return s.deleteReaction(ctx, url) |
| 519 |
} |
| 520 |
|
| 521 |
// DeleteTeamDiscussionCommentReactionByOrgIDAndTeamID deletes the reaction to a team discussion comment by organization ID and team ID. |
| 522 |
// |
| 523 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#create-reaction-for-a-team-discussion-comment |
| 524 |
// |
| 525 |
//meta:operation POST /orgs/{org}/teams/{team_slug}/discussions/{discussion_number}/comments/{comment_number}/reactions |
| 526 |
func (s *ReactionsService) DeleteTeamDiscussionCommentReactionByOrgIDAndTeamID(ctx context.Context, orgID, teamID, discussionNumber, commentNumber int, reactionID int64) (*Response, error) { |
| 527 |
url := fmt.Sprintf("organizations/%v/team/%v/discussions/%v/comments/%v/reactions/%v", orgID, teamID, discussionNumber, commentNumber, reactionID) |
| 528 |
|
| 529 |
return s.deleteReaction(ctx, url) |
| 530 |
} |
| 531 |
|
| 532 |
func (s *ReactionsService) deleteReaction(ctx context.Context, url string) (*Response, error) { |
| 533 |
req, err := s.client.NewRequest(http.MethodDelete, url, nil) |
| 534 |
if err != nil { |
| 535 |
return nil, err |
| 536 |
} |
| 537 |
|
| 538 |
// TODO: remove custom Accept headers when APIs fully launch. |
| 539 |
req.Header.Set("Accept", mediaTypeReactionsPreview) |
| 540 |
|
| 541 |
return s.client.Do(ctx, req, nil) |
| 542 |
} |
| 543 |
|
| 544 |
// CreateReleaseReaction creates a reaction to a release. |
| 545 |
// Note that a response with a Status: 200 OK means that you already |
| 546 |
// added the reaction type to this release. |
| 547 |
// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray", "rocket", or "eyes". |
| 548 |
// |
| 549 |
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#create-reaction-for-a-release |
| 550 |
// |
| 551 |
//meta:operation POST /repos/{owner}/{repo}/releases/{release_id}/reactions |
| 552 |
func (s *ReactionsService) CreateReleaseReaction(ctx context.Context, owner, repo string, releaseID int64, content string) (*Reaction, *Response, error) { |
| 553 |
u := fmt.Sprintf("repos/%v/%v/releases/%v/reactions", owner, repo, releaseID) |
| 554 |
|
| 555 |
body := &Reaction{Content: String(content)} |
| 556 |
req, err := s.client.NewRequest("POST", u, body) |
| 557 |
if err != nil { |
| 558 |
return nil, nil, err |
| 559 |
} |
| 560 |
|
| 561 |
req.Header.Set("Accept", mediaTypeReactionsPreview) |
| 562 |
|
| 563 |
m := &Reaction{} |
| 564 |
resp, err := s.client.Do(ctx, req, m) |
| 565 |
if err != nil { |
| 566 |
return nil, resp, err |
| 567 |
} |
| 568 |
|
| 569 |
return m, resp, nil |
| 570 |
} |