-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflaskcreatejiraticketbasedoninputfromgithub.py
More file actions
69 lines (57 loc) · 1.56 KB
/
flaskcreatejiraticketbasedoninputfromgithub.py
File metadata and controls
69 lines (57 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# This code sample uses the 'requests' library:
# http://docs.python-requests.org
import requests
from requests.auth import HTTPBasicAuth
import json
from flask import Flask,request
app = Flask(__name__)
# Define a route that handles GET requests
@app.route('/createJIRA', methods=['POST'])
def createJira():
data = request.get_json()
# Get the body from the comment only
comment_body = data.get("comment", {}).get("body", "")
if "/jira" not in comment_body:
return json.dumps({"message": "No /jira command in the comment. Skipping JIRA creation."}), 200
url = "https://thirupathicob.atlassian.net/rest/api/3/issue"
auth = HTTPBasicAuth("email", "APIKEY")
headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}
payload = json.dumps( {
"fields": {
"description": {
"content": [
{
"content": [
{
"text": "My first JIRA ticket.",
"type": "text"
}
],
"type": "paragraph"
}
],
"type": "doc",
"version": 1
},
"issuetype": {
"id": "10009"
},
"project": {
"key": "THIR"
},
"summary": "Creating first JIRA ticket",
},
"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=(",", ": "))
app.run('0.0.0.0',port=5000)