GitHub-Jira Integration via Webhooks
Kundan Antyakula
DevSecOps | AWS Certified (2x) | GitHub Certified (1x) | Kubernetes & Containerization | CI/CD & Infrastructure Automation | Driving Secure & Scalable DevOps Solutions
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
# 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=(",", ": ")))
Now, Let's Create Flask API integrating with github web hook which further creates backlog ticket on jira
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.
领英推荐
what if we keep something after / ?
It will display 404 error because of app route decorator limiting with ‘/‘.
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)
Select radio button -> Let me select individual events -> Issue Comments
Click on New issue -> Add Comment
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.