From c77026dac5b34de9a663f31cac593cd01f04b0b6 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 29 Dec 2009 01:33:22 +0100 Subject: 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. --- gitnoti.py | 27 ++++++++++++++++++++++++--- 1 file 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 -- cgit v1.2.3