aboutsummaryrefslogtreecommitdiffstats
path: root/local/handler
diff options
context:
space:
mode:
authorkongr45gpen <electrovesta@gmail.com>2014-12-31 17:05:05 +0200
committerkongr45gpen <electrovesta@gmail.com>2014-12-31 17:05:05 +0200
commitafdb8a96e0b4adb612560ad241f288c7761af73a (patch)
tree0a3924c9785e0872d707175cf44aee8fdecedc30 /local/handler
parentd7e9c2b03f552193e2d8ccbcfc44987c659fc469 (diff)
downloadsupybot_github-afdb8a96e0b4adb612560ad241f288c7761af73a.tar.gz
supybot_github-afdb8a96e0b4adb612560ad241f288c7761af73a.tar.bz2
supybot_github-afdb8a96e0b4adb612560ad241f288c7761af73a.zip
Add support for different themes
Diffstat (limited to 'local/handler')
-rw-r--r--local/handler/GithubHandler.py36
-rw-r--r--local/handler/IssueCommentHandler.py56
-rw-r--r--local/handler/IssueHandler.py51
-rw-r--r--local/handler/PushHandler.py126
-rw-r--r--local/handler/StatusHandler.py18
-rw-r--r--local/handler/TravisHandler.py26
-rw-r--r--local/handler/WikiHandler.py55
7 files changed, 153 insertions, 215 deletions
diff --git a/local/handler/GithubHandler.py b/local/handler/GithubHandler.py
index f095ec8..dfa024c 100644
--- a/local/handler/GithubHandler.py
+++ b/local/handler/GithubHandler.py
@@ -29,6 +29,8 @@ import StatusHandler
import TravisHandler
import IssueCommentHandler
+from .. import theme as themes
+
class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_POST(s):
"""Respond to a POST request."""
@@ -90,31 +92,47 @@ class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler):
s.wfile.write("The password is wrong")
return
- irc = {}
- # Handle different event types
+ themeName = configValue('theme')
+
+ alphanumericPattern = re.compile('[\W_]+')
+ themeClass = ''.join([alphanumericPattern.sub('', themeName).title(), 'Theme'])
+ try:
+ mod = getattr(themes, themeClass)
+ klass = getattr(mod, themeClass)
+ except AttributeError:
+ # The theme was not found
+ log.error("The '%s' theme was not found" % themeName)
+ klass = themes.DefaultTheme.DefaultTheme
+
+ theme = klass()
+
+ #
+ # Handle different event types
+ #
msgs = []
+ theme.msgs = msgs
if 'matrix' in data:
- msgs = TravisHandler.handle(data)
+ TravisHandler.handle(data, theme)
elif 'pages' in data:
- msgs = WikiHandler.handle(data)
+ WikiHandler.handle(data, theme)
elif 'state' in data:
- msgs = StatusHandler.handle(data)
+ StatusHandler.handle(data, theme)
elif 'commits' in data:
- msgs = PushHandler.handle(data)
+ PushHandler.handle(data, theme)
elif 'issue' in data:
if 'comment' in data:
- msgs = IssueCommentHandler.handle(data)
+ IssueCommentHandler.handle(data, theme)
else:
- msgs = IssueHandler.handle(data)
+ IssueHandler.handle(data, theme)
else:
msgs.append("Something happened")
+ theme.finalize()
saveMessages(msgs)
- #msgs.append( ircmsgs.privmsg("#main", "%s" % ()) )
if not world.testing:
for msg in msgs:
for irc in world.ircs:
diff --git a/local/handler/IssueCommentHandler.py b/local/handler/IssueCommentHandler.py
index ba6d846..e0084f3 100644
--- a/local/handler/IssueCommentHandler.py
+++ b/local/handler/IssueCommentHandler.py
@@ -1,39 +1,23 @@
from ..utility import *
-def handle(data):
- msgs = []
-
- url = getShortURL(data['comment']['html_url'])
-
- creator = ''
- if data['sender']['login'] != data['issue']['user']['login']:
- creator = " by %s" % (ircutils.mircColor(data['issue']['user']['login'],"green"),)
-
+def handle(data, theme):
milestone = ''
- if data['issue']['milestone'] and configValue("showMilestone"):
- milestone = ircutils.mircColor(" (%s" % (data['issue']['milestone']['title']),"brown")
-
- if milestone:
- oparen = '- '
- else:
- oparen = '('
-
- lines = data['comment']['body'].splitlines()
- line = lines[0]
- if len(line) > 70:
- line = "%s..." % (line[0:67])
- elif len(lines) > 1:
- line += "..."
-
- msgs.append( "%s: %s commented on issue %s \"%s\"%s%s %s%s): %s" % (
- ircutils.bold(data['repository']['name']),
- ircutils.mircColor(data['comment']['user']['login'], "green"),
- ''.join(["#",str(data['issue']['number'])]),
- ircutils.bold(data['issue']['title']),
- creator,
- milestone,
- oparen, url,
- line
- ))
-
- return msgs
+ if configValue("showMilestone") and 'milestone' in data['issue'] and data['issue']['milestone']:
+ milestone = data['issue']['milestone']['title']
+
+ assignee = ''
+ if 'assignee' in data['issue'] and data['issue']['assignee']:
+ assignee = data['issue']['assignee']['login']
+
+ theme.issue(
+ repo = data['repository']['name'],
+ actor = data['comment']['user']['login'],
+ action = 'commented on',
+ comment = data['comment']['body'],
+ issueNo = data['issue']['number'],
+ issueTitle = data['issue']['title'],
+ creator = data['issue']['user']['login'],
+ milestone = milestone,
+ url = getShortURL(data['comment']['html_url']),
+ assignee = assignee
+ )
diff --git a/local/handler/IssueHandler.py b/local/handler/IssueHandler.py
index 1ae9a6d..df07a9c 100644
--- a/local/handler/IssueHandler.py
+++ b/local/handler/IssueHandler.py
@@ -1,37 +1,22 @@
from ..utility import *
-def handle(data):
- msgs = []
-
- url = data['issue']['url']
-
- if data['issue']['assignee'] and data['sender']['login'] == data['issue']['assignee']['login']:
- senderColor = "green"
- else:
- senderColor = "dark grey"
-
- creator = ''
- if data['sender']['login'] != data['issue']['user']['login']:
- creator = " by %s" % (ircutils.mircColor(data['issue']['user']['login'],"green"),)
-
+def handle(data, theme):
milestone = ''
if data['issue']['milestone'] and configValue("showMilestone"):
- milestone = ircutils.mircColor(" (%s" % (data['issue']['milestone']['title']),"brown")
-
- if milestone:
- oparen = '- '
- else:
- oparen = '('
-
- msgs.append( "%s: %s %s issue %s \"%s\"%s%s %s%s)" % (
- ircutils.bold(data['repository']['name']),
- ircutils.mircColor(data['sender']['login'], senderColor),
- colorAction(data['action']),
- ''.join(["#",str(data['issue']['number'])]),
- ircutils.bold(data['issue']['title']),
- creator,
- milestone,
- oparen, url
- ))
-
- return msgs
+ milestone = data['issue']['milestone']['title']
+
+ assignee = ''
+ if 'assignee' in data['issue'] and data['issue']['assignee']:
+ assignee = data['issue']['assignee']['login']
+
+ theme.issue(
+ repo = data['repository']['name'],
+ actor = data['sender']['login'],
+ action = data['action'],
+ issueNo = data['issue']['number'],
+ issueTitle = data['issue']['title'],
+ creator = data['issue']['user']['login'],
+ milestone = milestone,
+ url = getShortURL(data['issue']['url']),
+ assignee = assignee
+ )
diff --git a/local/handler/PushHandler.py b/local/handler/PushHandler.py
index 96b9339..19bc436 100644
--- a/local/handler/PushHandler.py
+++ b/local/handler/PushHandler.py
@@ -1,16 +1,10 @@
from ..utility import *
-def handle(data):
- msgs = []
-
+def handle(data, theme):
commitno = len(data['commits'])
ref = data['ref'].split('/',2)
branch = ref[2]
- colon = ''
- if data['commits']:
- colon = ':'
-
isTag = False
isMerge = False
@@ -24,14 +18,11 @@ def handle(data):
if ref[1] == 'tags':
isTag = True
- urls = ' (%s)' % (getShortURL(data['compare']),)
+ urls = getShortURL(data['compare'])
if 'base_ref' in data:
base_ref = data['base_ref'].split('/',2)
baseBranch = base_ref[2]
- if isTag:
- branchFrom = '%s %s ' % (baseBranch, ircutils.bold('*'))
- else:
- branchFrom = ' from %s' % (ircutils.bold(ircutils.mircColor(baseBranch, "blue")), )
+ branchFrom = baseBranch
if (data['created'] and data['deleted']) or (not data['created'] and not data['deleted'] and data['forced']):
if isTag:
@@ -67,58 +58,47 @@ def handle(data):
isMerge = True
if configValue("hidePush",None) == False and not branched:
- msgs.append( "%s @ %s: %s pushed %s %s (%s)%s" % (
- ircutils.bold(ircutils.mircColor(branch, "blue")),
- ircutils.bold(data['repository']['name']),
- ircutils.mircColor(data['pusher']['name'], "green"),
- ircutils.bold(str(commitno)),
- plural(commitno, "commit", "commits"),
- getShortURL(data['compare']),
- colon
- ))
+ theme.push(
+ repo = data['repository']['name'],
+ branch = branch,
+ actor = data['pusher']['name'],
+ url = getShortURL(data['compare']),
+ count = commitno
+ )
elif branched:
if isTag:
- if onlyDeleted:
- commitInfo = ""
- else:
- commitMsg = ""
- if configValue("tagShowCommitMsg"):
- commitMsg = ircutils.mircColor(" (%s)" % (maxLen(data['head_commit']['message'].splitlines()[0],75)),"brown")
- commitInfo = " %s %s%s as" % (branchFrom, ircutils.bold(data['head_commit']['id'][0:6]), commitMsg)
- msgs.append("%s: %s %s%s %s%s" % (
- ircutils.bold(data['repository']['name']),
- ircutils.mircColor(data['pusher']['name'], "green"),
- colorAction(action),
- commitInfo,
- ircutils.bold(ircutils.mircColor(branch, "blue")),
- urls,
- ))
+ theme.tag(
+ repo = data['repository']['name'],
+ actor = data['pusher']['name'],
+ action = action,
+ base = branchFrom,
+ to = branch,
+ onlyDeleted = onlyDeleted,
+ headMsg = data['head_commit']['message'],
+ headId = data['head_commit']['id'],
+ url = urls
+ )
elif isMerge:
- distinctMessage = ""
- if configValue("hidePush",None) == False and regularCommitCount > 0:
- distinctMessage = " and %s %s %s" % ( colorAction("pushed"), regularCommitCount, plural(regularCommitCount, 'commit', 'commits'))
-
- msgs.append( "%s: %s %s %s %s%s%s into %s%s" % (
- ircutils.bold(data['repository']['name']),
- ircutils.mircColor(data['pusher']['name'], "green"),
- colorAction(action),
- mergedCommitCount,
- plural(mergedCommitCount, 'commit', 'commits'),
- branchFrom,
- distinctMessage,
- ircutils.bold(ircutils.mircColor(branch, "blue")),
- urls
- ))
+ theme.merge(
+ repo = data['repository']['name'],
+ actor = data['pusher']['name'],
+ action = action,
+ mergeCount = mergedCommitCount,
+ regularCount = regularCommitCount,
+ base = branchFrom,
+ to = branch,
+ url = urls
+ )
else:
- msgs.append( "%s: %s %s branch %s%s%s%s" % (
- ircutils.bold(data['repository']['name']),
- ircutils.mircColor(data['pusher']['name'], "green"),
- colorAction(action),
- ircutils.bold(ircutils.mircColor(branch, "blue")),
- branchFrom,
- urls,
- colon
- ))
+ theme.branch(
+ repo = data['repository']['name'],
+ actor = data['pusher']['name'],
+ action = action,
+ count = commitno,
+ base = branchFrom,
+ to = branch,
+ url = urls
+ )
for commit in data['commits']:
if 'username' in commit['author']:
@@ -134,21 +114,11 @@ def handle(data):
if isMerge and not commit['distinct']:
commitBranch = "%s -> %s" % ( baseBranch, branch )
- msgs.append("%s @ %s: %s * %s (%s)" % (
- ircutils.bold(ircutils.mircColor(commitBranch, "blue")),
- ircutils.bold(data['repository']['name']),
- ircutils.mircColor(author, "green"),
- ircutils.bold(commit['id'][0:6]),
- getShortURL(commit['url']),
- ))
-
- commitlines = commit['message'].splitlines()
- for rawline in commitlines:
- line = maxLen(rawline, 400)
- msgs.append( "%s @ %s: %s" % (
- ircutils.bold(ircutils.mircColor(commitBranch, "blue")),
- ircutils.bold(data['repository']['name']),
- line,
- ))
-
- return msgs
+ theme.commit(
+ branch = commitBranch,
+ repo = data['repository']['name'],
+ author = author,
+ id = commit['id'],
+ message = commit['message'],
+ url = getShortURL(commit['url'])
+ )
diff --git a/local/handler/StatusHandler.py b/local/handler/StatusHandler.py
index 46e2e67..dd4bbd9 100644
--- a/local/handler/StatusHandler.py
+++ b/local/handler/StatusHandler.py
@@ -1,13 +1,9 @@
from ..utility import *
-def handle(data):
- msgs = []
-
- msgs.append( "%s: %s - %s (%s)" % (
- ircutils.bold(data['repository']['name']),
- colorAction(data['state']),
- data['description'],
- data['target_url']
- ))
-
- return msgs
+def handle(data, theme):
+ theme.status(
+ repo = data['repository']['name'],
+ status = data['state'],
+ description = data['description'],
+ url = data['target_url']
+ )
diff --git a/local/handler/TravisHandler.py b/local/handler/TravisHandler.py
index e69ab9d..bdfb484 100644
--- a/local/handler/TravisHandler.py
+++ b/local/handler/TravisHandler.py
@@ -1,18 +1,12 @@
from ..utility import *
-def handle(data):
- msgs = []
-
- status = data['status_message'].lower()
-
- if isStatusVisible(data['repository']['url'], status):
- msgs.append( "%s: Build status: %s * %s by %s (%s - %s)" % (
- ircutils.bold(data['repository']['name']),
- colorAction(status),
- 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
+def handle(data, theme):
+ if isStatusVisible(data['repository']['url'], data['status_message'].lower()):
+ theme.travis(
+ repo = data['repository']['name'],
+ status = data['status_message'],
+ commitId = data['commit'],
+ commitMessage = data['message'],
+ commitAuthor = data['author_name'],
+ buildUrl = data['build_url']
+ )
diff --git a/local/handler/WikiHandler.py b/local/handler/WikiHandler.py
index 1f93718..59bb37e 100644
--- a/local/handler/WikiHandler.py
+++ b/local/handler/WikiHandler.py
@@ -1,40 +1,31 @@
from ..utility import *
-def handle(data):
- msgs = []
-
+def handle(data, theme):
pageno = len(data['pages'])
url = getShortURL("%s/wiki/_compare/%s" % ( data['repository']['html_url'], data['pages'][0]['sha'] ))
if configValue("hidePush",None) is False:
- msgs.append( "%s: %s modified %s wiki %s (%s):" % (
- ircutils.bold(data['repository']['name']),
- ircutils.mircColor(data['sender']['login'], "green"),
- ircutils.bold(str(pageno)),
- plural(pageno, "page", "pages"),
- url
- ))
-
- urlShown = False;
-
+ theme.wikiPush(
+ repo = data['repository']['name'],
+ actor = data['sender']['login'],
+ count = pageno,
+ url = url
+ )
+
+ pages = []
for page in data['pages']:
- if configValue("hidePush") and urlShown is False:
- pageurl = "(%s)" % (url,)
- urlShown = True
- elif configValue("hidePush"):
- pageurl = ""
- else:
- pageurl = "(%s)" % (page['html_url'],)
-
- # Unfortunately github doesn't support edit summaries :(
- msgs.append( "%s: %s %s %s * %s %s" % (
- ircutils.bold(data['repository']['name']),
- ircutils.mircColor(data['sender']['login'], "green"),
- colorAction(page['action']),
- ircutils.bold(ircutils.mircColor(page['page_name'], "blue")),
- ircutils.bold(page['sha'][0:6]),
- pageurl,
- ))
-
- return msgs
+ pages.append({
+ 'action': page['action'],
+ 'name' : page['page_name'],
+ 'hash' : page['sha'],
+ 'url' : page['html_url']
+ })
+
+ # Unfortunately github doesn't support edit summaries :(
+ theme.wikiPages(
+ repo = data['repository']['name'],
+ actor = data['sender']['login'],
+ pages = pages,
+ url = url
+ )

© 2014-2024 Faster IT GmbH | imprint | privacy policy