Friday, August 6, 2010

Twitter your SVN commits via the command line. (Windows)

Had some fun today. One, I got reCaptcha wired up with asp.net mvc2, and it was as easy as you could hope for. I won't bother re-creating it here, because this post does it wonderfully: http://devlicio.us/blogs/derik_whittaker/archive/2008/12/02/using-recaptcha-with-asp-net-mvc.aspx. Plus anyone named D. Whittaker is 100% A-OK in my book.

No, I dorked around and added a line to my single-click batch file (which currently commits to SVN, robocopies out to a fresh directory, compiles the website with visual studio, 7zips up the package, puts a copy on the network for archive, and puts a copy on the server with a flagged file for the server to check and extract and publish the update). The line I added was

tweetupdate

Here are the steps

  1. Grab the code from Jason Fowler (here) to get yourself tweeting from the command line.  His "application" is a little bit of my favorite type.  Basically, you need wget.exe (wget for windows), and a simple .bat file which you set your twitter username and password, then because twitter uses the dead simple REST API, you can hit URI with a single wget command which will tweet you status update.
  2. Getting the current version of you HEAD is not as straightforward, but not bad.  Thanks to the invaluable StackOverflow.  (I lost the solution link now, but something like SVN command line version).  You can drop
    for /f "tokens=5" %%i in ('SubWCRev .^|find "Last committed at revision"') do set version=%%i
    echo %version%

    into a batch file and you are all set (note that this batch file needs to be in the directory you are versioning from becuase I am calling "SubWCRev"* on " . ".  If you want to test it out, you need to replace "." with the path to your current working directory.  Anyhow, this will return the current version.
  3. Put step 2 with setp 1
    twitter "MyAPP just did svn commit number %version%"
    will update your twitter status with "MyAPP just did svn commit number 1099", assuming you are on commit # 109.  :) Like here.

That's it.  How easy could that be?  (well, I combined step 2 and three and made a file called tweetupdate.bat and now execute it from my publish script.

*SubWCRev is a command that comes installed when you install TortoiseSVN on your windows machine.

No comments:

Post a Comment