From 2a3b56a1dc40b7050e6c6c9bdb7b6422a8c6855c Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 15 Aug 2016 11:12:01 +0100 Subject: [PATCH] Return a specific not found error message when the user hasn't authed with JIRA --- src/github.com/matrix-org/go-neb/realms/jira/jira.go | 2 -- src/github.com/matrix-org/go-neb/services/jira/jira.go | 5 ++++- .../matrix-org/go-neb/services/jira/webhook/webhook.go | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/github.com/matrix-org/go-neb/realms/jira/jira.go b/src/github.com/matrix-org/go-neb/realms/jira/jira.go index 26e6fb7..1b31a92 100644 --- a/src/github.com/matrix-org/go-neb/realms/jira/jira.go +++ b/src/github.com/matrix-org/go-neb/realms/jira/jira.go @@ -251,9 +251,7 @@ func (r *JIRARealm) JIRAClient(userID string, allowUnauth bool) (*jira.Client, e // make an unauthenticated client return jira.NewClient(nil, r.JIRAEndpoint) } - return nil, errors.New("No authenticated session found for " + userID) } - // some other error return nil, err } 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 9e92af6..deb8027 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 @@ -117,6 +117,10 @@ func (s *jiraService) cmdJiraCreate(roomID, userID string, args []string) (inter } cli, err := r.JIRAClient(userID, false) if err != nil { + if err == sql.ErrNoRows { // no client found + return &matrix.TextMessage{"m.notice", + userID + " : You have not linked your JIRA account."}, nil + } return nil, err } i, res, err := cli.Issue.Create(&iss) @@ -286,7 +290,6 @@ func (s *jiraService) projectToRealm(userID, pkey string) (*realms.JIRARealm, er // - If there is a matching project with that key, return that realm. // We search installations which the user has already OAuthed with first as most likely // the project key will be on a JIRA they have access to. - // TODO: Return whether they have authed or not so they know if they need to make a starter link logger := log.WithFields(log.Fields{ "user_id": userID, "project": pkey, diff --git a/src/github.com/matrix-org/go-neb/services/jira/webhook/webhook.go b/src/github.com/matrix-org/go-neb/services/jira/webhook/webhook.go index a34765c..b5635d9 100644 --- a/src/github.com/matrix-org/go-neb/services/jira/webhook/webhook.go +++ b/src/github.com/matrix-org/go-neb/services/jira/webhook/webhook.go @@ -119,6 +119,9 @@ func OnReceiveRequest(req *http.Request) (string, *Event, *errors.HTTPError) { func createWebhook(jrealm *realms.JIRARealm, webhookEndpointURL, userID string) error { cli, err := jrealm.JIRAClient(userID, false) + if err != nil { + return err + } req, err := cli.NewRequest("POST", "rest/webhooks/1.0/webhook", jiraWebhook{ Name: "Go-NEB",