From d100d8ddd46c926622ac3d09c6ae6e01f3daef70 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 24 Aug 2016 17:40:23 +0100 Subject: [PATCH] Don't share the matchingGroups array across multiple functions because that's insane --- .../go-neb/services/github/github.go | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) 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 49b5e3f..b038174 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 @@ -112,24 +112,15 @@ func (s *githubService) cmdGithubCreate(roomID, userID string, args []string) (i return matrix.TextMessage{"m.notice", fmt.Sprintf("Created issue: %s", *issue.HTMLURL)}, nil } -func (s *githubService) expandIssue(roomID, userID string, matchingGroups []string) interface{} { - // matchingGroups => ["foo/bar#11", "foo/bar", "foo", "bar", "11"] - num, err := strconv.Atoi(matchingGroups[4]) - if err != nil { - log.WithField("issue_number", matchingGroups[4]).Print("Bad issue number") - return nil - } - owner := matchingGroups[2] - repo := matchingGroups[3] - +func (s *githubService) expandIssue(roomID, userID, owner, repo string, issueNum int) interface{} { cli := s.githubClientFor(userID, true) - i, _, err := cli.Issues.Get(owner, repo, num) + i, _, err := cli.Issues.Get(owner, repo, issueNum) if err != nil { log.WithError(err).WithFields(log.Fields{ "owner": owner, "repo": repo, - "number": num, + "number": issueNum, }).Print("Failed to fetch issue") return nil } @@ -166,7 +157,6 @@ func (s *githubService) Plugin(roomID string) plugin.Plugin { ) return nil } - log.Print(matchingGroups) if matchingGroups[1] == "" && matchingGroups[2] == "" && matchingGroups[3] == "" { // issue only match, this only works if there is a default repo defaultRepo := s.defaultRepo(roomID) @@ -190,7 +180,12 @@ func (s *githubService) Plugin(roomID string) plugin.Plugin { matchingGroups[4], } } - return s.expandIssue(roomID, userID, matchingGroups) + num, err := strconv.Atoi(matchingGroups[4]) + if err != nil { + log.WithField("issue_number", matchingGroups[4]).Print("Bad issue number") + return nil + } + return s.expandIssue(roomID, userID, matchingGroups[2], matchingGroups[3], num) }, }, },