summaryrefslogtreecommitdiff
path: root/gitnoti.py
diff options
context:
space:
mode:
Diffstat (limited to 'gitnoti.py')
-rwxr-xr-xgitnoti.py27
1 files changed, 24 insertions, 3 deletions
diff --git a/gitnoti.py b/gitnoti.py
index 5f2fd40..7817182 100755
--- a/gitnoti.py
+++ b/gitnoti.py
@@ -1,11 +1,17 @@
#!/usr/bin/env python
-import git, os, sys, time
+import git, os, sys, time, pyinotify, netrc
from optparse import OptionParser
from twisted.words.protocols import irc
from twisted.internet import reactor, protocol
from twisted.internet.task import LoopingCall
-import pyinotify
+
+have_bitly = False
+try:
+ import bitly
+ have_bitly = True
+except:
+ pass
parser = OptionParser()
parser.add_option('-s', '--host')
@@ -21,6 +27,9 @@ if not options.host or not options.dir or not options.channel or not options.nic
parser.print_help()
sys.exit(1)
+if have_bitly and not netrc.netrc().authenticators('bitly'):
+ have_bitly = False
+
root = options.dir
if root[-1] == '/':
@@ -44,7 +53,19 @@ def repo_commit_msg(repo, commit):
if options.url:
msg += ' | '
- msg += options.url % {'repo': reponame, 'commit': commit.id}
+ url = options.url % {'repo': reponame, 'commit': commit.id}
+ if have_bitly:
+ short_url = None
+ try:
+ bitly_auth = netrc.netrc().authenticators('bitly')
+ bitly_api = bitly.Api(login = bitly_auth[0], apikey = bitly_auth[2])
+ short_url = bitly_api.shorten(url)
+ except:
+ short_url = None
+
+ if short_url:
+ url = short_url
+ msg += url
return msg