GitHub-Jira Integration via Webhooks
Project Workflow

GitHub-Jira Integration via Webhooks

In a Nutshell - This Project Trigger's New Jira ticket for every issue created in github with prompt /jira.

Real Time Use Case Elucidation -

When there is a development team that owns this GitHub repository, and issues are created by QE Engineers or developers from other teams using this project. These issues can range from genuine problems to configuration errors. To manage this, developers want to review the issues, and if a developer identifies a legitimate issue, they can accept it. The developer wants to track all work related to the issue on a Jira board or as a Jira ticket for future reference, such as for reporting to a manager.

However, triaging and manually creating Jira tickets for numerous GitHub issues daily is cumbersome. Thus, the developers asked the DevOps team to automate this process. The automation would allow a developer to simply comment "/jira" on a GitHub issue, which would then automatically create a corresponding issue in the Jira backlog, complete with all relevant details from the GitHub issue.

For example, currently, the Jira backlog is empty. When a developer comments "/jira" on a GitHub issue and refreshes the Jira backlog, the new issue appears with all pertinent details, such as who created the issue and the problem description. This project focuses on automating the integration between GitHub and Jira.

Lastly , this project aims to automate the integration of GitHub and Jira, allowing for seamless issue tracking and management.

Project END-TO-END Explanation:

To implement this project

  1. Firstly, Create an API token in your Atlassian account.
  2. AWS Free Tier Account
  3. Offcourse, Github Account ??

Navigate to manage Custom Filters in your Project
select story then you will be getting project id in the web link on top of the web page
Similar to this the last one is the issue type id in the code
Now hover on projects , Project key will be KUN


# This code sample uses the 'requests' library:
# https://docs.python-requests.org
import requests
from requests.auth import HTTPBasicAuth
import json

url = "https://kundan-antyakula.atlassian.net/rest/api/3/issue"

APITOKEN = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth = HTTPBasicAuth("[email protected]", APITOKEN)

headers = {
  "Accept": "application/json",
  "Content-Type": "application/json"
}

payload = json.dumps( {
  "fields": {
    
    "description": {
      "content": [
        {
          "content": [
            {
              "text": "Order entry fails when selecting supplier.",
              "type": "text"
            }
          ],
          "type": "paragraph"
        }
      ],
      "type": "doc",
      "version": 1
    },
   
    "issuetype": {
      "id": "10006"
    },

    "project": {
      "key": "KUN"
    },

    "summary": "first jira ticket",
    
  },
  "update": {}
} )

response = requests.request(
   "POST",
   url,
   data=payload,
   headers=headers,
   auth=auth
)

print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))        


Output will be similar to this indicating that it created a jira ticket
This is the backlog created using above code

Now, Let's Create Flask API integrating with github web hook which further creates backlog ticket on jira

  • Create an Ec2 ubuntu instance.
  • Create Flask app returning hello world

from flask import Flask
app = Flask(__name__) #creating flask app instance

@app.route("/") 
# decorator purpose is before invoking function it perform action
#if someone is working on API but before he needs to be authenticated so #decorator can be used in such circumstances
#similarly here if someone wants to access this hello API are they trying to access #on particular path or not.

def fl():
    return "first flask"

app.run('0.0.0.0')

#to build we need server but flask has inbuilt development server without deploying #on tomcat.        
Dev server returing first flask text returned to the function fl


what if we keep something after / ?

It will display 404 error because of app route decorator limiting with ‘/‘.

@app.route("/")?this decorator is not letting us enter anything after / can only accesed before /


Integrate above flask code with GET code from jira first program & convert into POST method as we need post operation performed to push issues through /jira in github issues & automatically generate backlog ticket/issue in jira .

Run this code on the ec2 instance

# This code sample uses the 'requests' library:
# https://docs.python-requests.org
import requests
from requests.auth import HTTPBasicAuth
import json
from flask import Flask

app = Flask(__name__)

# Define a route that handles GET requests
@app.route('/createJira', methods=['POST'])
def createJira():

    url = "https://kundan-antyakula.atlassian.net/rest/api/3/issue"


    auth = HTTPBasicAuth("[email protected]", API_TOKEN)

    headers = {
        "Accept": "application/json",
        "Content-Type": "application/json"
    }

    payload = json.dumps( {
        "fields": {
        "description": {
            "content": [
                {
                    "content": [
                        {
                            "text": "Order entry fails when selecting supplier.",
                            "type": "text"
                        }
                    ],
                    "type": "paragraph"
                    }
                ],
            "type": "doc",
             "version": 1
        },
        "project": {
           "key": "KUN"
        },
        "issuetype": {
            "id": "10006"
        },
        "summary": "Main order flow broken",
    },
    "update": {}
    } )


    response = requests.request(
        "POST",
        url,
        data=payload,
        headers=headers,
        auth=auth
    )

    return json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": "))

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)        
Output of the above code

  1. Navigate to Github Repo settings
  2. Now, Add web hook from public dns of EC2 instance.

Be extra cautious while entering payload URL make sure port no and Create Jira added in code is similar.


Select radio button -> Let me select individual events -> Issue Comments


Click on Add webhook


Click on New issue -> Add Comment


"Main order flow broken" issue is generated in jira automatically.


In summary, this project has shown the potential of using GitHub webhooks to automate Jira workflows. Moving forward, we can explore integrating these technologies to streamline our development process. Future directions may involve expanding automated workflows and exploring integrations with other tools and services.

要查看或添加评论,请登录

Kundan Antyakula的更多文章

社区洞察

其他会员也浏览了