Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions github/reactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package github
import (
"context"
"fmt"
"net/http"
)

// ReactionsService provides access to the reactions-related functions in the
Expand Down Expand Up @@ -109,6 +110,36 @@ func (s ReactionsService) CreateCommentReaction(ctx context.Context, owner, repo
return m, resp, nil
}

// 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, commentID, reactionID int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions/%v", owner, repo, commentID, reactionID)

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
}

// 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
Expand Down
32 changes: 32 additions & 0 deletions github/reactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,35 @@ 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("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)
}
}