-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjirahelper.py
69 lines (51 loc) · 2.1 KB
/
jirahelper.py
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
import json
import re
from ConfigParser import ConfigParser
import requests
from releaseissue import ReleaseIssue
config = ConfigParser()
config.read("./config.ini")
url = config.get('instance', 'url')
token = config.get('instance', 'token')
project_name = config.get('instance', 'project_name')
version = config.get('instance', 'version')
image_host = config.get('instance', 'image_host')
header_text = config.get('instance', 'header_text')
# Get release notes by pulling Jira issues tagged with the fix version
def get_issues():
query = '/rest/api/2/search?jql=fixVersion=%s' % version
resp = requests.get(url + query, headers={'Authorization': 'Basic %s' % token})
resp = json.loads(resp.text)
if 'issues' in resp:
issues = process_issues(resp['issues'])
return issues
else:
return
def process_issues(issues):
release_issues = []
for issue in issues:
release_issues.append(ReleaseIssue(issue['id'],
issue['key'],
issue['fields']['summary'],
truncate_field(issue['fields']['description']),
check_exists(issue, ('fields', 'assignee', 'displayName')),
'%s/browse/%s' % (url, issue['key'])))
return release_issues
# dealing with nested dict/json throwing KeyErrors if the key doesn't exist
def check_exists(d, l):
try: # try to get the value
return reduce(dict.__getitem__, l, d)
except KeyError: # failed
return None
except TypeError:
return None
# formatting fix for long descriptions with hyperlinks, images, etc..
def truncate_field(d):
if d:
regex = re.compile(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+')
urls = re.findall(regex, d)
for url in urls:
url_link = "<a href='%s'>%s...</a>" % (url, url[:20])
d = d.replace(str(url), str(url_link))
d = (d[:1021] + ' ...') if len(d) > 1024 and d else d
return d