-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathggithub.py
73 lines (58 loc) · 1.65 KB
/
ggithub.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
70
71
72
73
#!/usr/bin/env python
import re
from tabulate import tabulate
import github
from response import Response
import config
commands = {}
def handle(mattermost_request):
text = mattermost_request.text[0]
text = text.strip()
try:
(command, arg) = text.split(' ', 1)
except ValueError:
command = text
arg = ""
try:
global commands
func = commands[command]
except KeyError:
return Response("Unknown command: " + command)
return Response(func(arg))
def issue(arg):
arg = arg.strip()
if len(arg) == 0:
return "error: missing arguments"
if ' ' in arg:
(project, issue) = arg.split(' ')
issue = issue.lstrip('#')
else:
print arg
try:
(project, issue) = re.search('([^/]+/[^/]+)/issues/(\d+)', arg).groups()
except AttributeError:
return "error: no url found"
issue = int(issue)
hub = github.Github()
repo = hub.get_repo(project)
try:
issue = repo.get_issue(issue)
except github.UnknownObjectException:
return "Issue not found"
header = ["Link", issue.html_url]
rows = []
rows.append(['Title', issue.title])
rows.append(['State', issue.state])
assignee = issue.assignee
if not assignee:
name = "No one assigned"
else:
name = "{} ({})".format(assignee.login, assignee.name)
rows.append(['Assignee', name])
if issue.labels:
labels = ""
for label in issue.labels:
labels += label.name + " "
rows.append(["Labels", labels])
return tabulate(rows, header, tablefmt="pipe")
commands['issue'] = issue