Browse Source

Return a specific not found error message when the user hasn't authed with JIRA

pull/28/head
Kegan Dougal 8 years ago
parent
commit
2a3b56a1dc
  1. 2
      src/github.com/matrix-org/go-neb/realms/jira/jira.go
  2. 5
      src/github.com/matrix-org/go-neb/services/jira/jira.go
  3. 3
      src/github.com/matrix-org/go-neb/services/jira/webhook/webhook.go

2
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 // make an unauthenticated client
return jira.NewClient(nil, r.JIRAEndpoint) return jira.NewClient(nil, r.JIRAEndpoint)
} }
return nil, errors.New("No authenticated session found for " + userID)
} }
// some other error
return nil, err return nil, err
} }

5
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) cli, err := r.JIRAClient(userID, false)
if err != nil { 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 return nil, err
} }
i, res, err := cli.Issue.Create(&iss) 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. // - 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 // 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. // 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{ logger := log.WithFields(log.Fields{
"user_id": userID, "user_id": userID,
"project": pkey, "project": pkey,

3
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 { func createWebhook(jrealm *realms.JIRARealm, webhookEndpointURL, userID string) error {
cli, err := jrealm.JIRAClient(userID, false) cli, err := jrealm.JIRAClient(userID, false)
if err != nil {
return err
}
req, err := cli.NewRequest("POST", "rest/webhooks/1.0/webhook", jiraWebhook{ req, err := cli.NewRequest("POST", "rest/webhooks/1.0/webhook", jiraWebhook{
Name: "Go-NEB", Name: "Go-NEB",

Loading…
Cancel
Save