diff options
author | kongr45gpen <electrovesta@gmail.com> | 2014-04-26 15:52:48 +0300 |
---|---|---|
committer | kongr45gpen <electrovesta@gmail.com> | 2014-04-26 15:52:48 +0300 |
commit | e149f5274a8149d9366717b9d762d13097834a53 (patch) | |
tree | bfb27402b5f2effa35b0b3ac74acd9501d60b621 /local | |
parent | 59aa66b0b8e1e17255effc3a4a6e32994be8d177 (diff) | |
download | supybot_github-e149f5274a8149d9366717b9d762d13097834a53.tar.gz supybot_github-e149f5274a8149d9366717b9d762d13097834a53.tar.bz2 supybot_github-e149f5274a8149d9366717b9d762d13097834a53.zip |
Better handling of branch merges
Diffstat (limited to 'local')
-rw-r--r-- | local/handler/GithubHandler.py | 14 | ||||
-rw-r--r-- | local/handler/IssueCommentHandler.py | 22 | ||||
-rw-r--r-- | local/handler/PushHandler.py | 44 |
3 files changed, 57 insertions, 23 deletions
diff --git a/local/handler/GithubHandler.py b/local/handler/GithubHandler.py index 598dc36..db0d3d5 100644 --- a/local/handler/GithubHandler.py +++ b/local/handler/GithubHandler.py @@ -7,6 +7,7 @@ import urllib2 import urlparse import threading import BaseHTTPServer +from time import strftime import supybot.conf as conf import supybot.utils as utils @@ -42,7 +43,15 @@ class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler): s.wfile.write('</body></html>\n') s.wfile.write(s.path.split('/')) - #print json.dumps(data, sort_keys=True, indent=4, separators=(',', ': ')) + + if 'X-GitHub-Event' in s.headers: + eventType = s.headers['X-GitHub-Event'] + else: + eventType = '' + + f = open('requests/' + eventType + strftime("%Y-%m-%d %H:%M:%S") + '.json', 'w') + f.write(json.dumps(data, sort_keys=True, indent=4, separators=(',', ': '))) + f.close() path = s.path.split('/') channel = configValue('channel') @@ -70,9 +79,6 @@ class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler): i+=1 - - - if requireCode and receivedcode != configValue('passcode'): # The password is wrong s.wfile.write("The password is wrong") diff --git a/local/handler/IssueCommentHandler.py b/local/handler/IssueCommentHandler.py index 06aa005..92a3b65 100644 --- a/local/handler/IssueCommentHandler.py +++ b/local/handler/IssueCommentHandler.py @@ -5,8 +5,7 @@ from ..utility import * def handle(irc, data, channel): msgs = [] - url = getShortURL(data['comment']['url']) - + url = getShortURL(data['comment']['html_url']) creator = '' if data['sender']['login'] != data['issue']['user']['login']: @@ -28,15 +27,16 @@ def handle(irc, data, channel): elif len(lines) > 1: line += "..." - msgs.append( ircmsgs.privmsg(channel, "%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 + msgs.append( ircmsgs.privmsg( + channel, "%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 diff --git a/local/handler/PushHandler.py b/local/handler/PushHandler.py index 97ed825..3755cc9 100644 --- a/local/handler/PushHandler.py +++ b/local/handler/PushHandler.py @@ -14,27 +14,28 @@ def handle(irc, data, channel): colon = ':' isTag = False + isMerge = False - branched = data['created'] or data['deleted'] or ref[1] == "tags" + branched = data['created'] or data['deleted'] or ref[1] == "tags" or 'base_ref' in data branchFrom = '' tagFrom = '' onlyDeleted = data['deleted'] and not data['created'] if branched: - print branch if ref[1] == 'tags': isTag = True urls = ' (%s)' % (getShortURL(data['compare']),) if 'base_ref' in data: base_ref = data['base_ref'].split('/',2) + baseBranch = base_ref[2] if isTag: - branchFrom = '%s %s ' % (base_ref[2], ircutils.bold('*')) + branchFrom = '%s %s ' % (baseBranch, ircutils.bold('*')) else: - branchFrom = ' from %s' % (base_ref[2],) + branchFrom = ' from %s' % (ircutils.bold(ircutils.mircColor(baseBranch, "blue")), ) - if data['created'] and data['deleted'] or (not data['created'] and not data['deleted'] and data['forced']): + if (data['created'] and data['deleted']) or (not data['created'] and not data['deleted'] and data['forced']): if isTag: action = "re-tagged" else: @@ -62,7 +63,10 @@ def handle(irc, data, channel): action = "deleted" urls = '' else: - action = "did something with" + action = "merged" + mergedCommitCount = sum(not commit['distinct'] for commit in data['commits']) + regularCommitCount = len(data['commits']) - mergedCommitCount + isMerge = True if configValue("hidePush",None) == False and not branched: @@ -92,6 +96,22 @@ def handle(irc, data, channel): ircutils.bold(ircutils.mircColor(branch, "blue")), 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( ircmsgs.privmsg(channel, "%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 + )) ) else: msgs.append( ircmsgs.privmsg(channel, "%s: %s %s branch %s%s%s%s" % ( ircutils.bold(data['repository']['name']), @@ -109,8 +129,16 @@ def handle(irc, data, channel): else: author = commit['author']['name'] + commitBranch = branch + + if not commit['distinct'] and not configValue('showMergedCommits'): + continue + + if isMerge and not commit['distinct']: + commitBranch = "%s -> %s" % ( baseBranch, branch ) + msgs.append( ircmsgs.privmsg(channel, "%s @ %s: %s * %s (%s)" % ( - ircutils.bold(ircutils.mircColor(branch, "blue")), + ircutils.bold(ircutils.mircColor(commitBranch, "blue")), ircutils.bold(data['repository']['name']), ircutils.mircColor(author, "green"), ircutils.bold(commit['id'][0:6]), @@ -121,7 +149,7 @@ def handle(irc, data, channel): for rawline in commitlines: line = maxLen(rawline, 400) msgs.append(ircmsgs.privmsg(channel, "%s @ %s: %s" % ( - ircutils.bold(ircutils.mircColor(branch, "blue")), + ircutils.bold(ircutils.mircColor(commitBranch, "blue")), ircutils.bold(data['repository']['name']), line, )) ) |