From 7b8ac6a410068059c33b6fa815b51509f6101fae Mon Sep 17 00:00:00 2001 From: Weslei Juan Novaes Pereira Date: Fri, 28 Feb 2020 10:37:18 -0300 Subject: [PATCH 1/4] Added support to delete commit comment --- github/reactions.go | 18 ++++++++++++++++++ github/reactions_test.go | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/github/reactions.go b/github/reactions.go index 43c863af61d..6d3b8536fff 100644 --- a/github/reactions.go +++ b/github/reactions.go @@ -8,6 +8,7 @@ package github import ( "context" "fmt" + "net/http" ) // ReactionsService provides access to the reactions-related functions in the @@ -109,6 +110,23 @@ func (s ReactionsService) CreateCommentReaction(ctx context.Context, owner, repo return m, resp, nil } +// DeleteCommentReaction delete the reaction for a commit comment. +// +// GitHub API docs: https://developer.github.com/v3/reactions/#delete-a-commit-comment-reaction +func (s *ReactionsService) DeleteCommentReaction(ctx context.Context, owner, repo string, id, reactionID int64) (*Response, error) { + u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions/%v", owner, repo, id, reactionID) + + req, err := s.client.NewRequest(http.MethodDelete, u, nil) + if err != nil { + return nil, err + } + + // TODO: remove custom Accept headers when APIs fully launch. + req.Header.Set("Accept", mediaTypeReactionsPreview) + + return s.client.Do(ctx, req, nil) +} + // ListIssueReactions lists the reactions for an issue. // // GitHub API docs: https://developer.github.com/v3/reactions/#list-reactions-for-an-issue diff --git a/github/reactions_test.go b/github/reactions_test.go index c32274dec53..47eb4c917d1 100644 --- a/github/reactions_test.go +++ b/github/reactions_test.go @@ -340,3 +340,19 @@ func TestReactionsService_DeleteReaction(t *testing.T) { t.Errorf("DeleteReaction returned error: %v", err) } } + +func TestReactionsService_DeleteCommitCommentReaction(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/comments/1/reactions/2", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + testHeader(t, r, "Accept", mediaTypeReactionsPreview) + + w.WriteHeader(http.StatusNoContent) + }) + + if _, err := client.Reactions.DeleteCommentReaction(context.Background(), "o", "r", 1, 2); err != nil { + t.Errorf("DeleteReaction returned error: %v", err) + } +} From b2c96fca98ca5597df6142ff9785f879a85268cd Mon Sep 17 00:00:00 2001 From: Weslei Juan Novaes Pereira Date: Fri, 28 Feb 2020 10:50:38 -0300 Subject: [PATCH 2/4] Updated message --- github/reactions_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/reactions_test.go b/github/reactions_test.go index 47eb4c917d1..0f3e6d894ef 100644 --- a/github/reactions_test.go +++ b/github/reactions_test.go @@ -353,6 +353,6 @@ func TestReactionsService_DeleteCommitCommentReaction(t *testing.T) { }) if _, err := client.Reactions.DeleteCommentReaction(context.Background(), "o", "r", 1, 2); err != nil { - t.Errorf("DeleteReaction returned error: %v", err) + t.Errorf("DeleteCommentReaction returned error: %v", err) } } From 96ee94989fbf77ad963afc5267a3aae1f1651b92 Mon Sep 17 00:00:00 2001 From: Weslei Juan Novaes Pereira Date: Fri, 28 Feb 2020 11:59:07 -0300 Subject: [PATCH 3/4] Typo and param name --- github/reactions.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/github/reactions.go b/github/reactions.go index 6d3b8536fff..9e062c5995d 100644 --- a/github/reactions.go +++ b/github/reactions.go @@ -110,11 +110,11 @@ func (s ReactionsService) CreateCommentReaction(ctx context.Context, owner, repo return m, resp, nil } -// DeleteCommentReaction delete the reaction for a commit comment. +// DeleteCommentReaction deletes the reaction for a commit comment. // // GitHub API docs: https://developer.github.com/v3/reactions/#delete-a-commit-comment-reaction -func (s *ReactionsService) DeleteCommentReaction(ctx context.Context, owner, repo string, id, reactionID int64) (*Response, error) { - u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions/%v", owner, repo, id, reactionID) +func (s *ReactionsService) DeleteCommentReaction(ctx context.Context, owner, repo string, commentID, reactionID int64) (*Response, error) { + u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions/%v", owner, repo, commentID, reactionID) req, err := s.client.NewRequest(http.MethodDelete, u, nil) if err != nil { From 821eb9681fcea86bcde764cad95e17b56987b36f Mon Sep 17 00:00:00 2001 From: Weslei Juan Novaes Pereira Date: Fri, 28 Feb 2020 12:12:49 -0300 Subject: [PATCH 4/4] Added support to delete reaction by repo_id --- github/reactions.go | 15 ++++++++++++++- github/reactions_test.go | 16 ++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/github/reactions.go b/github/reactions.go index 9e062c5995d..c2c9ced3193 100644 --- a/github/reactions.go +++ b/github/reactions.go @@ -116,7 +116,20 @@ func (s ReactionsService) CreateCommentReaction(ctx context.Context, owner, repo func (s *ReactionsService) DeleteCommentReaction(ctx context.Context, owner, repo string, commentID, reactionID int64) (*Response, error) { u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions/%v", owner, repo, commentID, reactionID) - req, err := s.client.NewRequest(http.MethodDelete, u, nil) + return s.deleteCommentReaction(ctx, u) +} + +// DeleteCommentReactionByRepoID deletes the reaction for a commit comment by repository ID. +// +// GitHub API docs: https://developer.github.com/v3/reactions/#delete-a-commit-comment-reaction +func (s *ReactionsService) DeleteCommentReactionByRepoID(ctx context.Context, repoID, commentID, reactionID int64) (*Response, error) { + u := fmt.Sprintf("repositories/%v/comments/%v/reactions/%v", repoID, commentID, reactionID) + + return s.deleteCommentReaction(ctx, u) +} + +func (s ReactionsService) deleteCommentReaction(ctx context.Context, url string) (*Response, error) { + req, err := s.client.NewRequest(http.MethodDelete, url, nil) if err != nil { return nil, err } diff --git a/github/reactions_test.go b/github/reactions_test.go index 0f3e6d894ef..90b9eaafc28 100644 --- a/github/reactions_test.go +++ b/github/reactions_test.go @@ -356,3 +356,19 @@ func TestReactionsService_DeleteCommitCommentReaction(t *testing.T) { t.Errorf("DeleteCommentReaction returned error: %v", err) } } + +func TestReactionsService_DeleteCommitCommentReactionByRepoID(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repositories/1/comments/2/reactions/3", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + testHeader(t, r, "Accept", mediaTypeReactionsPreview) + + w.WriteHeader(http.StatusNoContent) + }) + + if _, err := client.Reactions.DeleteCommentReactionByRepoID(context.Background(), 1, 2, 3); err != nil { + t.Errorf("DeleteCommentReactionByRepoID returned error: %v", err) + } +}