The Jira and GitHub integration synchronizes development across tools and leverages automation to eliminate manual steps and reduce delivery time. By integrating GitHub code with Jira projects, developers can focus less on updates and more on creating amazing products.

OBJECTIVE:

To configure github with jira through pytest to update results on jira tickets, When Merging a Pull Request the github workflow will be executed, After the workflow execution the status of the jira tickets will be updated as per the result of github workflow execution through pytest

What is Jira?

Jira is a web application used as tracking tools for tasks like epicstorybugs and so on. Jira is available as an open source and paid version.

Why do we use Jira ?

It is used for various kinds of projects like business projects, software projects and service projects

Applications like Github, slack, jenkins, zendesk etc can be integrated with jira. By using jira a ticket can be created for each type of task to monitor application development, 

Here we integrate Github with jira through the pytest framework.

What is Pytest ?

Pytest is an automation testing framework in python which is used for testing software applications.

Why do we use Pytest ?

Pytest is a python framework, using pytest we can create TDD, BDD as well as Hybrid testing framework used for automation testing like UI, REST API and it is flexible for supporting different actions.

Here we are going to execute the test cases that are triggered from the github actions workflow and update the particular jira tickets based on the workflow execution results.

What is Rest API ?

REST is abbreviated as (Representational State Transfer) it is an architectural style for interacting between the client and the server, the client sends the request and a response is received from the server in of JSON, XML, or HTML, but json is most commonly used response type because it is readable for both human and machine.

Here we interact with the Jira through Rest API, the API Endpoints we are using to interact with Jira is given below

EXECUTION FLOW OF GITHUB FOR JIRA THROUGH PYTEST

To update the jira tickets through pytest, we need to know about the Github workflow execution, Jira Rest API endpoints, pytest configurations

Things we need to know for execution:

  • To create a github workflow file to execute pytest test cases when a PR is merged
  • To configure pytest test cases with jira API endpoints to send the workflow results

JIRA REST API ENDPOINTS

Prerequisites for Jira API Integration:

Steps to create API Token:

  • STEP 1: Login to Jira with the registered Email ID Use this link https://id.atlassian.com/login to login into the jira
  • STEP 2: Click on your jira Profile and click on manage accounts in the popup

STEP 3: Click on Security tab and click create and manage API token

STEP 4: Click on create API Token button:

STEP 5: Provide a label for the token and click create, a new API Token will be generated Copy the token and save the token in a separate file because you cant able to get the same token again

Encoding the API Token:

Encoding the Api token can be done in the terminal, to create a base64 encoded token use the following command

In LINUX/ mac-os:

In Windows:

You can use the link below to encode the api token online

https://www.base64encode.org/

GET Transition ID API:

  • GET:

https://<JIRA_DOMAIN>.atlassian.net/rest/api/2/issue/<TICKET-ID>/transitions

By using this API we can get all the transition details like transition ID transition name The transition ID is default for To-Do, In-progress and Done status, the curl command is given below

Transition Status Transition ID
To-Do 11
In-Progress 21
Done 31
Issue 1 2
Issue 2 3

Update Transition Status API:

Post :

https://<JIRA_DOMAIN>.atlassian.net/rest/api/2/issue/<TICKET-ID>/transitions

This API Endpoint is used to update the transition status of the jira ticket.

Ticket ID is passed in the path param and the Transition ID is passed in the body of the request, The status of the ticket will be updated with respect to the transition id, Curl for the following API endpoint is mentioned below, The Transition ID can be obtained by using the Get transition ID API, which is mentioned above

Add Attachments API:

Post:

https://<JIRA_DOMAIN>.atlassian.net/rest/api/2/issue/<TICKET-ID>/attachments

This API endpoint is used to add the attachment in a JIRA ticket according to the given Ticket ID and passed file. Use the below curl command

Search API:

GET:

https://<jira_domain>.atlassian.net/rest/api/2/search

This API Endpoint is used to get the ticket information using the Jira Query Language (JQL) syntax, the JQL should be passed as an parameter to this API, By using this API we can get the information of all/any of the ticket, An example for JQL to get the ticket information using PR Link which is mentioned in the Github info paragraph field of a jira ticket

Example for JQL:

CONFIGURING GITHUB WITH JIRA:

There are two ways in configuring github with jira, one is by providing the PR link in a separate field of jira ticket and the other way is by configuring github app in jira

   1. Configuring jira with PR link:

  • We can able to identify the ticket information by providing the PR link in a Jira ticket
  • PR Link should be provided in the custom field of Jira ticket
  • After placing the PR link in custom field, we need to use the Jira Search API endpoint through Jira Query Language(JQL) syntax

   2. Steps to configure PR link in Jira Ticket on custom field:

  • Go to Project Board > Project settings Issue types
  • Select the Paragraph field type  Enter the field name and description
  • Click Save changes

   3. Configure github app with jira:

  • To configure Github with jira,Login into Jira, go to Apps➡ Manage Your apps
  • Select Github for jira ➡ click connect github organization
  • CLICK Install github for jira on new organization
  • On clicking Install github for jira on new organization select the github organization in which you want to install jira
  • Select repository which you want to configure and click install
  • Now you can see your git repository that have been configured in the github for jira tab

UPDATING EXECUTION RESULTS TO JIRA TICKET USING PYTEST:

  • All the test cases and the reports report generation for all the test cases are done using pytest
  • After the Workflow execution, the build status and PR link will be added as comments and the reports will be added as attachments to the jira ticket, this is done by the pytest fixture. The pytest fixture is used to execute the conditions before and after the execution of test case, the yield keyword is used to execute the conditions after the execution of all test cases
  • The teardown module() method calls the Jira API Endpoints for Adding Comments and Attachments.
Posted in Technologies