Skip to content

Instantly share code, notes, and snippets.

@TylerLubeck
Last active December 26, 2015 04:39
Show Gist options
  • Save TylerLubeck/7095392 to your computer and use it in GitHub Desktop.
Save TylerLubeck/7095392 to your computer and use it in GitHub Desktop.
Remove unnecessary spacing
#!/usr/bin/python
# To Install:
# This script will go in your git directory, in the folder .git/hooks
# It has to be called "post-commit", so the final path will be
# MYGITPROJECT/.git/hooks/post-commit
# Then give this script execute permissions:
# chmod +x MYGITPROJECT/.git/hooks/post-commit
# You will need to get the twitter python library, as such:
# pip install twitter
# You will also need Twitter OAuth Keys, which you can get at:
# https://dev.twitter.com/apps/new
# You'll need to create a new application. After it's created, you can get
# your consumer key and secret underneath "OAuth settings" and your
# access token and secret under "Your access token"
# (These are the OAuth_Token and Oauth_Secret).
# Finally, you'll need to give this application write permissions underneath
# the settings tab - Application Type.
#
# After copying the keys in to the constants below, you'll be all set.
import sys
from subprocess import check_output
from twitter import *
TCK = TWITTER_CONSUMER_KEY = None #Should be a string, see instructions
TCS = TWITTER_CONSUMER_SECRET = None #Should be a string, see instructions
TOT = TWITTER_OAUTH_TOKEN = None #Should be a string, see instructions
TOS = TWITTER_OAUTH_SECRET = None #Should be a string, see instructions
if __name__ == "__main__":
#Check for keys
if not TCK or not TCS or not TOT or not TOS:
print "You haven't set your keys yet"
sys.exit()
#Get commit message
msg = check_output(["git", "log", "-1", "HEAD", "--pretty=format:%s"])
#Modify commit message to make room for extra pretty stuff
if(len(msg) > 96):
msg = msg[0:93] + '...'
else:
msg = msg[0:96]
#Add the extra pretty stuff
tweet = 'git commit -m "' + msg + '" #TuftsHack'
#Login to twitter and post tweet
t = Twitter(auth=OAuth(TOT, TOS, TCK, TCS))
t.statuses.update(status=tweet)
print "Tweeting: " + tweet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment