summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2009-12-29 01:33:22 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2009-12-29 01:33:22 +0100
commitc77026dac5b34de9a663f31cac593cd01f04b0b6 (patch)
treee4ea2551de6725127f22a11ef6310d44cce95695
parent6b223a1f039ecd6ed515e0f2714aa7a1f0a44c1b (diff)
Added bit.ly support for URLs to web frontends.
This is an optional feature and requires python-bitly to work. User name and api key is read from the user's .netrc, using the password field for the api key.
-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