Ejemplo n.º 1
0
def addJiraticket(token, project_name, serverURL):

    jira = JIRA(basic_auth=('*****@*****.**', token),
                options={'server': serverURL})

    # sdi = {"id": "3"},
    # rti = {'name': 10010},
    summary = "working",
    description = "kdjsfg"

    options = {
        "serviceDeskId": "4",
        "requestTypeId": 10020,
        "requestFieldValues": {
            "summary": "Request JSD help via jsd task",
            "description": "I need a ne mouse for my Mac"
        },
        "assignee": "Jenny G"
    }

    issue = jira.create_customer_request(options)
Ejemplo n.º 2
0
    def run(
        self,
        username: str = None,
        access_token: str = None,
        server_url: str = None,
        service_desk_id: str = None,
        issue_type: int = None,
        summary: str = None,
        description: str = None,
    ) -> None:
        """
        Run method for this Task. Invoked by calling this Task after initialization within a
        Flow context, or by using `Task.bind`.

        Args:
            - username(str): the jira username, provided with a Prefect secret (defaults to
                JIRAUSER in JIRASECRETS)
            - access_token (str): a Jira access token, provided with a Prefect secret (defaults
                to JIRATOKEN in JIRASECRETS)
            - server_url (str): the URL of your atlassian account e.g.
                "https://test.atlassian.net".  Can also be set as a Prefect Secret. Defaults to
                the one provided at initialization
            - service_desk_id(str):  the key for your jira project; defaults to the one
                provided at initialization
            - issue_type (str, optional): the type of issue you want to create;
            - summary (str, optional): summary or title for your issue; defaults to the one
                provided at initialization
            - description (str, optional): description or additional information for the issue;
                defaults to the one provided at initialization

        Raises:
            - ValueError: if a `service_desk_id`, `request_type`, or `summary` are not provided

        Returns:
            - None
        """
        try:
            from jira import JIRA
        except ImportError as exc:
            raise ImportError(
                'Using Jira tasks requires Prefect to be installed with the "jira" extra.'
            ) from exc

        jira_credentials = cast(dict, Secret("JIRASECRETS").get())

        if username is None:
            username = jira_credentials["JIRAUSER"]

        if access_token is None:
            access_token = jira_credentials["JIRATOKEN"]

        if server_url is None:
            server_url = jira_credentials["JIRASERVER"]

        if issue_type is None:
            raise ValueError("An issue_type must be provided")

        if service_desk_id is None:
            raise ValueError("A service desk id must be provided")

        if summary is None:
            raise ValueError("A summary must be provided")

        jira = JIRA(basic_auth=(username, access_token),
                    options={"server": server_url})

        options = {
            "serviceDeskId": service_desk_id,
            "requestTypeId": issue_type,
            "requestFieldValues": {
                "summary": summary,
                "description": description
            },
        }
        created = jira.create_customer_request(options)

        if not created:
            raise ValueError("Creating Jira Issue failed")