[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Post-commit hook tutorials?

From: Robert Denton <robert_at_headsprout.com>
Date: Tue, 04 Mar 2008 15:04:20 -0800

Thanks everyone for the terrific input. Here is how my solution took form:

Instead of having the hook directly copy the file in question to the windows server, all I needed to do was determine what was committed and then pass that in a URL var to a cold fusion page. I am fortunate in that I am surrounded on all sides by CF guys who love to do everything in CF. Simplifies my job quite a bit.

First the hook script doesn't do any work itself, it just calls other scripts:

[rogerroger_at_svn etc]# more /svn/repos/RIPgaryg/hooks/post-commit
#!/bin/sh

REPOS="$1"
REV="$2"

/svn/etc/svnsync.sh
/svn/etc/sounds.pl $REPOS $REV

As far as the sounds script goes, the general consensus was dead on: svnlook is the ticket:

 
#! /usr/bin/perl

use LWP;

$repo = $ARGV[0];
$rev = $ARGV[1];
$mail_options = "-s 'A sound file has been commited' svn-commits\@10.78.222.39";

@changes = `svnlook changed $repo -r $rev`;

while (@changes) {
   $commited_item = shift(@changes);
   if ($commited_item =~ /(trunk.*\/sound\/.*)/) {
      `echo "$1" | mail $mail_options`;
      sound2fusion($1);
   }
}

sub sound2fusion {
   my $agent = LWP::UserAgent->new;
   my $cfmfile = "svn_test1.html";
   my $url_var = "?VAR=$_[0]";
   my $uri = "http://10.79.26.1/$cfmfile$url_var";
   my $mail_fail = "-s 'ALERT! Sound Commit Hook Failure!'";

   $HTTPrequest = HTTP::Request->new(GET => $uri);
   $HTTPresponse = $agent->request($HTTPrequest);

   $fail_string = "The file $_[0] was committed but the call to $uri failed. The HTTP Response was: " . $HTTPresponse->status_line;

   if (!($HTTPresponse->is_success)) {
      `echo "$fail_string" | mail $mail_fail svn-commits\@10.78.222.39`;
   }

   #print " ***> HTTPResponse: " . $HTTPresponse->content . "\n";
   #print " ***> HTTPResponse: " . $HTTPresponse->status_line . "\n";
   #print " ***> HTTPResponse: " . $HTTPresponse->code . "\n";
   #print " ***> HTTPResponse: " . $HTTPresponse->message . "\n";

} # end sub sound2fusion

Something less than polished at this point but it is doing exactly what I need it to do. I thought I'd offer it up for anyone who needs a similar solution in the future. Thanks again!

Robert
  
Received on 2008-03-05 00:04:43 CET

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.