diff options
author | kongr45gpen <electrovesta@gmail.com> | 2014-05-11 13:52:29 +0300 |
---|---|---|
committer | kongr45gpen <electrovesta@gmail.com> | 2014-05-11 13:54:26 +0300 |
commit | 9b117389606bbe5c398c52bf7001c0324ba83183 (patch) | |
tree | f1bc94fef6b6ffa5c1587481d41306473e02a49b /local | |
parent | 32f28055bd0e6368f0b13c8d40e9fc11e18b8cef (diff) | |
download | supybot_github-9b117389606bbe5c398c52bf7001c0324ba83183.tar.gz supybot_github-9b117389606bbe5c398c52bf7001c0324ba83183.tar.bz2 supybot_github-9b117389606bbe5c398c52bf7001c0324ba83183.zip |
Handle travis hook messages
Diffstat (limited to 'local')
-rw-r--r-- | local/handler/GithubHandler.py | 7 | ||||
-rw-r--r-- | local/handler/TravisHandler.py | 15 | ||||
-rw-r--r-- | local/testing/ExpectationPluginTestCase.py | 23 | ||||
-rw-r--r-- | local/utility.py | 9 |
4 files changed, 45 insertions, 9 deletions
diff --git a/local/handler/GithubHandler.py b/local/handler/GithubHandler.py index 788ef94..fabe544 100644 --- a/local/handler/GithubHandler.py +++ b/local/handler/GithubHandler.py @@ -26,6 +26,7 @@ import PushHandler import WikiHandler import IssueHandler import StatusHandler +import TravisHandler import IssueCommentHandler class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler): @@ -89,7 +90,9 @@ class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler): msgs = [] - if 'pages' in data: + if 'matrix' in data: + msgs = TravisHandler.handle(data) + elif 'pages' in data: msgs = WikiHandler.handle(data) elif 'state' in data: msgs = StatusHandler.handle(data) @@ -101,7 +104,7 @@ class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler): else: msgs = IssueHandler.handle(data) else: - msgs.append( ircmsgs.privmsg(channel, "Something happened")) + msgs.append("Something happened") saveMessages(msgs) diff --git a/local/handler/TravisHandler.py b/local/handler/TravisHandler.py new file mode 100644 index 0000000..a8a8d86 --- /dev/null +++ b/local/handler/TravisHandler.py @@ -0,0 +1,15 @@ +from ..utility import * + +def handle(data): + msgs = [] + + msgs.append( "%s: The build %s * %s by %s (%s - %s)" % ( + ircutils.bold(data['repository']['name']), + colorAction(data['status_message'].lower()), + ircutils.bold(data['commit'][0:6]), + ircutils.mircColor(data['author_name'], "green"), + ircutils.mircColor(maxLen(data['message'].splitlines()[0], 50), "dark gray"), + getShortURL(data['build_url']) + )) + + return msgs diff --git a/local/testing/ExpectationPluginTestCase.py b/local/testing/ExpectationPluginTestCase.py index af6e56d..9027927 100644 --- a/local/testing/ExpectationPluginTestCase.py +++ b/local/testing/ExpectationPluginTestCase.py @@ -2,6 +2,8 @@ from supybot.log import info from supybot.test import * +from copy import deepcopy + from sys import stdout from time import sleep @@ -40,7 +42,7 @@ class ExpectationPluginTestCase(PluginTestCase): for error in errors: print "- Failed to assert that %s" % (error,) print tcolors.ENDC - self.fail() + self.fail("%i assertions failed while describing %s" % (len(errors), query)) def sendRequest(self, file): """ Opens the `samples` folder and sends a file as a request @@ -87,11 +89,22 @@ def it(): class Expectation: def __init__(self): self.error = '' + self.negation = False + self.should = self self.to = self + self.should_not = self.negate() def evaluate(self): - return self.assertion() + if self.negation is True: + return not self.assertion() + else: + return self.assertion() + + def negate(self): + other = deepcopy(self) + other.negation = not other.negation + return other def cleanReply(self): return clean(self.reply) @@ -105,7 +118,11 @@ class Expectation: def contain(self, what): self.assertion = self.contains self.assertionParameter = what - self.summary = "'%s' contains '%s'" + if self.negation: + verb = "does not contain" + else: + verb = "contains" + self.summary = "'%s' " +verb+ " '%s'" return self def contains(self, flags=re.I): diff --git a/local/utility.py b/local/utility.py index 5aa8724..fa8ca28 100644 --- a/local/utility.py +++ b/local/utility.py @@ -41,7 +41,8 @@ def maxLen(msg, maxn=400): def colorAction(action): """Give an action string (e.g. created, edited) and get a nice IRC colouring""" - if action == "created" or action == "opened" or action == "tagged" or action == "success": + if action == "created" or action == "opened" or action == "tagged" or \ + action == "success" or action == "passed": return ircutils.bold(ircutils.mircColor(action, "green")) if action == "deleted" or action == "closed" or action == "re-tagged" or \ action == "deleted tag" or action == "failed" or action == "errored" or \ @@ -73,9 +74,9 @@ def saveMessages(msgs): globals.messageList = msgs def clean(string): - """Strips IRC control characters from a string""" - regex = re.compile("(([\x02\x1f\x16\x0f])|(\x03(?:\d{1,2}(?:,\d{1,2})?)?))", re.UNICODE) - return regex.sub('', string) + """Strips IRC control characters from a string""" + regex = re.compile("(([\x02\x1f\x16\x0f])|(\x03(?:\d{1,2}(?:,\d{1,2})?)?))", re.UNICODE) + return regex.sub('', string) # Possible colours: # white, black, (light/dark) blue, (light) green, red, brown, purple, |