pythonjira

How to get the link/reference of a "Requirement" and "Testrail: Cases" from a JIRA entry via python API?


When using JIRA with TestRail and Confluence you can link a Requirement to a ticket and you can link a TestRail Test Case to a JIRA ticket. For example:

enter image description here

Now using the JIRA python module it is possible to get the ticket details using a code like

from jira import JIRA
myjira = JIRA(server="https://my.jiraserver.com/", basic_auth=(username, password))
issue = jira.issue("PROJ-1")
print(issue.raw)

and print all the details of the ticket. Unfortunately, there is no mention of the linked requirement "DALEX-REQ-001" or the TestRail TestCase "C155535"!

How can I use the JIRA API to get these two fields for the Requirement and the TestRail TestCase?


Solution

  • As it turns out, the references are used in JIRA by a tool/plug-in named "Yogi". There is a reference for these """Yogi""" requirements HERE.

    Then you have to guess how to create your query, and the following code does in deed finally return requirements information associated with a ticket:

    import requests
    from requests.auth import HTTPBasicAuth
    
    # Username and Password
    username = "your_username"
    password = "your_password"
    
    # Headers
    headers = {
        "Accept": "application/json",
        "Content-Type": "application/json"
    }
    
    # Complete JIRA URL
    jira_url = "https://my.jira-instance.com/rest/reqs/1/issuelinks/TEST-2619"
    
    # Make the GET request to fetch issue details
    response = requests.get(
        jira_url,
        headers=headers,
        auth=HTTPBasicAuth(username, password)
    )
    print(response.json())