ndaversa / hubot-jira-bot

Lets you search for JIRA tickets, open them, transition them thru different states, comment on them, rank them up or down, start or stop watching them or change who is assigned to a ticket. Also, notifications for assignments, mentions and watched tickets.
https://www.npmjs.com/package/hubot-jira-bot
MIT License
61 stars 43 forks source link

Unable to lookup users in jira, assigning tickets to bot user instead #32

Closed vwbusguy closed 7 years ago

vwbusguy commented 7 years ago

Whenever an attempt is made to assign or add a watcher to a Jira issue, the plugin fails to find the jira user and assigns/adds a watcher for the bot user instead. It is attempting to look up the jira name based on the email of the user. I have verified that the email address in slack matches the email address in Jira.

Here's the versions:

At a glance, I believe the plugin may be assuming that the Jira username is an email address rather the querying the actual email field in Jira? In our Jira instance, usernames are not email addresses.

vwbusguy commented 7 years ago

Example error output when adding a watcher/assignee. (Note that the bot returns a success that the slack user was added/assigned in channel):

ERROR Cannot find jira user with (email address), trying myself

vwbusguy commented 7 years ago

It looks like the query at https://github.com/ndaversa/hubot-jira-bot/blob/master/src/jira/user.coffee#L9 utilizes the Jira API endpoint at https://docs.atlassian.com/jira/REST/server/#api/2/user-findUsers which should work for email addresses. It appears to be using this function for assigning at https://github.com/ndaversa/hubot-jira-bot/blob/master/src/jira/assign.coffee#L12 and https://github.com/ndaversa/hubot-jira-bot/blob/master/src/jira/watch.coffee#L13 , but failing to return a Jira user.

For good measure, I even temporarily elevated the bot user to an admin in jira and was still not able to resolve users, so i do not believe it is a Jira permissions issue and the bot is properly resolving slack email addresses.

vwbusguy commented 7 years ago

One more thing, I am able to resolve a username based on an email address using the /rest/api/2/user/search endpoint in Jira manually. In doing so, I have found the issue - the emailAddress field returned was parsed as "(user) at (domain) dot (tld)" so that it does not match the string verbatim. This means that although it finds matches, it fails the secondary query at https://github.com/ndaversa/hubot-jira-bot/blob/master/src/jira/user.coffee#L11 .

I found that in my Jira instance, there is a setting, "User email visibility" which obfuscates the emailAddress field in the API. After setting this to "Logged in only" the bot plugin now resolves Jira users. If it is of interest, we could introduce a simple extra formatting regex to https://github.com/ndaversa/hubot-jira-bot/blob/master/src/jira/user.coffee#L11 to work for both cases so that the plugin would also work for jira systems that have email obfuscated in the API?