Beispiel #1
0
    def validate_config(self, project, config, actor=None):
        """
        ```
        if config['foo'] and not config['bar']:
            raise PluginError('You cannot configure foo with bar')
        return config
        ```
        """
        client = JIRAClient(config['instance_url'], config['username'],
                            config['password'])
        try:
            client.get_projects_list()
        except JIRAError as e:
            self.raise_error(e)

        return config
Beispiel #2
0
    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_response = client.get_projects_list()
            except JIRAError:
                projects_response = None
            else:
                projects = projects_response.json
                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_response = client.get_priorities()
                except JIRAError:
                    priorities_response = None
                else:
                    priorities = priorities_response.json
                    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 JIRAError:
                    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'})

        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',
            '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'
        }]