Browse Source

Merge pull request #206 from t3chguy/github-reopen

add !github reopen cmd
pull/231/head
Richard Lewis 7 years ago
committed by GitHub
parent
commit
8c1ac06ef7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 34
      src/github.com/matrix-org/go-neb/services/github/github.go

34
src/github.com/matrix-org/go-neb/services/github/github.go

@ -341,39 +341,48 @@ func (s *Service) cmdGithubAssign(roomID, userID string, args []string) (interfa
return gomatrix.TextMessage{"m.notice", fmt.Sprintf("Added assignees to issue: %s", *issue.HTMLURL)}, nil
}
const cmdGithubCloseUsage = `!github close [owner/repo]#issue`
func (s *Service) cmdGithubClose(roomID, userID string, args []string) (interface{}, error) {
func (s *Service) githubIssueCloseReopen(roomID, userID string, args []string, state, verb, help string) (interface{}, error) {
cli, resp, err := s.requireGithubClientFor(userID)
if cli == nil {
return resp, err
}
if len(args) == 0 {
return &gomatrix.TextMessage{"m.notice", "Usage: " + cmdGithubCloseUsage}, nil
return &gomatrix.TextMessage{"m.notice", "Usage: " + help}, nil
}
// get owner,repo,issue,resp out of args[0]
owner, repo, issueNum, resp := s.getIssueDetailsFor(args[0], roomID, cmdGithubCloseUsage)
owner, repo, issueNum, resp := s.getIssueDetailsFor(args[0], roomID, help)
if resp != nil {
return resp, nil
}
state := "closed"
issueComment, res, err := cli.Issues.Edit(owner, repo, issueNum, &gogithub.IssueRequest{
State: &state,
})
if err != nil {
log.WithField("err", err).Print("Failed to close issue")
log.WithField("err", err).Print("Failed to %s issue", verb)
if res == nil {
return nil, fmt.Errorf("Failed to close issue. Failed to connect to Github")
return nil, fmt.Errorf("Failed to %s issue. Failed to connect to Github", verb)
}
return nil, fmt.Errorf("Failed to close issue. HTTP %d", res.StatusCode)
return nil, fmt.Errorf("Failed to %s issue. HTTP %d", verb, res.StatusCode)
}
return gomatrix.TextMessage{"m.notice", fmt.Sprintf("Closed issue: %s", *issueComment.HTMLURL)}, nil
}
const cmdGithubCloseUsage = `!github close [owner/repo]#issue`
func (s *Service) cmdGithubClose(roomID, userID string, args []string) (interface{}, error) {
return s.githubIssueCloseReopen(roomID, userID, args, "closed", "close", cmdGithubCloseUsage)
}
const cmdGithubReopenUsage = `!github reopen [owner/repo]#issue`
func (s *Service) cmdGithubReopen(roomID, userID string, args []string) (interface{}, error) {
return s.githubIssueCloseReopen(roomID, userID, args, "open", "open", cmdGithubCloseUsage)
}
func (s *Service) getIssueDetailsFor(input, roomID, usage string) (owner, repo string, issueNum int, resp interface{}) {
// We expect the input to look like:
// "[owner/repo]#issue"
@ -533,6 +542,12 @@ func (s *Service) Commands(cli *gomatrix.Client) []types.Command {
return s.cmdGithubClose(roomID, userID, args)
},
},
types.Command{
Path: []string{"github", "reopen"},
Command: func(roomID, userID string, args []string) (interface{}, error) {
return s.cmdGithubReopen(roomID, userID, args)
},
},
types.Command{
Path: []string{"github", "help"},
Command: func(roomID, userID string, args []string) (interface{}, error) {
@ -544,6 +559,7 @@ func (s *Service) Commands(cli *gomatrix.Client) []types.Command {
cmdGithubCommentUsage,
cmdGithubAssignUsage,
cmdGithubCloseUsage,
cmdGithubReopenUsage,
}, "\n"),
}, nil
},

Loading…
Cancel
Save