Search code examples
windowsfacebooksvnvisualsvnvisualsvn-server

SVN Post-commit hook for posting on Facebook wall


I'm using Visual SVN Server on my local machine running Windows 7 x64.

I'm looking for a simplest way to create a post-commit hook to some of my local repositories, allowing me to post commit information to my Facebook wall.

Bonus feature would be queueing the messages, if at the time of commit my pc isn't connected to Internet (it's laptop PC).

Best solution wouldn't require installing any other software. I am able of writing HTTP connecting program, I'd however like to use existing software, if any could be helpful.


Solution

  • I've managed to implement a solution that creates a new feed object (i.e. a creates a new post) on Facebook after each commit. The recipe is not fully tested and you should consider it as a proof of concept. I would not use a real Facebook account to test this.

    Environment:

    • Windows Server 2012,
    • VisualSVN Server 2.5.8,
    • Windows Powershell / Powershell ISE,
    • FacebookPSModule.

    Actions:

    Creating Facebook application for our SVN server's commit messages.

    1. Go to https://developers.facebook.com/,
    2. Apps | choose to create a new Facebook app,
    3. As a Display Name use something like "The Smart & Shiny SVN Server",
    4. Request App Domain for the application (remember the URL!),
    5. Remember the App ID.

    Configuring Subversion post-commit hook.

    Powershell script execution must be enabled for the VisualSVN Server service user account.

    1. Install FacebookPSModule (check the docs),
    2. Start Powershell ISE,
    3. Run the command:

      New-FBConnection -AppID <YOUR-APP-ID> -RedirectUri <YOUR-APP-DOMAIN-URL>

      Now you see a web-browser with a Facebook page requesting you to login and to allow access for the SVN server Facebook web app. Login and agree.

    4. Start VisualSVN Server Manager, choose a repository and go to hooks management,

    5. Choose to edit a post-commit hook,

    6. Enter the following code and click OK:

      @echo off
      set PWSH=%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
      %PWSH% -command $input ^| %1\hooks\Facebook.ps1 %1 %2
      if errorlevel 1 exit %errorlevel%
      
    7. Create C:\Repositories\<repo-name>\hooks\Facebook.ps1 and enter the following code to the file:

      $repos = $args[0]
      $rev   = $args[1]
      $logmessage = svnlook info $repos -r $rev 
      New-FBFeed -Message "$logmessage"
      

    That's it! Though the messages are not formatted and the solution has a GREAT ROOM FOR IMPROVEMENT. The room can be compared to the size of the whole universe.