aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkongr45gpen <electrovesta@gmail.com>2016-01-21 18:41:55 +0200
committerkongr45gpen <electrovesta@gmail.com>2016-01-21 18:41:55 +0200
commit8fd81d577568517c12e23512dda43a7aecd1883a (patch)
tree784690ade7786e2b394f546f0e64ecca18ddbf84
parent230da7e0db5a31a543bbaa24a63478f5111ceba8 (diff)
downloadsupybot_github-8fd81d577568517c12e23512dda43a7aecd1883a.tar.gz
supybot_github-8fd81d577568517c12e23512dda43a7aecd1883a.tar.bz2
supybot_github-8fd81d577568517c12e23512dda43a7aecd1883a.zip
Show repo owner if the repo is a fork
-rw-r--r--local/handler/CreateDeleteHandler.py2
-rw-r--r--local/handler/GithubHandler.py10
-rw-r--r--local/handler/IssueCommentHandler.py1
-rw-r--r--local/handler/IssueHandler.py1
-rw-r--r--local/handler/PushHandler.py5
-rw-r--r--local/handler/StatusHandler.py1
-rw-r--r--local/handler/WikiHandler.py2
-rw-r--r--local/theme/CompactTheme.py7
-rw-r--r--local/theme/DefaultTheme.py65
-rw-r--r--local/theme/Theme.py3
-rw-r--r--samples/wiki-new-page.json2
-rw-r--r--test.py4
12 files changed, 55 insertions, 48 deletions
diff --git a/local/handler/CreateDeleteHandler.py b/local/handler/CreateDeleteHandler.py
index fc6f0cb..3fa0d45 100644
--- a/local/handler/CreateDeleteHandler.py
+++ b/local/handler/CreateDeleteHandler.py
@@ -5,7 +5,6 @@ def handle(data, theme):
if data['ref_type'] == 'tag':
theme.tag(
- repo = data['repository']['name'],
actor = data['sender']['login'],
action = "tagged" if created else "deleted tag",
to = data['ref'],
@@ -14,7 +13,6 @@ def handle(data, theme):
)
else:
theme.branch(
- repo = data['repository']['name'],
actor = data['sender']['login'],
action = "created" if created else "deleted",
count = 0,
diff --git a/local/handler/GithubHandler.py b/local/handler/GithubHandler.py
index 1c54ce8..79a635a 100644
--- a/local/handler/GithubHandler.py
+++ b/local/handler/GithubHandler.py
@@ -69,7 +69,6 @@ class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler):
and configValue('passcode').strip().lower() != 'false' \
and configValue('passcode').strip().lower() != 'null' \
and configValue('passcode').strip().lower() != 'no'
- brackets = parseBrackets(configValue('brackets'))
resetConfigOverrides()
@@ -98,11 +97,13 @@ class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler):
s.wfile.write("The password is wrong")
return
+ brackets = parseBrackets(configValue('brackets'))
themeName = configValue('theme')
alphanumericPattern = re.compile('[\W_]+')
themeClass = ''.join([alphanumericPattern.sub('', themeName).title(), 'Theme'])
+ # Find the theme's class
try:
mod = getattr(themes, themeClass)
klass = getattr(mod, themeClass)
@@ -111,7 +112,12 @@ class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler):
log.error("The '%s' theme was not found" % themeName)
klass = themes.DefaultTheme.DefaultTheme
- theme = klass(brackets)
+ repo = {}
+
+ repo['name'] = data.get('repository').get('name')
+ repo['owner'] = data.get('repository').get('owner',{}).get('login')
+ repo['fork'] = data.get('repository').get('fork', False)
+ theme = klass(repo, brackets)
#
# Handle different event types
diff --git a/local/handler/IssueCommentHandler.py b/local/handler/IssueCommentHandler.py
index e0084f3..b066013 100644
--- a/local/handler/IssueCommentHandler.py
+++ b/local/handler/IssueCommentHandler.py
@@ -10,7 +10,6 @@ def handle(data, theme):
assignee = data['issue']['assignee']['login']
theme.issue(
- repo = data['repository']['name'],
actor = data['comment']['user']['login'],
action = 'commented on',
comment = data['comment']['body'],
diff --git a/local/handler/IssueHandler.py b/local/handler/IssueHandler.py
index cc5cf4e..122e519 100644
--- a/local/handler/IssueHandler.py
+++ b/local/handler/IssueHandler.py
@@ -18,7 +18,6 @@ def handle(data, theme):
labelColor = data['label']['color']
theme.issue(
- repo = data['repository']['name'],
actor = data['sender']['login'],
action = data['action'],
issueNo = data['issue']['number'],
diff --git a/local/handler/PushHandler.py b/local/handler/PushHandler.py
index 46e57a7..e40aa64 100644
--- a/local/handler/PushHandler.py
+++ b/local/handler/PushHandler.py
@@ -59,7 +59,6 @@ def handle(data, theme):
if configValue("hidePush",None) == False and not branched:
theme.push(
- repo = data['repository']['name'],
branch = branch,
actor = data['pusher']['name'],
url = getShortURL(data['compare']),
@@ -68,7 +67,6 @@ def handle(data, theme):
elif branched:
if isTag:
theme.tag(
- repo = data['repository']['name'],
actor = data['pusher']['name'],
action = action,
base = branchFrom,
@@ -80,7 +78,6 @@ def handle(data, theme):
)
elif isMerge:
theme.merge(
- repo = data['repository']['name'],
actor = data['pusher']['name'],
action = action,
mergeCount = mergedCommitCount,
@@ -91,7 +88,6 @@ def handle(data, theme):
)
else:
theme.branch(
- repo = data['repository']['name'],
actor = data['pusher']['name'],
action = action,
count = commitno,
@@ -116,7 +112,6 @@ def handle(data, theme):
theme.commit(
branch = commitBranch,
- repo = data['repository']['name'],
author = author,
id = commit['id'],
message = commit['message'],
diff --git a/local/handler/StatusHandler.py b/local/handler/StatusHandler.py
index dd4bbd9..729daac 100644
--- a/local/handler/StatusHandler.py
+++ b/local/handler/StatusHandler.py
@@ -2,7 +2,6 @@ from ..utility import *
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/WikiHandler.py b/local/handler/WikiHandler.py
index 59bb37e..d04a589 100644
--- a/local/handler/WikiHandler.py
+++ b/local/handler/WikiHandler.py
@@ -7,7 +7,6 @@ def handle(data, theme):
if configValue("hidePush",None) is False:
theme.wikiPush(
- repo = data['repository']['name'],
actor = data['sender']['login'],
count = pageno,
url = url
@@ -24,7 +23,6 @@ def handle(data, theme):
# Unfortunately github doesn't support edit summaries :(
theme.wikiPages(
- repo = data['repository']['name'],
actor = data['sender']['login'],
pages = pages,
url = url
diff --git a/local/theme/CompactTheme.py b/local/theme/CompactTheme.py
index a4dbed7..cb3364d 100644
--- a/local/theme/CompactTheme.py
+++ b/local/theme/CompactTheme.py
@@ -3,10 +3,9 @@ from DefaultTheme import DefaultTheme
from ..utility import *
class CompactTheme(DefaultTheme):
- def commit(self, branch, repo, author, message, id, url):
- self.msgs.append("%s @ %s: %s %s: %s %s" % (
- ircutils.bold(ircutils.mircColor(branch, "blue")),
- ircutils.bold(repo),
+ def commit(self, branch, author, message, id, url):
+ self.msgs.append("%s: %s %s: %s %s" % (
+ self.repo(branch),
ircutils.mircColor(author, "green"),
ircutils.mircColor(id[0:6], "dark grey"),
maxLen(message.splitlines()[0], 300),
diff --git a/local/theme/DefaultTheme.py b/local/theme/DefaultTheme.py
index 7bd8bfc..86d4cb2 100644
--- a/local/theme/DefaultTheme.py
+++ b/local/theme/DefaultTheme.py
@@ -3,10 +3,9 @@ from Theme import Theme
from ..utility import *
class DefaultTheme(Theme):
- def push(self, branch, repo, actor, count, url):
- self.msgs.append( "%s @ %s: %s pushed %s %s %s%s" % (
- ircutils.bold(ircutils.mircColor(branch, "blue")),
- ircutils.bold(repo),
+ def push(self, branch, actor, count, url):
+ self.msgs.append( "%s: %s pushed %s %s %s%s" % (
+ self.repo(branch),
ircutils.mircColor(actor, "green"),
ircutils.bold(str(count)),
plural(count, "commit", "commits"),
@@ -14,10 +13,9 @@ class DefaultTheme(Theme):
':' if count else ''
))
- def commit(self, branch, repo, author, message, id, url):
- self.msgs.append("%s @ %s: %s * %s %s" % (
- ircutils.bold(ircutils.mircColor(branch, "blue")),
- ircutils.bold(repo),
+ def commit(self, branch, author, message, id, url):
+ self.msgs.append("%s: %s * %s %s" % (
+ self.repo(branch),
ircutils.mircColor(author, "green"),
ircutils.bold(id[0:6]),
self.enclose(url)
@@ -25,19 +23,18 @@ class DefaultTheme(Theme):
commitlines = message.splitlines()
for line in commitlines:
- self.msgs.append( "%s @ %s: %s" % (
- ircutils.bold(ircutils.mircColor(branch, "blue")),
- ircutils.bold(repo),
- maxLen(line, 400),
+ self.msgs.append( "%s: %s" % (
+ self.repo(branch),
+ maxLen(line, 400)
))
- def merge(self, repo, actor, action, mergeCount, regularCount, base, to, url):
+ def merge(self, actor, action, mergeCount, regularCount, base, to, url):
distinctMessage = ""
if configValue("hidePush",None) == False and regularCount > 0:
distinctMessage = " and %s %s %s" % ( colorAction("pushed"), regularCount, plural(regularCount, 'commit', 'commits'))
self.msgs.append( "%s: %s %s %s %s from %s%s into %s%s" % (
- ircutils.bold(repo),
+ self.repo(),
ircutils.mircColor(actor, "green"),
colorAction(action),
mergeCount,
@@ -48,9 +45,9 @@ class DefaultTheme(Theme):
' %s' % self.enclose(url) if url else ''
))
- def branch(self, repo, actor, action, count, to, url, base = None):
+ def branch(self, actor, action, count, to, url, base = None):
self.msgs.append( "%s: %s %s branch %s%s%s%s" % (
- ircutils.bold(repo),
+ self.repo(),
ircutils.mircColor(actor, "green"),
colorAction(action),
ircutils.bold(ircutils.mircColor(to, "blue")),
@@ -59,7 +56,7 @@ class DefaultTheme(Theme):
':' if count else ''
))
- def tag(self, repo, actor, action, to, onlyDeleted, base = None, headMsg = None, headId = None, url = None):
+ def tag(self, actor, action, to, onlyDeleted, base = None, headMsg = None, headId = None, url = None):
if onlyDeleted:
commitInfo = ""
else:
@@ -69,7 +66,7 @@ class DefaultTheme(Theme):
commitInfo = " %s %s %s%s as" % (base, ircutils.bold('*'), ircutils.bold(headId[0:6]), commitMsg)
self.msgs.append("%s: %s %s%s %s%s" % (
- ircutils.bold(repo),
+ self.repo(),
ircutils.mircColor(actor, "green"),
colorAction(action),
commitInfo,
@@ -77,7 +74,7 @@ class DefaultTheme(Theme):
' %s' % self.enclose(url) if url else ''
))
- def issue(self, repo, actor, action, issueNo, issueTitle, creator, milestone, url, assignee = None, comment = None, labelName = None, labelColor = None):
+ def issue(self, actor, action, issueNo, issueTitle, creator, milestone, url, assignee = None, comment = None, labelName = None, labelColor = None):
formattedActor = ircutils.mircColor(actor, "green")
if actor == assignee:
@@ -92,7 +89,7 @@ class DefaultTheme(Theme):
extra = " as %s" % ircutils.mircColor(labelName, hexToMirc(labelColor))
self.msgs.append( "%s: %s %s issue #%s \"%s\"%s%s %s %s" % (
- ircutils.bold(repo),
+ self.repo(),
formattedActor,
colorAction(action),
issueNo,
@@ -106,16 +103,16 @@ class DefaultTheme(Theme):
": %s" % maxLen(comment, 70) if comment else ''
))
- def wikiPush(self, repo, actor, count, url):
+ def wikiPush(self, actor, count, url):
self.msgs.append( "%s: %s modified %s wiki %s %s:" % (
- ircutils.bold(repo),
+ self.repo(),
ircutils.mircColor(actor, "green"),
ircutils.bold(str(count)),
plural(count, "page", "pages"),
self.enclose(url)
))
- def wikiPages(self, repo, actor, pages, url):
+ def wikiPages(self, actor, pages, url):
urlShown = False;
for page in pages:
@@ -128,7 +125,7 @@ class DefaultTheme(Theme):
pageurl = self.enclose(page['url'])
self.msgs.append( "%s: %s %s %s * %s %s" % (
- ircutils.bold(repo),
+ self.repo(),
ircutils.mircColor(actor, "green"),
colorAction(page['action']),
ircutils.bold(ircutils.mircColor(page['name'], "blue")),
@@ -149,10 +146,26 @@ class DefaultTheme(Theme):
))
))
- def status(self, repo, status, description, url):
+ def status(self, status, description, url):
self.msgs.append( "%s: %s - %s %s" % (
- ircutils.bold(repo),
+ self.repo(),
colorAction(status),
description,
self.enclose(url)
))
+
+ def repo(self, branch = None):
+ name = ircutils.bold(self.repoInfo['name'])
+
+ if self.repoInfo['fork'] and self.repoInfo['owner']:
+ repo = "%s/%s" % (self.repoInfo['owner'], name)
+ else:
+ repo = name
+
+ if branch is not None:
+ return "%s @ %s" % (
+ ircutils.bold(ircutils.mircColor(branch, "blue")),
+ repo
+ )
+ else:
+ return repo
diff --git a/local/theme/Theme.py b/local/theme/Theme.py
index 8aa32fb..ecad213 100644
--- a/local/theme/Theme.py
+++ b/local/theme/Theme.py
@@ -1,6 +1,7 @@
class Theme(object):
- def __init__(self, brackets = "()"):
+ def __init__(self, repository, brackets = "()"):
self.msgs = []
+ self.repoInfo = repository
self.brackets = brackets
def finalize(self):
diff --git a/samples/wiki-new-page.json b/samples/wiki-new-page.json
index b9ca4fa..53189de 100644
--- a/samples/wiki-new-page.json
+++ b/samples/wiki-new-page.json
@@ -35,7 +35,7 @@
"private": false,
"html_url": "https://github.com/kongr45gpen/supybot-github",
"description": "Highly configurable, still under construction supybot/gribble plugin that uses an HTTP post-commit hook to report commits and other updates from Github repositories",
- "fork": false,
+ "fork": true,
"url": "https://api.github.com/repos/kongr45gpen/supybot-github",
"forks_url": "https://api.github.com/repos/kongr45gpen/supybot-github/forks",
"keys_url": "https://api.github.com/repos/kongr45gpen/supybot-github/keys{/key_id}",
diff --git a/test.py b/test.py
index be5d8cb..7a103ea 100644
--- a/test.py
+++ b/test.py
@@ -59,8 +59,8 @@ class GithubTestCase(ExpectationPluginTestCase):
self.sendRequest('wiki-new-page')
self.describe('first message',
- it().should.contain('kongr45gpen'),
- it().should.contain('modified 1 wiki page'),
+ it().should.contain('kongr45gpen/supybot-github'),
+ it().should.contain('kongr45gpen modified 1 wiki page'),
it().should.contain('https://github.com/kongr45gpen/supybot-github/wiki/_compare/9941c1a1bb1b2db99ad9aabf10c8f946d808e634')
)

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