diff --git a/sentry_jira/forms.py b/sentry_jira/forms.py index da1d9f5..fca72b4 100644 --- a/sentry_jira/forms.py +++ b/sentry_jira/forms.py @@ -142,15 +142,16 @@ class JIRAIssueForm(forms.Form): def __init__(self, *args, **kwargs): self.ignored_fields = kwargs.pop("ignored_fields") initial = kwargs.get("initial") - jira_client = initial.pop("jira_client") + jira_client = kwargs.pop("jira_client") + project_key = kwargs.pop("project_key") priorities = jira_client.get_priorities().json - versions = jira_client.get_versions(initial.get("project_key")).json + versions = jira_client.get_versions(project_key).json # Returns the metadata the configured JIRA instance requires for - # creating issues for a given project. + # creating issues for a given project. # https://developer.atlassian.com/static/rest/jira/5.0.html#id200251 - meta = jira_client.get_create_meta(initial.get("project_key")).json + meta = jira_client.get_create_meta(project_key).json # Early exit, somehow made it here without properly configuring the # plugin. @@ -280,8 +281,6 @@ def clean(self): # above clean method.) very_clean["issuetype"] = {"id": very_clean["issuetype"]} - very_clean.pop("project_key", None) - return very_clean def build_dynamic_field(self, field_meta): diff --git a/sentry_jira/plugin.py b/sentry_jira/plugin.py index e10484b..c4a5dc9 100644 --- a/sentry_jira/plugin.py +++ b/sentry_jira/plugin.py @@ -53,9 +53,6 @@ def get_initial_form_data(self, request, group, event, **kwargs): initial = { 'summary': self._get_group_title(request, group, event), 'description': self._get_group_description(request, group, event), - 'project_key': self.get_option('default_project', group.project), - 'issuetype': request.POST.get('issuetype'), - 'jira_client': self.get_jira_client(group.project) } return initial @@ -72,7 +69,7 @@ def create_issue(self, request, group, form_data, **kwargs): jira_client = self.get_jira_client(group.project) issue_response = jira_client.create_issue(form_data) - if issue_response.status_code in [200, 201]: # weirdly inconsistent. + if issue_response.status_code in [200, 201]: # weirdly inconsistent. return issue_response.json.get("key"), None else: # return some sort of error. @@ -81,7 +78,7 @@ def create_issue(self, request, group, form_data, **kwargs): errdict["__all__"] = "JIRA Internal Server Error." elif issue_response.status_code == 400: for k in issue_response.json["errors"].keys(): - errdict[k] = [issue_response.json["errors"][k],] + errdict[k] = [issue_response.json["errors"][k], ] errdict["__all__"] = issue_response.json["errorMessages"] else: errdict["__all__"] = "Something went wrong, Sounds like a configuration issue: code %s" % issue_response.status_code @@ -109,13 +106,13 @@ def view(self, request, group, **kwargs): 'title': self.get_title(), 'project': group.project, 'has_auth_configured': has_auth_configured, - 'required_auth_settings': required_auth_settings, + 'required_auth_settings': required_auth_settings }) if self.needs_auth(project=group.project, request=request): return self.render(self.needs_auth_template, { 'title': self.get_title(), - 'project': group.project, + 'project': group.project }) if GroupMeta.objects.get_value(group, '%s:tid' % self.get_conf_key(), None): @@ -134,6 +131,8 @@ def view(self, request, group, **kwargs): form = self.new_issue_form( request.POST or None, initial=self.get_initial_form_data(request, group, event), + jira_client=self.get_jira_client(group.project), + project_key=self.get_option('default_project', group.project), ignored_fields=self.get_option("ignored_fields", group.project)) ####################################################################### # to allow the form to be submitted, but ignored so that dynamic fields @@ -172,8 +171,8 @@ def view(self, request, group, **kwargs): context = { 'form': form, - 'title': self.get_new_issue_title(), - } + 'title': self.get_new_issue_title() + } return self.render(self.create_issue_template, context) @@ -226,6 +225,7 @@ def handle_autocomplete(self, request, group, **kwargs): return JSONResponse({'users': users}) + class JSONResponse(Response): """ Hack through the builtin response reliance on plugin.render for responses