UNPKG

946 Btext/coffeescriptView Raw
1_ = require "underscore"
2
3Config = require "../config"
4Utils = require "../utils"
5
6class User
7
8 @withEmail: (email) ->
9 Utils.fetch("#{Config.jira.url}/rest/api/2/user/search?username=#{email}")
10 .then (users) ->
11 jiraUser = _(users).findWhere emailAddress: email if users and users.length > 0
12 throw "Cannot find jira user with #{email}, trying myself" unless jiraUser
13 jiraUser
14 .catch (error) ->
15 Utils.robot.logger.error error
16 Utils.Stats.increment "jirabot.user.lookup.email.failed"
17 Utils.fetch("#{Config.jira.url}/rest/api/2/myself")
18
19 @withUsername: (username) ->
20 Utils.fetch("#{Config.jira.url}/rest/api/2/user?username=#{username}")
21 .catch (error) ->
22 Utils.Stats.increment "jirabot.user.lookup.username.failed"
23 Utils.robot.logger.error "Cannot find jira user with #{username}, trying myself"
24 Utils.fetch("#{Config.jira.url}/rest/api/2/myself")
25
26module.exports = User