-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-flask-jira.py
More file actions
58 lines (50 loc) · 1.66 KB
/
github-flask-jira.py
File metadata and controls
58 lines (50 loc) · 1.66 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
import requests
from requests.auth import HTTPBasicAuth
import json
from flask import Flask, request
app = Flask(__name__)
@app.route('/createJira', methods=['POST'])
def createJira():
url = "https://<your-jira-url>/rest/api/3/issue"
API_TOKEN = ""
auth = HTTPBasicAuth("<your-jira-account-email", API_TOKEN)
headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}
payload = json.dumps({
"fields": {
"description": {
"content": [
{
"content": [
{
"text": "First jira issue.",
"type": "text"
}
],
"type": "paragraph"
}
],
"type": "doc",
"version": 1
},
"project": {
"key": "SCRUM"
},
"issuetype": {
"id": "10006"
},
"summary": "Automated Jira issue creation"
},
"update": {}
})
data = request.json
if data and "comment" in data and "body" in data["comment"] and data["comment"]["body"] == "/jira":
response = requests.post(url, data=payload, headers=headers, auth=auth)
return json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": "))
else:
print('Jira issue will be created only if the comment includes /jira')
return "No Jira issue created."
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)