-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbugs.py
76 lines (63 loc) · 2.33 KB
/
bugs.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
74
75
76
import bugzilla
import csv
from errbot import BotPlugin, botcmd
import sys
class Bugzilla(BotPlugin):
"""Example 'Hello, world!' plugin for Errbot"""
def __init__(self, bot, name=None):
super(self.__class__, self).__init__(bot, name)
self.URL = "bugzilla.redhat.com"
self.users = {}
with open("users.csv") as f:
reader = csv.reader(f)
for row in reader:
self.users[row[0]] = row[1]
@botcmd
def bzqa(self, msg, args):
"""Returns the number of bugs with the status defined
as the first argument where the requester is the QA contact
Example: !qa ON_QA
"""
args = args.split()
nick = str(msg.nick)
if len(args) < 1:
response = self.usage('bzqa')
return response
else:
status = args[0]
if status not in ['ON_QA', 'NEW', 'ON_DEV']:
response = "Unrecognized status %s" % status
elif nick in self.users:
bzapi = bugzilla.Bugzilla(self.URL)
query = bzapi.build_query(qa_contact=self.users[nick],
status=status)
bugs = bzapi.query(query)
response = ("%s: You have %d bugs with status %s which you are "
"the QA Contact" % (nick, len(bugs), status))
else:
response = ("%s: You are not registred to bugs query."
"Please use !bzregister <email> to register" % nick)
return response
@botcmd
def bzregister(self, msg, args):
""" Register a nick name with an email used in Bugzilla
Example: !bzregister user@example.com
"""
args = args.split()
nick = str(msg.nick)
if len(args) < 1:
response = self.usage('bzregister')
return response
else:
email = args[0]
row = [nick, email]
with open("users.csv", 'a') as f:
writer = csv.writer(f)
writer.writerow(row)
self.users[nick] = email
response = "%s: Registration successful!" % nick
return response
def usage(self, command):
usage_dict = {'bzqa': 'Usage: !bzqa <status>',
'bzregister': 'Usage: !bzregister <email>'}
return usage_dict.get(command)