Skip to content
Create a gist now

Instantly share code, notes, and snippets.

@kylefrost /HOWTO.md
Last active Jun 18, 2016

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.

@wbuchanan

Throws the following error:

{"errors":[{"code":32,"message":"Could not authenticate you."}]}[master (root-commit) 9a7f276] Initial Commit of Program to access Charitable Org Tax Data from the IRS in Stata

Not sure why. Tested the keys in Twitter, but the local commit threw that error in a new repo.

@fredzannarbor

It's echoing all the json after the commit, which is annoying, can I make that silent?


 git commit
{"created_at":"Sat Jun 18 01:22:36 +0000 2016","id":743977177939578880,"id_str":"743977177939578880","text":"#code #pagekicker-community [test_scripts]: \"Adds new test script for batch build\"","truncated":false,"entities":{"hashtags":[{"text":"code","indices":[0,5]},{"text":"pagekicker","indices":[6,17]}],"symbols":[],"user_mentions":[],"urls":[]},"source":"\u003ca href=\"http:\/\/github.com\/fredzannarbor\/pagekicker-community\" rel=\"nofollow\"\u003ePageKicker Local GitHook\u003c\/a\u003e","in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":22919451,"id_str":"22919451","name":"Fred Zimmerman","screen_name":"fredzannarbor","location":"Ann Arbor, Michigan, USA","description":"https:\/\/t.co\/IxnchNoqiK https:\/\/t.co\/qrqIEBUe7h","url":"http:\/\/t.co\/IxnchNG1ai","entities":{"url":{"urls":[{"url":"http:\/\/t.co\/IxnchNG1ai","expanded_url":"http:\/\/www.PageKicker.com","display_url":"PageKicker.com","indices":[0,22]}]},"description":{"urls":[{"url":"https:\/\/t.co\/IxnchNoqiK","expanded_url":"http:\/\/www.PageKicker.com","display_url":"PageKicker.com","indices":[0,23]},{"url":"https:\/\/t.co\/qrqIEBUe7h","expanded_url":"https:\/\/github.com\/fredzannarbor\/pagekicker-community\/","display_url":"github.com\/fredzannarbor\/\u2026","indices":[24,47]}]}},"protected":false,"followers_count":1827,"friends_count":1069,"listed_count":293,"created_at":"Thu Mar 05 13:44:12 +0000 2009","favourites_count":7064,"utc_offset":-14400,"time_zone":"Eastern Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":38575,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/684834068358365184\/sD8JzYke_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/684834068358365184\/sD8JzYke_normal.jpg","profile_link_color":"9266CC","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"000000","profile_text_color":"000000","profile_use_background_image":false,"has_extended_profile":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"retweet_count":0,"favorite_count":0,"favorited":false,"retweeted":false,"lang":"en"}[test_scripts 1c8b718] Adds new test script for batch build
 1 file changed, 2 insertions(+)
 create mode 100755 test/VR_batch.sh

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.