-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrredmine.py
69 lines (53 loc) · 1.63 KB
/
rredmine.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
#!/usr/bin/env python
import re
import sys
import traceback
import redmine
from tabulate import tabulate
from response import Response
import config
if config.redmine_key:
from redmine import Redmine,ResourceNotFoundError
redmine = Redmine(config.redmine_url, key=config.redmine_key)
else:
redmine = None
def link_redmine(mattermost_request):
text = mattermost_request.text
answer = ""
text = ''.join(text).encode('latin1')
ids = re.findall('#([0-9]+)', text)
if (len(ids) < 1):
return Response("no issue IDs found")
answer = ""
for issue in ids:
issue_data = get_data(issue)
header = issue_data[0]
rows = issue_data[1:]
answer += tabulate(rows, header, tablefmt="pipe")
answer += "\n"
return Response(answer)
def get_data(issue_id):
data = []
url = config.redmine_url + "issues/" + str(issue_id)
data.append(["link", url])
if not redmine:
return data
try:
i = redmine.issue.get(issue_id)
except ResourceNotFoundError as e:
data.append(["**ERROR**", "issue_id not found ${}".format(issue_id)])
traceback.print_exc(file=sys.stdout)
return data
except:
data.append(["**ERROR**", "Unable to get data for issue_id ${}".format(issue_id)])
traceback.print_exc(file=sys.stdout)
return data
data.append(["subject", i.subject])
data.append(["author", i.author.name])
if not hasattr(i, 'assigned_to'):
name = "Nobody"
else:
name = i.assigned_to.name
data.append(["assigned to", name])
data.append(["status", i.status.name])
return data