{"id":31,"date":"2009-05-25T10:25:53","date_gmt":"2009-05-25T15:25:53","guid":{"rendered":"http:\/\/developer.casgrain.com\/?p=31"},"modified":"2011-02-16T22:52:45","modified_gmt":"2011-02-17T03:52:45","slug":"sending-mercurial-commit-messages-to-twitter","status":"publish","type":"post","link":"http:\/\/developer.casgrain.com\/?p=31","title":{"rendered":"Sending Mercurial commit messages to Twitter"},"content":{"rendered":"<p>[Update 16\/02\/2011 &#8211; This no longer works now that Twitter has disabled basic_auth. Oh well&#8230;.]<br \/>\n[Update 21\/07\/2009 &#8211; Twilight is now called Daylight.]<\/p>\n<p>If you follow what I do on this blog and on my <a href=\"http:\/\/www.cocoacast.com\/?q=blog\/189\">podcast<\/a> with <a href=\"http:\/\/twitter.com\/philippeguitard\">Philippe Guitard<\/a>, you know that I like <a href=\"http:\/\/www.selenic.com\/mercurial\/\">Mercurial (<code>hg<\/code>)<\/a>, one of the newer <a href=\"http:\/\/en.wikipedia.org\/wiki\/Distributed_revision_control\">distributed version control systems<\/a>.<\/p>\n<p>\nIn particular, I really like <a href=\"http:\/\/bitbucket.org\/snej\/murky\/wiki\/Home\">Murky<\/a> as a GUI front-end to Mercurial. In fact, I&#8217;m working on the <a href=\"http:\/\/bitbucket.org\/kaluznyo\/murky_i18n\/\">French localization<\/a> with <a href=\"http:\/\/bitbucket.org\/kaluznyo\/\">Olivier Kaluzny<\/a>.<\/p>\n<p>\nI want to create a tweet from <a href=\"http:\/\/twitter.com\/ichibiapp\">@ichibiapp<\/a> or <a href=\"http:\/\/twitter.com\/daylightapp\">@daylightapp<\/a> for every commit. I do this with other apps and subversion, and find it pretty handy to catch new commits to production. Plus, if you follow these products on Twitter, you too can get on the inside track of the software releases.<\/p>\n<p>\nIf you want to do the same for your Mercurial repositories, here&#8217;s how:<\/p>\n<ol>\n<li>Put this shell script, called <code>commit-twitter<\/code>, in your <code>$PATH<\/code> and mark it as executable (<code>chmod a+x commit-twitter<\/code>):\n<pre>\r\n#!\/bin\/sh\r\n# Simple script to send the first line of the commit message as a tweet\r\nif [ $# -ne 2 ]\r\nthen\r\n  echo \"Usage: `basename $0` twitter-username twitter-password\"\r\n  exit 1\r\nfi\r\nTWITTER_USER=$1\r\nTWITTER_PASS=$2\r\nTWEET=$(hg log -r $HG_NODE --template '{desc|firstline}')\r\ncurl -s -u \"$TWITTER_USER:$TWITTER_PASS\" -d \"status=$TWEET\" http:\/\/twitter.com\/statuses\/update.xml & > \/dev\/null\r\n<\/pre>\n<p>\n<font size=\"-1\"><br \/>\nThe script takes two arguments, username and password, and checks that you have those two arguments. Then it extracts the tweet from the log using the <code>HG_<\/code> environment variables set by Mercurial. <br \/>Finally, it uses <code>curl<\/code> to generate the tweet, using silent mode (<code>-s<\/code>), running in the background with <code>&<\/code> (to return immediately) and sending the output to <code>\/dev\/null<\/code>.<br \/>\n<\/font>\n<\/li>\n<li>Add the following lines to your repository&#8217;s <code>.hg\/hgrc<\/code> file, creating it if it does not exist:\n<pre>\r\n[hooks]\r\ncommit.tweet = commithook-twitter &lt;twitter-username&gt; &lt;twitter-password&gt;\r\n<\/pre>\n<\/li>\n<p><li>There is no Step 3!\n<\/li>\n<\/ol>\n<p>Voil\u00e0! Every time you commit to Mercurial, the first line of your commit message will be posted as a tweet to the specified twitter account.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Update 16\/02\/2011 &#8211; This no longer works now that Twitter has disabled basic_auth. Oh well&#8230;.] [Update 21\/07\/2009 &#8211; Twilight is now called Daylight.] If you follow what I do on this blog and on my podcast with Philippe Guitard, you know that I like Mercurial (hg), one of the newer distributed version control systems. In [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-31","post","type-post","status-publish","format-standard","hentry","category-quickie"],"_links":{"self":[{"href":"http:\/\/developer.casgrain.com\/index.php?rest_route=\/wp\/v2\/posts\/31","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/developer.casgrain.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/developer.casgrain.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/developer.casgrain.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/developer.casgrain.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=31"}],"version-history":[{"count":4,"href":"http:\/\/developer.casgrain.com\/index.php?rest_route=\/wp\/v2\/posts\/31\/revisions"}],"predecessor-version":[{"id":111,"href":"http:\/\/developer.casgrain.com\/index.php?rest_route=\/wp\/v2\/posts\/31\/revisions\/111"}],"wp:attachment":[{"href":"http:\/\/developer.casgrain.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=31"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/developer.casgrain.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=31"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/developer.casgrain.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}