##// END OF EJS Templates
jira: fix jira and allow to pick issue types
ergo -
Show More
@@ -60,64 +60,72 b' class JiraClient(object):'
60 60 projects = self.client.projects()
61 61 return projects
62 62
63 def get_assignees(self):
63 def get_assignees(self, request):
64 64 """Gets list of possible assignees"""
65 users = self.client.search_assignable_users_for_issues(
66 None, project=self.project)
67 results = []
68 for user in users:
69 results.append({"id": user.name, "name": user.displayName})
70 return results
71
72 def get_metadata(self):
65 cache_region = request.registry.cache_regions.redis_sec_30
66 @cache_region.cache_on_arguments('JiraClient.get_assignees')
73 67 def cached(project_name):
74 metadata = self.client.createmeta(
75 projectKeys=project_name, expand='projects.issuetypes.fields')
76 assignees = self.get_assignees()
77 parsed_metadata = []
78 for entry in metadata['projects'][0]['issuetypes']:
79 issue = {"name": entry['name'],
80 "id": entry['id'],
81 "fields": []}
82 for i_id, field_i in entry['fields'].items():
83 field = {
84 "name": field_i['name'],
85 "id": i_id,
86 "required": field_i['required'],
87 "values": [],
88 "type": field_i['schema'].get('type')
89 }
90 if field_i.get('allowedValues'):
91 field['values'] = []
92 for i in field_i['allowedValues']:
93 field['values'].append(
94 {'id': i['id'],
95 'name': i.get('name', i.get('value', ''))
96 })
97 if field['id'] == 'assignee':
98 field['values'] = assignees
68 users = self.client.search_assignable_users_for_issues(
69 None, project=project_name)
70 results = []
71 for user in users:
72 results.append({"id": user.name, "name": user.displayName})
73 return results
74 return cached(self.project)
99 75
100 issue['fields'].append(field)
101 parsed_metadata.append(issue)
102 return parsed_metadata
76 def get_issue_types(self, request):
77 metadata = self.get_metadata(request)
78 assignees = self.get_assignees(request)
79 parsed_metadata = []
80 for entry in metadata['projects'][0]['issuetypes']:
81 issue = {"name": entry['name'],
82 "id": entry['id'],
83 "fields": []}
84 for i_id, field_i in entry['fields'].items():
85 field = {
86 "name": field_i['name'],
87 "id": i_id,
88 "required": field_i['required'],
89 "values": [],
90 "type": field_i['schema'].get('type')
91 }
92 if field_i.get('allowedValues'):
93 field['values'] = []
94 for i in field_i['allowedValues']:
95 field['values'].append(
96 {'id': i['id'],
97 'name': i.get('name', i.get('value', ''))
98 })
99 if field['id'] == 'assignee':
100 field['values'] = assignees
101 issue['fields'].append(field)
102 parsed_metadata.append(issue)
103 return parsed_metadata
103 104
105 def get_metadata(self, request):
106 # cache_region = request.registry.cache_regions.redis_sec_30
107 # @cache_region.cache_on_arguments('JiraClient.get_metadata')
108 def cached(project_name):
109 return self.client.createmeta(
110 projectKeys=project_name, expand='projects.issuetypes.fields')
104 111 return cached(self.project)
105 112
106 def create_issue(self, form_data):
107 metadata = self.get_metadata()
113 def create_issue(self, form_data, request):
114 issue_types = self.get_issue_types(request)
108 115 payload = {
109 116 'project': {'key': form_data['project']},
110 117 'summary': form_data['title'],
111 118 'description': form_data['content'],
112 'issuetype': {'id': '1'},
119 'issuetype': {'id': form_data['issue_type']},
113 120 "priority": {'id': form_data['priority']},
114 121 "assignee": {'name': form_data['responsible']},
115 122 }
116 for issue_type in metadata:
117 if issue_type['id'] == '1':
123 for issue_type in issue_types:
124 if issue_type['id'] == form_data['issue_type']:
118 125 for field in issue_type['fields']:
126 # set some defaults for other required fields
119 127 if field == 'reporter':
120 payload["reporter"] = {'id': self.user_name},
128 payload["reporter"] = {'id': self.user_name}
121 129 if field['required'] and field['id'] not in payload:
122 130 if field['type'] == 'array':
123 131 payload[field['id']] = [field['values'][0], ]
@@ -4613,6 +4613,11 b' function kickstartAE() {'
4613 4613 " <div class=\"col-sm-8 col-lg-9\">\n" +
4614 4614 " <data-form-errors errors=\"integration.integrationForm.ae_validation.host_name\"></data-form-errors>\n" +
4615 4615 " <input class=\"form-control\" id=\"host_name\" name=\"host_name\" type=\"text\" ng-model=\"integration.config.host_name\">\n" +
4616 "\n" +
4617 " <p>\n" +
4618 " <small>https://servername.atlassian.net</small>\n" +
4619 " </p>\n" +
4620 "\n" +
4616 4621 " </div>\n" +
4617 4622 " </div>\n" +
4618 4623 " <div class=\"form-group\" id=\"row-user_name\">\n" +
@@ -4624,6 +4629,11 b' function kickstartAE() {'
4624 4629 "\n" +
4625 4630 " <data-form-errors errors=\"integration.integrationForm.ae_validation.user_name\"></data-form-errors>\n" +
4626 4631 " <input class=\"form-control\" id=\"user_name\" name=\"user_name\" type=\"text\" ng-model=\"integration.config.user_name\">\n" +
4632 "\n" +
4633 " <p>\n" +
4634 " <small>user@email.com</small>\n" +
4635 " </p>\n" +
4636 "\n" +
4627 4637 " </div>\n" +
4628 4638 " </div>\n" +
4629 4639 " <div class=\"form-group\" id=\"row-password\">\n" +
@@ -5609,6 +5619,11 b' function kickstartAE() {'
5609 5619 " <label for=\"issue_title\">Issue Title</label>\n" +
5610 5620 " <input type=\"text\" class=\"form-control\" id=\"issue_title\" placeholder=\"Issue title\" ng-model=\"ctrl.form.title\">\n" +
5611 5621 " </div>\n" +
5622 "\n" +
5623 " <div class=\"form-group\">\n" +
5624 " <label for=\"issue_type\">Issue Type</label>\n" +
5625 " <select class=\"form-control\" id=\"issue_type\" ng-options=\"i.name for i in ctrl.issue_types\" ng-model=\"ctrl.form.issue_type\"></select>\n" +
5626 " </div>\n" +
5612 5627 " <div class=\"form-group row\">\n" +
5613 5628 " <div class=\"col-sm-6\">\n" +
5614 5629 " <label for=\"issue_priority\">Priority</label>\n" +
@@ -9091,6 +9106,7 b' function JiraIntegrationCtrl($uibModalInstance, $state, report, integrationName,'
9091 9106 vm.integrationName = integrationName;
9092 9107 vm.statuses = [];
9093 9108 vm.priorities = [];
9109 vm.issue_types = [];
9094 9110 vm.error_messages = [];
9095 9111 vm.form = {
9096 9112 content: '\n' +
@@ -9111,6 +9127,8 b' function JiraIntegrationCtrl($uibModalInstance, $state, report, integrationName,'
9111 9127 }
9112 9128 vm.assignees = data.assignees;
9113 9129 vm.priorities = data.priorities;
9130 vm.issue_types = data.issue_types;
9131 vm.form.issue_type = vm.issue_types[0];
9114 9132 vm.form.responsible = vm.assignees[0];
9115 9133 vm.form.priority = vm.priorities[0];
9116 9134 }, function (error_data) {
@@ -86,7 +86,7 b' class BitbucketView(IntegrationView):'
86 86 return {'error_messages': [str(e)]}
87 87
88 88 comment_body = 'Bitbucket issue created: %s ' % issue['web_url']
89 comment = ReportComment(user_name=self.request.user.user_name,
89 comment = ReportComment(owner_id=self.request.user.id,
90 90 report_time=report.first_timestamp,
91 91 body=comment_body)
92 92 report.comments.append(comment)
@@ -88,7 +88,7 b' class GithubView(IntegrationView):'
88 88 return {'error_messages': [str(e)]}
89 89
90 90 comment_body = 'Github issue created: %s ' % issue['web_url']
91 comment = ReportComment(user_name=self.request.user.user_name,
91 comment = ReportComment(owner_id=self.request.user.id,
92 92 report_time=report.first_timestamp,
93 93 body=comment_body)
94 94 report.comments.append(comment)
@@ -68,15 +68,19 b' class JiraView(IntegrationView):'
68 68 return {'error_messages': [str(e)]}
69 69 assignees = []
70 70 priorities = []
71 metadata = client.get_metadata()
72 for issue_type in metadata:
71 issue_types = []
72 possible_issue_types = client.get_issue_types(self.request)
73 for issue_type in possible_issue_types:
73 74 for field in issue_type['fields']:
74 75 if field['id'] == 'assignee':
75 76 assignees = field['values']
76 77 if field['id'] == 'priority':
77 78 priorities = field['values']
79 issue_types.append({'name':issue_type['name'],
80 'id':issue_type['id']})
78 81 return {'assignees': assignees,
79 'priorities': priorities}
82 'priorities': priorities,
83 'issue_types': issue_types}
80 84
81 85 @view_config(route_name='integrations_id',
82 86 match_param=['action=create-issue',
@@ -92,20 +96,20 b' class JiraView(IntegrationView):'
92 96 'title': self.request.unsafe_json_body.get('title',
93 97 'Unknown Title'),
94 98 'content': self.request.unsafe_json_body.get('content', ''),
95 'kind': 'bug',
99 'issue_type': self.request.unsafe_json_body['issue_type']['id'],
96 100 'priority': self.request.unsafe_json_body['priority']['id'],
97 101 'responsible': self.request.unsafe_json_body['responsible']['id'],
98 102 'project': self.integration.config['project']
99 103 }
100 104 try:
101 105 client = self.create_client()
102 issue = client.create_issue(form_data)
106 issue = client.create_issue(form_data, request=self.request)
103 107 except IntegrationException as e:
104 108 self.request.response.status_code = 503
105 109 return {'error_messages': [str(e)]}
106 110
107 111 comment_body = 'Jira issue created: %s ' % issue['web_url']
108 comment = ReportComment(user_name=self.request.user.user_name,
112 comment = ReportComment(owner_id=self.request.user.id,
109 113 report_time=report.first_timestamp,
110 114 body=comment_body)
111 115 report.comments.append(comment)
@@ -30,6 +30,7 b' function JiraIntegrationCtrl($uibModalInstance, $state, report, integrationName,'
30 30 vm.integrationName = integrationName;
31 31 vm.statuses = [];
32 32 vm.priorities = [];
33 vm.issue_types = [];
33 34 vm.error_messages = [];
34 35 vm.form = {
35 36 content: '\n' +
@@ -50,6 +51,8 b' function JiraIntegrationCtrl($uibModalInstance, $state, report, integrationName,'
50 51 }
51 52 vm.assignees = data.assignees;
52 53 vm.priorities = data.priorities;
54 vm.issue_types = data.issue_types;
55 vm.form.issue_type = vm.issue_types[0];
53 56 vm.form.responsible = vm.assignees[0];
54 57 vm.form.priority = vm.priorities[0];
55 58 }, function (error_data) {
@@ -16,6 +16,11 b''
16 16 <div class="col-sm-8 col-lg-9">
17 17 <data-form-errors errors="integration.integrationForm.ae_validation.host_name"></data-form-errors>
18 18 <input class="form-control" id="host_name" name="host_name" type="text" ng-model="integration.config.host_name">
19
20 <p>
21 <small>https://servername.atlassian.net</small>
22 </p>
23
19 24 </div>
20 25 </div>
21 26 <div class="form-group" id="row-user_name">
@@ -27,6 +32,11 b''
27 32
28 33 <data-form-errors errors="integration.integrationForm.ae_validation.user_name"></data-form-errors>
29 34 <input class="form-control" id="user_name" name="user_name" type="text" ng-model="integration.config.user_name">
35
36 <p>
37 <small>user@email.com</small>
38 </p>
39
30 40 </div>
31 41 </div>
32 42 <div class="form-group" id="row-password">
@@ -12,6 +12,11 b''
12 12 <label for="issue_title">Issue Title</label>
13 13 <input type="text" class="form-control" id="issue_title" placeholder="Issue title" ng-model="ctrl.form.title">
14 14 </div>
15
16 <div class="form-group">
17 <label for="issue_type">Issue Type</label>
18 <select class="form-control" id="issue_type" ng-options="i.name for i in ctrl.issue_types" ng-model="ctrl.form.issue_type"></select>
19 </div>
15 20 <div class="form-group row">
16 21 <div class="col-sm-6">
17 22 <label for="issue_priority">Priority</label>
General Comments 0
You need to be logged in to leave comments. Login now