Created
September 27, 2014 00:27
-
-
Save tempusfrangit/5c5a841098122c513301 to your computer and use it in GitHub Desktop.
Keystone Untriaged Bug Report Bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import itertools | |
import socket | |
import time | |
from launchpadlib import uris | |
from launchpadlib.launchpad import Launchpad | |
def get_untriaged_bugs(projects=None): | |
if projects is None: | |
projects = [ | |
'keystone', | |
'python-keystoneclient', | |
'keystonemiddleware', | |
] | |
lp = Launchpad.login_anonymously( | |
'keystone-untriaged-bot', | |
service_root=uris.LPNET_SERVICE_ROOT | |
) | |
links = {} | |
for name in projects: | |
project = lp.projects[name] | |
undecided = project.searchTasks(importance='Undecided') | |
new = project.searchTasks(status='New') | |
for bug in itertools.chain(iter(undecided), iter(new)): | |
# incomplete bugs with additional comments from the owner are worth | |
# looking one more time :) | |
if bug.status == 'Incomplete': | |
for comment in bug.bug.messages.entries[2:]: | |
if comment['owner_link'] == bug.owner.self_link: | |
links.setdefault(project, set()).add(bug.web_link) | |
break | |
else: | |
pass | |
else: | |
links.setdefault(project, set()).add(bug.web_link) | |
return links | |
def send_update(msg, channel='#openstack-keystone', user='ks-untriaged-bot'): | |
s = socket.socket() | |
s.connect(('irc.freenode.net', 6667)) | |
try: | |
commands = [ | |
('NICK %s', user), | |
('USER %s %s %s :%s', (user, user, user, user)), | |
('JOIN %s', channel), | |
] | |
for line in msg.splitlines(): | |
if line: | |
commands.append(('PRIVMSG %s :%s', (channel, line))) | |
commands.append(('QUIT', ())) | |
for (command, args) in commands: | |
s.send(command % args + '\r\n') | |
time.sleep(2) # FIXME: without this sleep freenode will close the connection for some reason | |
finally: | |
s.close() | |
def main(): | |
links = get_untriaged_bugs() | |
msg = '' | |
for proj in links.keys(): | |
if proj: | |
msg += 'Untriaged bugs for project %s:\n' % str(proj).rsplit('/', 1)[-1] | |
msg += '\n'.join(links[proj]) | |
msg += '\n' | |
#msg += '\n' | |
#print msg | |
if msg: | |
send_update(msg) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment