Skip to content

Commit 51d32d9

Browse files
feat!: Add ListReactionOptions to all ListxxReactions functions to enable filter by content (#3532)
BREAKING CHANGE: `ListCommentReactionOptions` => `ListReactionOptions` and all `List*Reactions` methods now use it.
1 parent 3cac18b commit 51d32d9

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

github/reactions.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ func (r Reaction) String() string {
4848
return Stringify(r)
4949
}
5050

51-
// ListCommentReactionOptions specifies the optional parameters to the
52-
// ReactionsService.ListCommentReactions method.
53-
type ListCommentReactionOptions struct {
51+
// ListReactionOptions specifies the optional parameters to the list reactions endpoints.
52+
type ListReactionOptions struct {
5453
// Content restricts the returned comment reactions to only those with the given type.
5554
// Omit this parameter to list all reactions to a commit comment.
5655
// Possible values are: "+1", "-1", "laugh", "confused", "heart", "hooray", "rocket", or "eyes".
@@ -64,7 +63,7 @@ type ListCommentReactionOptions struct {
6463
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#list-reactions-for-a-commit-comment
6564
//
6665
//meta:operation GET /repos/{owner}/{repo}/comments/{comment_id}/reactions
67-
func (s *ReactionsService) ListCommentReactions(ctx context.Context, owner, repo string, id int64, opts *ListCommentReactionOptions) ([]*Reaction, *Response, error) {
66+
func (s *ReactionsService) ListCommentReactions(ctx context.Context, owner, repo string, id int64, opts *ListReactionOptions) ([]*Reaction, *Response, error) {
6867
u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions", owner, repo, id)
6968
u, err := addOptions(u, opts)
7069
if err != nil {
@@ -144,7 +143,7 @@ func (s *ReactionsService) DeleteCommentReactionByID(ctx context.Context, repoID
144143
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#list-reactions-for-an-issue
145144
//
146145
//meta:operation GET /repos/{owner}/{repo}/issues/{issue_number}/reactions
147-
func (s *ReactionsService) ListIssueReactions(ctx context.Context, owner, repo string, number int, opts *ListOptions) ([]*Reaction, *Response, error) {
146+
func (s *ReactionsService) ListIssueReactions(ctx context.Context, owner, repo string, number int, opts *ListReactionOptions) ([]*Reaction, *Response, error) {
148147
u := fmt.Sprintf("repos/%v/%v/issues/%v/reactions", owner, repo, number)
149148
u, err := addOptions(u, opts)
150149
if err != nil {
@@ -224,7 +223,7 @@ func (s *ReactionsService) DeleteIssueReactionByID(ctx context.Context, repoID,
224223
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#list-reactions-for-an-issue-comment
225224
//
226225
//meta:operation GET /repos/{owner}/{repo}/issues/comments/{comment_id}/reactions
227-
func (s *ReactionsService) ListIssueCommentReactions(ctx context.Context, owner, repo string, id int64, opts *ListOptions) ([]*Reaction, *Response, error) {
226+
func (s *ReactionsService) ListIssueCommentReactions(ctx context.Context, owner, repo string, id int64, opts *ListReactionOptions) ([]*Reaction, *Response, error) {
228227
u := fmt.Sprintf("repos/%v/%v/issues/comments/%v/reactions", owner, repo, id)
229228
u, err := addOptions(u, opts)
230229
if err != nil {
@@ -304,7 +303,7 @@ func (s *ReactionsService) DeleteIssueCommentReactionByID(ctx context.Context, r
304303
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#list-reactions-for-a-pull-request-review-comment
305304
//
306305
//meta:operation GET /repos/{owner}/{repo}/pulls/comments/{comment_id}/reactions
307-
func (s *ReactionsService) ListPullRequestCommentReactions(ctx context.Context, owner, repo string, id int64, opts *ListOptions) ([]*Reaction, *Response, error) {
306+
func (s *ReactionsService) ListPullRequestCommentReactions(ctx context.Context, owner, repo string, id int64, opts *ListReactionOptions) ([]*Reaction, *Response, error) {
308307
u := fmt.Sprintf("repos/%v/%v/pulls/comments/%v/reactions", owner, repo, id)
309308
u, err := addOptions(u, opts)
310309
if err != nil {
@@ -384,7 +383,7 @@ func (s *ReactionsService) DeletePullRequestCommentReactionByID(ctx context.Cont
384383
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#list-reactions-for-a-team-discussion-legacy
385384
//
386385
//meta:operation GET /teams/{team_id}/discussions/{discussion_number}/reactions
387-
func (s *ReactionsService) ListTeamDiscussionReactions(ctx context.Context, teamID int64, discussionNumber int, opts *ListOptions) ([]*Reaction, *Response, error) {
386+
func (s *ReactionsService) ListTeamDiscussionReactions(ctx context.Context, teamID int64, discussionNumber int, opts *ListReactionOptions) ([]*Reaction, *Response, error) {
388387
u := fmt.Sprintf("teams/%v/discussions/%v/reactions", teamID, discussionNumber)
389388
u, err := addOptions(u, opts)
390389
if err != nil {
@@ -460,7 +459,7 @@ func (s *ReactionsService) DeleteTeamDiscussionReactionByOrgIDAndTeamID(ctx cont
460459
// GitHub API docs: https://docs.github.com/rest/reactions/reactions#list-reactions-for-a-team-discussion-comment-legacy
461460
//
462461
//meta:operation GET /teams/{team_id}/discussions/{discussion_number}/comments/{comment_number}/reactions
463-
func (s *ReactionsService) ListTeamDiscussionCommentReactions(ctx context.Context, teamID int64, discussionNumber, commentNumber int, opts *ListOptions) ([]*Reaction, *Response, error) {
462+
func (s *ReactionsService) ListTeamDiscussionCommentReactions(ctx context.Context, teamID int64, discussionNumber, commentNumber int, opts *ListReactionOptions) ([]*Reaction, *Response, error) {
464463
u := fmt.Sprintf("teams/%v/discussions/%v/comments/%v/reactions", teamID, discussionNumber, commentNumber)
465464
u, err := addOptions(u, opts)
466465
if err != nil {

github/reactions_test.go

+21-11
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func TestReactionsService_ListCommentReactions(t *testing.T) {
7979
fmt.Fprint(w, `[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`)
8080
})
8181

82-
opt := &ListCommentReactionOptions{Content: "+1"}
82+
opt := &ListReactionOptions{Content: "+1"}
8383
ctx := context.Background()
8484
reactions, _, err := client.Reactions.ListCommentReactions(ctx, "o", "r", 1, opt)
8585
if err != nil {
@@ -149,13 +149,15 @@ func TestReactionsService_ListIssueReactions(t *testing.T) {
149149
mux.HandleFunc("/repos/o/r/issues/1/reactions", func(w http.ResponseWriter, r *http.Request) {
150150
testMethod(t, r, "GET")
151151
testHeader(t, r, "Accept", mediaTypeReactionsPreview)
152+
testFormValues(t, r, values{"content": "+1"})
152153

153154
w.WriteHeader(http.StatusOK)
154155
assertWrite(t, w, []byte(`[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`))
155156
})
156157

158+
opt := &ListReactionOptions{Content: "+1"}
157159
ctx := context.Background()
158-
got, _, err := client.Reactions.ListIssueReactions(ctx, "o", "r", 1, nil)
160+
got, _, err := client.Reactions.ListIssueReactions(ctx, "o", "r", 1, opt)
159161
if err != nil {
160162
t.Errorf("ListIssueReactions returned error: %v", err)
161163
}
@@ -173,7 +175,7 @@ func TestReactionsService_ListIssueReactions_coverage(t *testing.T) {
173175

174176
const methodName = "ListIssueReactions"
175177
testBadOptions(t, methodName, func() (err error) {
176-
_, _, err = client.Reactions.ListIssueReactions(ctx, "\n", "\n", -1, &ListOptions{})
178+
_, _, err = client.Reactions.ListIssueReactions(ctx, "\n", "\n", -1, &ListReactionOptions{})
177179
return err
178180
})
179181

@@ -230,13 +232,15 @@ func TestReactionsService_ListIssueCommentReactions(t *testing.T) {
230232
mux.HandleFunc("/repos/o/r/issues/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) {
231233
testMethod(t, r, "GET")
232234
testHeader(t, r, "Accept", mediaTypeReactionsPreview)
235+
testFormValues(t, r, values{"content": "+1"})
233236

234237
w.WriteHeader(http.StatusOK)
235238
assertWrite(t, w, []byte(`[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`))
236239
})
237240

241+
opt := &ListReactionOptions{Content: "+1"}
238242
ctx := context.Background()
239-
got, _, err := client.Reactions.ListIssueCommentReactions(ctx, "o", "r", 1, nil)
243+
got, _, err := client.Reactions.ListIssueCommentReactions(ctx, "o", "r", 1, opt)
240244
if err != nil {
241245
t.Errorf("ListIssueCommentReactions returned error: %v", err)
242246
}
@@ -254,7 +258,7 @@ func TestReactionsService_ListIssueCommentReactions_coverage(t *testing.T) {
254258

255259
const methodName = "ListIssueCommentReactions"
256260
testBadOptions(t, methodName, func() (err error) {
257-
_, _, err = client.Reactions.ListIssueCommentReactions(ctx, "\n", "\n", -1, &ListOptions{})
261+
_, _, err = client.Reactions.ListIssueCommentReactions(ctx, "\n", "\n", -1, &ListReactionOptions{})
258262
return err
259263
})
260264

@@ -311,13 +315,15 @@ func TestReactionsService_ListPullRequestCommentReactions(t *testing.T) {
311315
mux.HandleFunc("/repos/o/r/pulls/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) {
312316
testMethod(t, r, "GET")
313317
testHeader(t, r, "Accept", mediaTypeReactionsPreview)
318+
testFormValues(t, r, values{"content": "+1"})
314319

315320
w.WriteHeader(http.StatusOK)
316321
assertWrite(t, w, []byte(`[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`))
317322
})
318323

324+
opt := &ListReactionOptions{Content: "+1"}
319325
ctx := context.Background()
320-
got, _, err := client.Reactions.ListPullRequestCommentReactions(ctx, "o", "r", 1, nil)
326+
got, _, err := client.Reactions.ListPullRequestCommentReactions(ctx, "o", "r", 1, opt)
321327
if err != nil {
322328
t.Errorf("ListPullRequestCommentReactions returned error: %v", err)
323329
}
@@ -335,7 +341,7 @@ func TestReactionsService_ListPullRequestCommentReactions_coverage(t *testing.T)
335341

336342
const methodName = "ListPullRequestCommentReactions"
337343
testBadOptions(t, methodName, func() (err error) {
338-
_, _, err = client.Reactions.ListPullRequestCommentReactions(ctx, "\n", "\n", -1, &ListOptions{})
344+
_, _, err = client.Reactions.ListPullRequestCommentReactions(ctx, "\n", "\n", -1, &ListReactionOptions{})
339345
return err
340346
})
341347

@@ -392,13 +398,15 @@ func TestReactionsService_ListTeamDiscussionReactions(t *testing.T) {
392398
mux.HandleFunc("/teams/1/discussions/2/reactions", func(w http.ResponseWriter, r *http.Request) {
393399
testMethod(t, r, "GET")
394400
testHeader(t, r, "Accept", mediaTypeReactionsPreview)
401+
testFormValues(t, r, values{"content": "+1"})
395402

396403
w.WriteHeader(http.StatusOK)
397404
assertWrite(t, w, []byte(`[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`))
398405
})
399406

407+
opt := &ListReactionOptions{Content: "+1"}
400408
ctx := context.Background()
401-
got, _, err := client.Reactions.ListTeamDiscussionReactions(ctx, 1, 2, nil)
409+
got, _, err := client.Reactions.ListTeamDiscussionReactions(ctx, 1, 2, opt)
402410
if err != nil {
403411
t.Errorf("ListTeamDiscussionReactions returned error: %v", err)
404412
}
@@ -416,7 +424,7 @@ func TestReactionsService_ListTeamDiscussionReactions_coverage(t *testing.T) {
416424

417425
const methodName = "ListTeamDiscussionReactions"
418426
testBadOptions(t, methodName, func() (err error) {
419-
_, _, err = client.Reactions.ListTeamDiscussionReactions(ctx, -1, -2, &ListOptions{})
427+
_, _, err = client.Reactions.ListTeamDiscussionReactions(ctx, -1, -2, &ListReactionOptions{})
420428
return err
421429
})
422430

@@ -473,13 +481,15 @@ func TestReactionService_ListTeamDiscussionCommentReactions(t *testing.T) {
473481
mux.HandleFunc("/teams/1/discussions/2/comments/3/reactions", func(w http.ResponseWriter, r *http.Request) {
474482
testMethod(t, r, "GET")
475483
testHeader(t, r, "Accept", mediaTypeReactionsPreview)
484+
testFormValues(t, r, values{"content": "+1"})
476485

477486
w.WriteHeader(http.StatusOK)
478487
assertWrite(t, w, []byte(`[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`))
479488
})
480489

490+
opt := &ListReactionOptions{Content: "+1"}
481491
ctx := context.Background()
482-
got, _, err := client.Reactions.ListTeamDiscussionCommentReactions(ctx, 1, 2, 3, nil)
492+
got, _, err := client.Reactions.ListTeamDiscussionCommentReactions(ctx, 1, 2, 3, opt)
483493
if err != nil {
484494
t.Errorf("ListTeamDiscussionCommentReactions returned error: %v", err)
485495
}
@@ -497,7 +507,7 @@ func TestReactionService_ListTeamDiscussionCommentReactions_coverage(t *testing.
497507

498508
const methodName = "ListTeamDiscussionCommentReactions"
499509
testBadOptions(t, methodName, func() (err error) {
500-
_, _, err = client.Reactions.ListTeamDiscussionCommentReactions(ctx, -1, -2, -3, &ListOptions{})
510+
_, _, err = client.Reactions.ListTeamDiscussionCommentReactions(ctx, -1, -2, -3, &ListReactionOptions{})
501511
return err
502512
})
503513

0 commit comments

Comments
 (0)