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

Move jira_client and project out of the initial_data and as separate kwargs. #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions sentry_jira/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand Down
18 changes: 9 additions & 9 deletions sentry_jira/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down