diff --git a/backend/src/appenlight/models/integrations/jira.py b/backend/src/appenlight/models/integrations/jira.py index a0f3c20..f8c2380 100644 --- a/backend/src/appenlight/models/integrations/jira.py +++ b/backend/src/appenlight/models/integrations/jira.py @@ -60,64 +60,72 @@ class JiraClient(object): projects = self.client.projects() return projects - def get_assignees(self): + def get_assignees(self, request): """Gets list of possible assignees""" - users = self.client.search_assignable_users_for_issues( - None, project=self.project) - results = [] - for user in users: - results.append({"id": user.name, "name": user.displayName}) - return results - - def get_metadata(self): + cache_region = request.registry.cache_regions.redis_sec_30 + @cache_region.cache_on_arguments('JiraClient.get_assignees') def cached(project_name): - metadata = self.client.createmeta( - projectKeys=project_name, expand='projects.issuetypes.fields') - assignees = self.get_assignees() - parsed_metadata = [] - for entry in metadata['projects'][0]['issuetypes']: - issue = {"name": entry['name'], - "id": entry['id'], - "fields": []} - for i_id, field_i in entry['fields'].items(): - field = { - "name": field_i['name'], - "id": i_id, - "required": field_i['required'], - "values": [], - "type": field_i['schema'].get('type') - } - if field_i.get('allowedValues'): - field['values'] = [] - for i in field_i['allowedValues']: - field['values'].append( - {'id': i['id'], - 'name': i.get('name', i.get('value', '')) - }) - if field['id'] == 'assignee': - field['values'] = assignees + users = self.client.search_assignable_users_for_issues( + None, project=project_name) + results = [] + for user in users: + results.append({"id": user.name, "name": user.displayName}) + return results + return cached(self.project) - issue['fields'].append(field) - parsed_metadata.append(issue) - return parsed_metadata + def get_issue_types(self, request): + metadata = self.get_metadata(request) + assignees = self.get_assignees(request) + parsed_metadata = [] + for entry in metadata['projects'][0]['issuetypes']: + issue = {"name": entry['name'], + "id": entry['id'], + "fields": []} + for i_id, field_i in entry['fields'].items(): + field = { + "name": field_i['name'], + "id": i_id, + "required": field_i['required'], + "values": [], + "type": field_i['schema'].get('type') + } + if field_i.get('allowedValues'): + field['values'] = [] + for i in field_i['allowedValues']: + field['values'].append( + {'id': i['id'], + 'name': i.get('name', i.get('value', '')) + }) + if field['id'] == 'assignee': + field['values'] = assignees + issue['fields'].append(field) + parsed_metadata.append(issue) + return parsed_metadata + def get_metadata(self, request): + # cache_region = request.registry.cache_regions.redis_sec_30 + # @cache_region.cache_on_arguments('JiraClient.get_metadata') + def cached(project_name): + return self.client.createmeta( + projectKeys=project_name, expand='projects.issuetypes.fields') return cached(self.project) - def create_issue(self, form_data): - metadata = self.get_metadata() + def create_issue(self, form_data, request): + issue_types = self.get_issue_types(request) payload = { 'project': {'key': form_data['project']}, 'summary': form_data['title'], 'description': form_data['content'], - 'issuetype': {'id': '1'}, + 'issuetype': {'id': form_data['issue_type']}, "priority": {'id': form_data['priority']}, "assignee": {'name': form_data['responsible']}, } - for issue_type in metadata: - if issue_type['id'] == '1': + for issue_type in issue_types: + if issue_type['id'] == form_data['issue_type']: for field in issue_type['fields']: + # set some defaults for other required fields if field == 'reporter': - payload["reporter"] = {'id': self.user_name}, + payload["reporter"] = {'id': self.user_name} if field['required'] and field['id'] not in payload: if field['type'] == 'array': payload[field['id']] = [field['values'][0], ] diff --git a/backend/src/appenlight/static/js/appenlight.js b/backend/src/appenlight/static/js/appenlight.js index 1fa25c9..20d06d9 100644 --- a/backend/src/appenlight/static/js/appenlight.js +++ b/backend/src/appenlight/static/js/appenlight.js @@ -4613,6 +4613,11 @@ function kickstartAE() { "
\n" + + " https://servername.atlassian.net\n" + + "
\n" + + "\n" + "\n" + + " user@email.com\n" + + "
\n" + + "\n" + "+ https://servername.atlassian.net +
++ user@email.com +
+