Skip to content

@kylefrost /HOWTO.md
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
How-To: Tweet All Commit Messages

Creating the post-commit file

Note: If you want to use your personal Twitter account to post commits, go to Step 2

  1. Create a new Twitter account for your commit messages. Example
  2. Go to http://dev.twitter.com and Sign In with your Twitter account you are posting commit messages to.
  3. Hover over your username in the top-right corner after signing in and select "My Applications"
  4. Create a new application
  5. The name, description, and site can all be whatever you want, but leave Callback URL empty
  6. Under "Application Settings" click "modify app permissions" next to "Access level"
  7. Select "Read and Write" and then click "Update Settings"
  8. On the tabs at the top, go to "API Keys"
  9. Scroll to the bottom and under "Your Access Token click "Create my access token"
  10. Copy down into a text document the "API Key" and "API Secret" under "Application Settings" as well as "Access Token" and "Access Token Secret" under the genereted "Your Access Token" - you need these later
    • You may have to wait a few moments and refresh in order to see your access token
  11. You can close Twitter Developer now
  12. Download oauth_sign and http_post, save them somewhere that you can easily find them
  13. Open your favorite Terminal application and cd to the directory of the uncompressed oauth_sign zip (e.g. cd /path/to/oauth_sign/)
  14. Run sudo make then sudo make install from inside the oauth_sign directory
  15. Now cd into the directory of the uncompressed http_post zip
  16. Run sudo make SSL_DEFS="-DUSE_SSL" SSL_LIBS="-lssl -lcrypto" then sudo make install
  17. Open a new Terminal window and make sure they are there by typing oauth_sign and http_post and it doesn't say command not found
  18. You can delete the left over files now
  19. Save the post-commit file from this gist and edit the file with your personal API Keys that you put in the text document earlier
  20. Copy post-commit into your local git repository in .git/hooks/post-commit
  21. Run chmod a+x on the post-commit in order to make it executable
  22. Now it should send a tweet every time you make a commit message from the repo you added it to

Add this file by default to every new git repo

  1. Create a .git_template/hooks/ folder in your home directory
  2. mkdir ~/.git_template
  3. mkdir ~/.git_template/hooks/
  4. Run git config --global init.templatedir '~/.git_template'
  5. Copy all the files from your current git repo's hooks folder (the one you put post-commit in) into the new hooks folder
    • e.g. cp -R /my/git/repo/.git/hooks/ ~/.git_template/hooks/
  6. Done! Every time you create a new repo on your machine, the post-commit file should be there
#!/bin/sh
# PATH modification needed for http_post and oauth_sign
export PATH=$PATH:/usr/local/bin
toplevel_path=`git rev-parse --show-toplevel`
toplevel_dir=`basename "$toplevel_path"`
branch=`git rev-parse --abbrev-ref HEAD`
subject=`git log --pretty=format:%s -n1`
hashtags="#code #$toplevel_dir"
tweet=$hashtags' ['$branch']: "'$subject'"'
# truncate tweets that are longer than 140 characters
if [ ${#tweet} -gt 140 ]
then
tweet_trunc=$(echo $tweet | cut -c1-137)
tweet=${tweet_trunc}...
fi
consumer_key="YOUR API KEY"
consumer_secret="YOUR API SECRET"
access_token="YOUR ACCESS TOKEN"
access_secret="YOUR ACCESS TOKEN SECRET"
url="https://api.twitter.com/1.1/statuses/update.json"
http_post -h Authorization "$(oauth_sign \
$consumer_key $consumer_secret \
$access_token $access_secret \
POST "$url" status="$tweet")" \
"$url" status="$tweet"
@groundh0g

Looks like the url for creating / managing apps has changed?

Was: https://dev.twitter.com/
Is: https://apps.twitter.com/

The dev address appears to be pimping their new suite of SDKs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.