Skip to content

feat/Possible improvements to the Jira connector #62

Open
@DanielBarbosabit

Description

@DanielBarbosabit

Is your feature request related to a problem? Please describe.
Currently, it is only possible to connect to Jira Cloud and not to Jira Server and it is also not possible to control the maximum number of issues collected per project, using the SimpleJiraConfig class described in the documentation.

Describe the solution you'd like
Using the Jira connector to collect Issues data from an internally hosted Jira Server, we found some points of improvement that would allow this integration to work properly.

  1. Allow authentication via the token API parameter, as authentication is currently only targeted to Jira Cloud. Thus, it would be interesting if the "create_jira_object" function allowed these two forms of authentication, one of them being aimed at Jira Cloud and the other for Jira Enterprise server. The suggestion below was built based on this documentation.
@requires_dependencies(["atlassian"], extras="jira")
def create_jira_object(url, user_email, api_token, cloud):
    """
    Creates a jira object for interacting with Jira Cloud.
    Args:
        url: URL to Jira Cloud organization
        user_email: Email for the user with the permissions
        api_token: API Token, generated for the user
        cloud: Type of Jira instance.
            If True: A Jira Cloud should be accessed.
            If False: A Jira Server shoud be accessed.

    Returns:
        Jira object
    """
    from atlassian import Jira

    if cloud:
        jira = Jira(
            url,
            username=user_email,
            password=api_token,
        )
    else:
        jira = Jira(
            url,
            token=api_token,
        )

    response = jira.get_permissions("BROWSE_PROJECTS")
    permitted = response["permissions"]["BROWSE_PROJECTS"]["havePermission"]

    if permitted:
        return jira

    else:
        raise ValueError(
            """The user with the provided *user_email* and the *api_token*
                         is not permitted to browse projects for the jira organization
                         for the provided *url*. Try checking user_email, api_token,
                         and the url arguments.""",
        )
  1. It is not possible to configure the maximum number of Issues to be collected from a project in the "SimpleJiraConfig" class. Thus, a project that has more than 100 issues needs all issues to have information collected to be referenced in the "issue" parameter of the class, which is not very practical. Just to perform a test, the parameter "" was included in the _get_issues_with_scroll method of the JiraSourceConnector class in order to increase the number of issues of a single project, as shown in the code snippet below.
    @requires_dependencies(["atlassian"], extras="jira")
    def _get_issues_within_one_project(
        self,
        project_id: str,
    ):
        get_issues_with_scroll = scroll_wrapper(self.jira.get_all_project_issues)
        results = get_issues_with_scroll(project=project_id, fields=["key"], number_of_items_to_fetch=200)

        return [(issue["key"], issue["id"], None) for issue in results]

Describe alternatives you've considered
Some alternatives have been mentioned above.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions