def prepare_jira_mapping()

in dusty/reporters/jira/legacy.py [0:0]


def prepare_jira_mapping(jira_service):
    """ Make Jira mapping (for projects that are using custom values) """
    if not jira_service or not jira_service.valid:
        return dict()
    jira_service.connect()
    issue_type = "Bug"
    if jira_service.fields["issuetype"]["name"] != "!default_issuetype":
        issue_type = jira_service.fields["issuetype"]["name"]
    project_priorities = get_project_priorities(
        jira_service.client,
        jira_service.project,
        issue_type
    )
    if not project_priorities:
        jira_service.client.close()
        return dict()
    logging.debug(
        "%s %s priorities: %s",
        jira_service.project, issue_type, str(project_priorities)
    )
    c = const
    mapping = dict()
    for severity in c.JIRA_SEVERITIES:
        if severity not in project_priorities:
            for alternative in c.JIRA_ALTERNATIVES[severity]:
                if alternative in project_priorities:
                    logging.warning(
                        "Mapping %s %s Jira priority: %s -> %s",
                        jira_service.project, issue_type,
                        severity, alternative
                    )
                    mapping[severity] = alternative
                    break
            if severity not in mapping:
                mapping[severity] = project_priorities[0]
                logging.error(
                    "Failed to find Jira mapping for %s, using %s as a fallback",
                    severity, mapping[severity]
                )
    jira_service.client.close()
    return mapping