From 69f65321d64cd25ae60419ec554d46858fe8c633 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Fri, 12 Aug 2016 15:13:57 +0100 Subject: [PATCH] Move out project key to realm ID mapping --- .../matrix-org/go-neb/services/jira/jira.go | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/github.com/matrix-org/go-neb/services/jira/jira.go b/src/github.com/matrix-org/go-neb/services/jira/jira.go index b4593e9..22cd933 100644 --- a/src/github.com/matrix-org/go-neb/services/jira/jira.go +++ b/src/github.com/matrix-org/go-neb/services/jira/jira.go @@ -150,20 +150,7 @@ func (s *jiraService) expandIssue(roomID, userID, issueKey string) interface{} { projectKey := groups[1] - // find which realm this project belongs to. - // TODO: Multiple realms with the same pkey will be randomly chosen. - realmID := "" - for r, realmConfig := range s.Rooms[roomID].Realms { - for pkey, projectConfig := range realmConfig.Projects { - if pkey == projectKey && projectConfig.Expand { - realmID = r - break - } - } - if realmID != "" { - break - } - } + realmID := s.realmIDForProject(roomID, projectKey) if realmID == "" { return nil } @@ -238,6 +225,18 @@ func (s *jiraService) OnReceiveWebhook(w http.ResponseWriter, req *http.Request, webhook.OnReceiveRequest(w, req, cli) } +func (s *jiraService) realmIDForProject(roomID, projectKey string) string { + // TODO: Multiple realms with the same pkey will be randomly chosen. + for r, realmConfig := range s.Rooms[roomID].Realms { + for pkey, projectConfig := range realmConfig.Projects { + if pkey == projectKey && projectConfig.Expand { + return r + } + } + } + return "" +} + func (s *jiraService) projectToRealm(userID, pkey string) (*realms.JIRARealm, error) { // We don't know which JIRA installation this project maps to, so: // - Get all known JIRA realms and f.e query their endpoints with the