From 3a046cf3ad2fc5683100b1cd3193bf3289bfda48 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 22 Aug 2017 15:52:43 +0100 Subject: [PATCH] add !github react Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../go-neb/services/github/github.go | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/github.com/matrix-org/go-neb/services/github/github.go b/src/github.com/matrix-org/go-neb/services/github/github.go index 0038ec4..ee62bd8 100644 --- a/src/github.com/matrix-org/go-neb/services/github/github.go +++ b/src/github.com/matrix-org/go-neb/services/github/github.go @@ -142,6 +142,35 @@ func (s *Service) cmdGithubCreate(roomID, userID string, args []string) (interfa return gomatrix.TextMessage{"m.notice", fmt.Sprintf("Created issue: %s", *issue.HTMLURL)}, nil } +func (s *Service) cmdGithubReact(roomID, userID string, args []string) (interface{}, error) { + cli, resp, err := s.requireGithubClientFor(userID) + if cli == nil { + return resp, err + } + if len(args) < 2 { + return &gomatrix.TextMessage{"m.notice", + `Usage: !github react [owner/repo]#issue [+1|-1|laugh|confused|heart|hooray]`}, nil + } + + // get owner,repo,issue,resp out of args[0] + owner, repo, issueNum, resp := s.getIssueDetailsFor(args[0], roomID, `!github react [owner/repo]#issue [+1|-1|laugh|confused|heart|hooray]`) + if resp != nil { + return resp, nil + } + + _, res, err := cli.Reactions.CreateIssueReaction(owner, repo, issueNum, args[1]) + + if err != nil { + log.WithField("err", err).Print("Failed to react to issue") + if res == nil { + return nil, fmt.Errorf("Failed to react to issue. Failed to connect to Github") + } + return nil, fmt.Errorf("Failed to react to issue. HTTP %d", res.StatusCode) + } + + return gomatrix.TextMessage{"m.notice", fmt.Sprintf("Reacted to issue with: %s", args[1])}, nil +} + func (s *Service) cmdGithubComment(roomID, userID string, args []string) (interface{}, error) { cli, resp, err := s.requireGithubClientFor(userID) if cli == nil { @@ -291,6 +320,12 @@ func (s *Service) Commands(cli *gomatrix.Client) []types.Command { return s.cmdGithubCreate(roomID, userID, args) }, }, + types.Command{ + Path: []string{"github", "react"}, + Command: func(roomID, userID string, args []string) (interface{}, error) { + return s.cmdGithubReact(roomID, userID, args) + }, + }, types.Command{ Path: []string{"github", "comment"}, Command: func(roomID, userID string, args []string) (interface{}, error) { @@ -309,6 +344,7 @@ func (s *Service) Commands(cli *gomatrix.Client) []types.Command { return &gomatrix.TextMessage{ "m.notice", fmt.Sprintf(`!github create owner/repo "title text" "description text"` + "\n" + + `!github react [owner/repo]#issue [+1|-1|laugh|confused|heart|hooray]` + "\n" + `!github comment [owner/repo]#issue "comment text"` + "\n" + `!github close [owner/repo]#issue`), }, nil