--- CVSROOT/cvs2rss.pl 2005/10/11 19:45:18 1.1 +++ CVSROOT/cvs2rss.pl 2005/10/24 21:53:20 1.9 @@ -13,23 +13,18 @@ # # AddType application/rss+xml .rss # -# Important note: -# If you have html files (or files with html in them) in your CVS Repository, look in your RSS.pm for: -# -# $text =~ s/ that -# contain HTML. -# # P.S. The "other" cvs2rss.pl isn't really cvs2rss, it is more like cvs2xml, boo! # P.P.S. Parts of this are stolen from commit2rss.rb and the XML::RSS examples. # # Version 1.0 - 08.24.04 RSS Compliant, no cvs diff capability yet.. # Version 1.1 - 08.31.04 Adding CVS Diff capability +# Edit by Guy Albertelli, -- corrected the packaging of Entities +# - commits now
ed
+#                          - removed html rants
 #
 
 use strict;
+use HTML::Entities();
 use XML::RSS;
 use POSIX;
 
@@ -37,10 +32,10 @@ use POSIX;
 my $rssFeed ="/home/loninst/public_html/loncapa.rss";
 my $emailDomain = "loncapa.org";
 my $channelTitle = "Lon-CAPA RSS Feed";
-my $channelLink = "http://install.loncapa.org/cvs.rss";
+my $channelLink = "http://install.loncapa.org/loncapa.rss";
 my $numEntries = 200;
 
-# Set this to 1 to enable cvs rdiff (is pretty broken if you are diffing html content)
+# Set this to 1 to enable cvs rdiff
 my $cvsDiff = 1;
 
 # Leave everything else alone
@@ -48,73 +43,93 @@ my $author = getpwuid(getuid()) . "\@" .
 $author = 'guy' . "\@" . 'albertelli.com';
 my $pubDate = strftime('%a, %d %b %Y %H:%M:%S %Z',localtime(time));
 my $description;
-my @title=split(",",$ARGV[0]);
+
+
+my @args = split(" ", $ARGV[0]);
+# bail when this is a new directory
+&bail if $args[0] eq '-' && "$args[1] $args[2]" eq 'New directory';
+# bail if this is an import
+&bail if $args[0] eq '-' && $args[1] eq 'Imported';
+
 
 my $rss = new XML::RSS(version => '2.0');
-$rss->channel(
-	title=> $channelTitle,
-	link => $channelLink,
-	language => 'en',
-	description => $channelTitle,
-	copyright => '(c) 2005 MSU Board of Trustees.'
-);
 
 # If rssFeed exists, parse it
 if (-r "$rssFeed") {
-	$rss->parsefile($rssFeed);
+    $rss->parsefile($rssFeed);
 }
 
+$rss->channel(
+	      title=> $channelTitle,
+	      link => $channelLink,
+	      language => 'en',
+	      description => $channelTitle,
+	      copyright => '(c) 2005 MSU Board of Trustees.',
+	      pubDate => $pubDate 
+	      );
+
 # Limit entries in the feed to $numEntries
 pop(@{$rss->{'items'}}) while (@{$rss->{'items'}} >= $numEntries);
 
-# Format title of the rss item
-# Remove space, append / and set title to /file/that/changed - oldversion/newversion
-$title[0] =~s/ /\//;
+foreach my $file (@args) {
+    my @title=split(",",$file);
 
-# Format the cvslog msg itself
-while () {
+
+    # Format title of the rss item
+    # Remove space, append / and set title to /file/that/changed - oldversion/newversion
+    $title[0] =~s/ /\//;
+    
+    # Format the cvslog msg itself
+    while () {
 	chomp($_);
 	if ($_=~/^[A-Z].*:\s*$/) {
-		$_ = "
" . $_ . "
"; - } - else { - $_ .= "
"; + $_ = "
" . &HTML::Entities::encode($_,'<>&"') . "
"; + } else { + $_ = &HTML::Entities::encode($_,'<>&"'); + $_ .= "
"; } $description .= $_; -} + } -if ($cvsDiff == 1) { - # If the old version of the file is not NONE (if it isn't a new file), and if it is a .txt or .java file (that has no html) - # This will rdiff it against the previous version, and include that diff in the rss feed - - if (($title[1] != "NONE") && ($title[0]=~/(.*).(txt|java)$/)){ - my $tmpFile = "/tmp/diff.$$"; - my $cmdLine = "cvs -n rdiff -kk -r " . $title[1] . " -r " . $title[2] . " " . $title[0] . ">" . $tmpFile; - system($cmdLine); - - $description .= "
Differences:
"; - open CVSDIFF, "<" . $tmpFile; - foreach my $line () { - chomp($line); - $description .= $line . "
"; - } - unlink($tmpFile); - } -} + if ($cvsDiff == 1) { -$rss->add_item( - title => "/" . $title[0] . " - " . $title[1] . "/" . $title[2], - author => $author, - pubDate => $pubDate, - description=> $description, - mode => 'insert' -); - -# XML::RSS doesn't like HTML in the XML so Escape the description body with -# This is messy and stupid, but both XML::RSS and XML are sort of dumb, and I can't figure out a way around it. -# Certain RSS readers will try and render the HTML regardless of if it is wrapped in a CDATA tag or not so um, deal. -foreach my $element (@{$rss->{'items'}}) { - $element->{'description'} = "{'description'} . "]]>"; + # If the old version of the file is not NONE (if + # it isn't a new file), and if it is a pm/pl/conf/tab file. + # This will rdiff it against the previous version, and + # include that diff in the rss feed + + if (($title[1] != "NONE") && ($title[0]=~/(.*).(pm|pl|conf|tab)$/)){ + my $tmpFile = "/tmp/diff.$$"; + my $cmdLine = "cvs -n rdiff -u -kk -r " . $title[1] . " -r " . $title[2] . " " . $title[0] . ">" . $tmpFile; + system($cmdLine); + + $description .= "
Differences:
";
+	    open CVSDIFF, "<" . $tmpFile;
+	    foreach my $line () {
+		$description .= &HTML::Entities::encode($line,'<>&"');
+	    }
+	    $description .= "
"; + unlink($tmpFile); + } + } + + my $link = 'http://install.loncapa.org/cgi-bin/cvsweb.cgi/'.$title[0]; + if ($title[1] != "NONE") { + $link .= '.diff?r1='.$title[1].';r2='.$title[2].';f=h'; + } + + $rss->add_item( + title => "/" . $title[0] . " - " . $title[1] . "/" . $title[2], + author => $author, + description=> $description, + mode => 'insert', + pubDate => $pubDate, + link => $link + ); + + foreach my $element (@{$rss->{'items'}}) { + $element->{'description'} = &HTML::Entities::encode($element->{'description'},'<>&"'); + } } $rss->save($rssFeed); @@ -122,3 +137,8 @@ $rss->save($rssFeed); # Rsync this rss feed to another publically accessable machine. #my $cmdLine="rsync -r -e ssh --delete /export/www/rss/html/ builder\@monkey:/export/www/rss/html/"; #system($cmdLine); + +sub bail { + my @toss = ; + exit @_; +} 500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.