Exemplo n.º 1
0
 def poll(self):
     new_issues = self.connection.client.search_issues(self.jql, startAt=0)
     for issue in new_issues:
         if issue.id not in self.found:
             output = normalize_issue(issue, get_attachments=self.get_attachments, logger=self.logger)
             self.found[issue.id] = True
             self.logger.debug('found: %s', output)
             self.send({Output.ISSUE: output})
Exemplo n.º 2
0
    def run(self, params={}):
        """Search for issues"""
        max_results = params.get(Input.MAX)
        get_attachments = params.get(Input.GET_ATTACHMENTS, False)
        issues = self.connection.client.search_issues(jql_str=params[Input.JQL], maxResults=max_results)

        results = list(
            map(lambda issue: normalize_issue(issue, get_attachments=get_attachments, logger=self.logger), issues))
        results = komand.helper.clean(results)

        return {Output.ISSUES: results}
Exemplo n.º 3
0
    def run(self, params={}):
        """ Get an issue by ID """
        issue = self.connection.client.issue(id=params[Input.ID])
        get_attachments = params.get(Input.GET_ATTACHMENTS)

        if not issue:
            raise PluginException(
                cause=f"No issue found with ID: {params[Input.ID]}.",
                assistance='Please provide a valid issue ID.')

        output = normalize_issue(issue=issue,
                                 get_attachments=get_attachments,
                                 include_raw_fields=True,
                                 logger=self.logger)

        clean_output = insightconnect_plugin_runtime.helper.clean(output)
        return {Output.FOUND: True, Output.ISSUE: clean_output}
Exemplo n.º 4
0
    def run(self, params={}):
        """Run action"""
        project = params.get(Input.PROJECT)

        issue_type = params.get(Input.TYPE)
        summary = params.get(Input.SUMMARY, " ").replace("\n", " ")
        description = params.get(Input.DESCRIPTION, " ")
        fields = params.get(Input.FIELDS, {})

        valid_project = look_up_project(project, self.connection.client)
        if not valid_project:
            raise PluginException(
                cause=
                f"Project {project} does not exist or user don't have permission to access the project.",
                assistance=
                "Please provide a valid project ID/name or make sure project is accessible to user.",
            )

        self.logger.debug("Create issue with: %s", params)

        fields["project"] = project
        fields["summary"] = summary
        fields["description"] = description
        fields["issuetype"] = {"name": issue_type}

        # Check that the type is available in Jira before creating the ticket
        # This is not a perfect check though (see below)
        try:
            # This seems to work for some cases e.g. 'Blah' but not others 'Task' (Task is found below) depending on the Jira installation
            self.connection.client.issue_type_by_name(issue_type)
            # All types can be retrieved with scope via: self.connection.client.issue_types()
            # A future improvement may be able to validate the scope before continuing
            # However, this call doesn't return JSON :'( it returns this stupid thing:
            # [<JIRA IssueType: name='Bug', id='10004'>, <JIRA IssueType: name='Epic', scope={'type': 'PROJECT', 'project': {'id': '10008'} ]
        except KeyError:
            raise PluginException(
                cause="Issue type not known or user doesn't have permissions.",
                assistance=
                "Talk to your Jira administrator to add the type or delegate necessary permissions, "
                "or choose an available type.",
            )

        for client_field in self.connection.client.fields():
            if client_field["name"] in fields:
                field_value = fields.pop(client_field["name"])
                fields[client_field["id"]] = {"value": field_value}

        issue = self.connection.client.create_issue(fields=fields)
        output = normalize_issue(issue, logger=self.logger)

        if params.get(Input.ATTACHMENT_BYTES) and not params.get(
                Input.ATTACHMENT_FILENAME):
            raise PluginException(
                cause=
                "Attachment contents provided but no attachment filename.",
                assistance="Please provide attachment filename.",
            )

        if params.get(Input.ATTACHMENT_FILENAME) and not params.get(
                Input.ATTACHMENT_BYTES):
            raise PluginException(
                cause=
                "Attachment filename provided but no attachment contents.",
                assistance="Please provide attachment contents.",
            )

        if params.get(Input.ATTACHMENT_BYTES) and params.get(
                Input.ATTACHMENT_FILENAME):
            self.connection.rest_client.add_attachment(
                issue.key,
                params.get(Input.ATTACHMENT_FILENAME),
                params.get(Input.ATTACHMENT_BYTES),
            )

        return {Output.ISSUE: output}