Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Commit

Permalink
Populate all Reporters when no query
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrobenolt committed Sep 21, 2015
1 parent 2a92dfe commit 8c4b164
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
4 changes: 4 additions & 0 deletions sentry_jira/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class JIRAClient(object):
CREATE_URL = '/rest/api/2/issue'
PRIORITIES_URL = '/rest/api/2/priority'
VERSIONS_URL = '/rest/api/2/project/%s/versions'
USERS_URL = '/rest/api/2/user/assignable/search'
HTTP_TIMEOUT = 5

def __init__(self, instance_uri, username, password):
Expand All @@ -43,6 +44,9 @@ def get_versions(self, project):
def get_priorities(self):
return self.get_cached(self.PRIORITIES_URL)

def get_users_for_project(self, project):
return self.make_request('get', self.USERS_URL, {'project': project})

def create_issue(self, raw_form_data):
data = {'fields': raw_form_data}
return self.make_request('post', self.CREATE_URL, payload=data)
Expand Down
30 changes: 24 additions & 6 deletions sentry_jira/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,22 +190,29 @@ def handle_autocomplete(self, request, group, **kwargs):
url = urllib.unquote_plus(request.GET.get("user_autocomplete"))
parsed = list(urlparse.urlsplit(url))
query = urlparse.parse_qs(parsed[3])
q = request.GET.get('q')

jira_client = self.get_jira_client(group.project)

project = self.get_option('default_project', group.project)
# shortcut case for no input since JIRA's API doesn't return all users
if q == '':
return self._get_all_users_for_project(jira_client, project)

if "/rest/api/latest/user/" in url: # its the JSON version of the autocompleter
isXML = False
query["username"] = request.GET.get('q')
query["username"] = q
query.pop('issueKey', False) # some reason JIRA complains if this key is in the URL.
query["project"] = self.get_option('default_project', group.project)
query["project"] = project
else: # its the stupid XML version of the API.
isXML = True
query["query"] = request.GET.get("q")
query["query"] = q
if query.get('fieldName'):
query["fieldName"] = query["fieldName"][0] # for some reason its a list.

parsed[3] = urllib.urlencode(query)
final_url = urlparse.urlunsplit(parsed)

jira_client = self.get_jira_client(group.project)
autocomplete_response = jira_client.get_cached(final_url)
users = []

Expand All @@ -215,19 +222,30 @@ def handle_autocomplete(self, request, group, **kwargs):
'value': userxml.find("name").text,
'display': userxml.find("html").text,
'needsRender': False,
'q': request.GET.get('q')
'q': q,
})
else:
for user in autocomplete_response.json:
users.append({
'value': user["name"],
'display': "%s - %s (%s)" % (user["displayName"], user["emailAddress"], user["name"]),
'needsRender': True,
'q': request.GET.get('q')
'q': q,
})

return JSONResponse({'users': users})

def _get_all_users_for_project(self, client, project):
users = []
for user in client.get_users_for_project(project).json:
users.append({
'value': user['name'],
'display': '%s - %s (%s)' % (user['displayName'], user['emailAddress'], user['name']),
'needsRender': True,
'q': '',
})
return JSONResponse({'users': users})

def _get_group_description(self, request, group, event):
# XXX: Mostly yanked from bases/issue:IssueTrackingPlugin,
# except change ``` code formatting to {code}
Expand Down

0 comments on commit 8c4b164

Please sign in to comment.