From 8beb8fda7fd4adf8cf6db59d7d6d95ea331794f3 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 8 Aug 2016 11:12:59 +0100 Subject: [PATCH 1/2] Implement `!github create owner/repo title` --- .../go-neb/services/github/github.go | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) 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 9e3ddb5..f621e9b 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 @@ -51,7 +51,39 @@ func (s *githubService) Plugin(roomID string) plugin.Plugin { return &matrix.TextMessage{"m.notice", userID + " : You have not linked your Github account."}, nil } - return &matrix.TextMessage{"m.notice", strings.Join(args, " ")}, nil + + if len(args) < 2 { + return &matrix.TextMessage{"m.notice", + `Usage: !github create owner/repo "issue title" "description"`}, nil + } + + var ( + ownerRepo string + title *string + desc *string + ) + ownerRepo = args[0] + if len(args) == 2 { + title = &args[1] + } else if len(args) == 3 { + title = &args[1] + desc = &args[2] + } else { // > 3 args is probably a title without quote marks + joinedTitle := strings.Join(args[1:], " ") + title = &joinedTitle + } + o := strings.Split(ownerRepo, "/") + + issue, res, err := cli.Issues.Create(o[0], o[1], &github.IssueRequest{ + Title: title, + Body: desc, + }) + if err != nil { + log.WithField("err", err).Print("Failed to create issue") + return nil, fmt.Errorf("Failed to create issue. HTTP %d", res.StatusCode) + } + + return matrix.TextMessage{"m.notice", fmt.Sprintf("Created issue: %s", *issue.HTMLURL)}, nil }, }, }, From b89c3ef776fd09c817e641f6290b8188e01d4678 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 8 Aug 2016 11:22:58 +0100 Subject: [PATCH 2/2] Length check the ownerRepo array --- src/github.com/matrix-org/go-neb/services/github/github.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 f621e9b..f01ad9d 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 @@ -63,6 +63,12 @@ func (s *githubService) Plugin(roomID string) plugin.Plugin { desc *string ) ownerRepo = args[0] + o := strings.Split(ownerRepo, "/") + if len(o) != 2 { + return &matrix.TextMessage{"m.notice", + `Usage: !github create owner/repo "issue title" "description"`}, nil + } + if len(args) == 2 { title = &args[1] } else if len(args) == 3 { @@ -72,7 +78,6 @@ func (s *githubService) Plugin(roomID string) plugin.Plugin { joinedTitle := strings.Join(args[1:], " ") title = &joinedTitle } - o := strings.Split(ownerRepo, "/") issue, res, err := cli.Issues.Create(o[0], o[1], &github.IssueRequest{ Title: title,