def get_configure_plugin_fields(self, request, project, **kwargs): instance = self.get_option('instance_url', project) username = self.get_option('username', project) pw = self.get_option('password', project) jira_project = self.get_option('default_project', project) default_priority = self.get_option('default_priority', project) default_issue_type = self.get_option('default_issue_type', project) project_choices = [] priority_choices = [] issue_type_choices = [] if instance and username and pw: client = JiraClient(instance, username, pw) try: projects = client.get_projects_list() except ApiError: projects = None else: if projects: project_choices = [ (p.get('key'), '%s (%s)' % (p.get('name'), p.get('key'))) for p in projects ] jira_project = jira_project or projects[0]['key'] if jira_project: try: priorities = client.get_priorities() except ApiError: priorities = None else: if priorities: priority_choices = [ (p.get('id'), '%s' % (p.get('name'))) for p in priorities ] default_priority = default_priority or priorities[0]['id'] try: meta = client.get_create_meta_for_project(jira_project) except ApiError: meta = None else: if meta: issue_type_choices = self.make_choices(meta['issuetypes']) if issue_type_choices: default_issue_type = default_issue_type or issue_type_choices[0][0] secret_field = get_secret_field_config(pw, '') secret_field.update({'name': 'password', 'label': 'Password/API Token'}) return [ { 'name': 'instance_url', 'label': 'JIRA Instance URL', 'default': instance, 'type': 'text', 'placeholder': 'e.g. "https://jira.atlassian.com"', 'help': 'It must be visible to the Sentry server' }, { 'name': 'username', 'label': 'Username/Email', 'default': username, 'type': 'text', 'help': 'Ensure the JIRA user has admin permissions on the project' }, secret_field, { 'name': 'default_project', 'label': 'Linked Project', 'type': 'select', 'choices': project_choices, 'default': jira_project, 'required': False }, { 'name': 'ignored_fields', 'label': 'Ignored Fields', 'type': 'textarea', 'required': False, 'placeholder': 'e.g. "components, security, customfield_10006"', 'default': self.get_option('ignored_fields', project), 'help': 'Comma-separated list of properties that you don\'t want to show in the form' }, { 'name': 'default_priority', 'label': 'Default Priority', 'type': 'select', 'choices': priority_choices, 'required': False, 'default': default_priority }, { 'name': 'default_issue_type', 'label': 'Default Issue Type', 'type': 'select', 'choices': issue_type_choices, 'required': False, 'default': default_issue_type }, { 'name': 'auto_create', 'label': 'Automatically create JIRA Tickets', 'default': self.get_option('auto_create', project) or False, 'type': 'bool', 'required': False, 'help': 'Automatically create a JIRA ticket for EVERY new issue' } ]
def get_configure_plugin_fields(self, request, project, **kwargs): instance = self.get_option("instance_url", project) username = self.get_option("username", project) pw = self.get_option("password", project) jira_project = self.get_option("default_project", project) default_priority = self.get_option("default_priority", project) default_issue_type = self.get_option("default_issue_type", project) project_choices = [] priority_choices = [] issue_type_choices = [] if instance and username and pw: client = JiraClient(instance, username, pw) try: projects = client.get_projects_list() except ApiError: projects = None else: if projects: project_choices = [ (p.get("key"), "%s (%s)" % (p.get("name"), p.get("key"))) for p in projects ] jira_project = jira_project or projects[0]["key"] if jira_project: try: priorities = client.get_priorities() except ApiError: priorities = None else: if priorities: priority_choices = [(p.get("id"), "%s" % (p.get("name"))) for p in priorities] default_priority = default_priority or priorities[0][ "id"] try: meta = client.get_create_meta_for_project(jira_project) except ApiError: meta = None else: if meta: issue_type_choices = self.make_choices( meta["issuetypes"]) if issue_type_choices: default_issue_type = default_issue_type or issue_type_choices[ 0][0] secret_field = get_secret_field_config(pw, "") secret_field.update({ "name": "password", "label": "Password/API Token" }) return [ { "name": "instance_url", "label": "JIRA Instance URL", "default": instance, "type": "text", "placeholder": 'e.g. "https://jira.atlassian.com"', "help": "It must be visible to the Sentry server", }, { "name": "username", "label": "Username/Email", "default": username, "type": "text", "help": "Ensure the JIRA user has admin permissions on the project", }, secret_field, { "name": "default_project", "label": "Linked Project", "type": "select", "choices": project_choices, "default": jira_project, "required": False, }, { "name": "ignored_fields", "label": "Ignored Fields", "type": "textarea", "required": False, "placeholder": 'e.g. "components, security, customfield_10006"', "default": self.get_option("ignored_fields", project), "help": "Comma-separated list of properties that you don't want to show in the form", }, { "name": "default_priority", "label": "Default Priority", "type": "select", "choices": priority_choices, "required": False, "default": default_priority, }, { "name": "default_issue_type", "label": "Default Issue Type", "type": "select", "choices": issue_type_choices, "required": False, "default": default_issue_type, }, { "name": "auto_create", "label": "Automatically create JIRA Tickets", "default": self.get_option("auto_create", project) or False, "type": "bool", "required": False, "help": "Automatically create a JIRA ticket for EVERY new issue", }, ]