Created
September 20, 2014 23:13
-
-
Save dims/7289b48e58dadcd81123 to your computer and use it in GitHub Desktop.
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 = [ | |
'diskimage-builder', | |
'os-apply-config', | |
'os-collect-config', | |
'os-refresh-config', | |
'python-tuskarclient', | |
'tripleo', | |
'tuskar', | |
] | |
lp = Launchpad.login_anonymously( | |
'tripleo-untriaged-bot', | |
service_root=uris.LPNET_SERVICE_ROOT | |
) | |
links = set() | |
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.add(bug.web_link) | |
break | |
else: | |
pass | |
else: | |
links.add(bug.web_link) | |
return links | |
def send_update(msg, channel='#tripleo', user='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() | |
if links: | |
msg = 'Untriaged bugs so far:\n' + '\n'.join(links) | |
else: | |
msg = 'No untriaged bugs so far! \o/' | |
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