File:  [LON-CAPA] / CVSROOT / cvs2rss.pl
Revision 1.13: download - view: text, annotated - select for diffs
Wed Nov 26 18:43:30 2008 UTC (13 years, 8 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Eliminate custom use of HTML::Entities() - XML::RSS 1.36 now used on CVS server does this automatically.
- location of RSS feed changed (new CVS server).
- style.

    1: #!/usr/bin/perl
    2: # Kyle Christensen <kyle@junglist.org>
    3: # http://junglist.org/files/scripts/cvs2rss.pl
    4: # 
    5: # This script (when setup properly) will magically create an RSS 2.0 compliant feed
    6: # that logs your cvs commits as well as a diff of the changes made.
    7: #
    8: # Run this from your CVSROOT/loginfo like:
    9: #
   10: #	/path/to/cvs2rss.pl %{sVv}
   11: #
   12: # Also, make sure your apache server has an AddType for rss like:
   13: #
   14: # 	AddType application/rss+xml .rss
   15: #
   16: # P.S. The "other" cvs2rss.pl isn't really cvs2rss, it is more like cvs2xml, boo!
   17: # P.P.S. Parts of this are stolen from commit2rss.rb and the XML::RSS examples.
   18: #
   19: # Version 1.0 - 08.24.04 RSS Compliant, no cvs diff capability yet..
   20: # Version 1.1 - 08.31.04 Adding CVS Diff capability
   21: # Edit by Guy Albertelli, -- corrected the packaging of Entities
   22: #                          - commits now <pre>ed
   23: #                          - removed html rants
   24: # Edit by Stuart Raeburn, -- eliminated earlier HTML::Entities customization.
   25: 
   26: use strict;
   27: use XML::RSS;
   28: use POSIX;
   29: 
   30: # Stuff you need to setup 
   31: my $cvslink = 'http://source.loncapa.org/cgi-bin/cvsweb.cgi/';
   32: my $rssFeed ="/home/rss/cvs.rss";
   33: my $emailDomain = "loncapa.org";
   34: my $channelTitle = "Lon-CAPA RSS Feed";
   35: my $channelLink = "http://source.loncapa.org/rss/cvs.rss";
   36: my $numEntries = 30;
   37: 
   38: # Set this to 1 to enable cvs rdiff
   39: my $cvsDiff = 1;
   40: 
   41: # Leave everything else alone
   42: my $author = getpwuid(getuid());
   43: my $pubDate = strftime('%a, %d %b %Y %H:%M:%S %Z',localtime(time));
   44: 
   45: my @args = split(" ", $ARGV[0]);
   46: my $dir = shift(@args);
   47: 
   48: # bail when this is a new directory
   49: &bail if $args[0] eq '-' && "$args[1] $args[2]" eq 'New directory';
   50: # bail if this is an import
   51: &bail if $args[0] eq '-' && $args[1] eq 'Imported';
   52: 
   53: 
   54: my $rss = new XML::RSS(version => '2.0');
   55: 
   56: # If rssFeed exists, parse it
   57: if (-r "$rssFeed") {
   58:     $rss->parsefile($rssFeed);
   59: }
   60: 
   61: $rss->channel(
   62: 	      title=> $channelTitle,
   63: 	      link => $channelLink,
   64: 	      language => 'en',
   65: 	      description => $channelTitle,
   66: 	      copyright => '(c) 2005 MSU Board of Trustees.',
   67: 	      pubDate => $pubDate 
   68: 	      );
   69: 
   70: # Limit entries in the feed to $numEntries
   71: pop(@{$rss->{'items'}}) while (@{$rss->{'items'}} >= $numEntries);
   72: 
   73: my $commit_msg;
   74: while (<STDIN>) {
   75:     chomp($_);
   76:     if ($_=~/^[A-Z].*:\s*$/) {
   77: 	$_ = "<br /><b>" .$_."</b><br />";
   78:     } else {
   79: 	$_ .= "<br />";
   80:     }
   81:     $commit_msg .= $_;
   82: }
   83: 
   84: $commit_msg .= '<br /><b>Author:</b><br />'.$author.'<br />';
   85: 
   86: foreach my $file (@args) {
   87:     my @title=split(",",$file);
   88: 
   89:     my $description = $commit_msg;
   90:     # Format title of the rss item
   91:     # Remove space, append / and set title to /file/that/changed - oldversion/newversion
   92:     $title[0] =~s/ /\//;
   93:     $title[0] = $dir.'/'.$title[0];
   94: 
   95:     # Format the cvslog msg itself
   96: 
   97:     if ($cvsDiff == 1) { 
   98: 
   99: 	# If the old version of the file is not NONE (if
  100: 	# it isn't a new file), and if it is a pm/pl/conf/tab file.
  101: 	# This will rdiff it against the previous version, and
  102: 	# include that diff in the rss feed
  103: 
  104: 	if (($title[1] != "NONE") 
  105: 	    && ($title[0]=~/(.*)\.(pm|pl|conf|tab)$/)
  106: 	    && ($title[0]!~{/localize/localize/..\.pm}) ) {
  107: 	    my $tmpFile = "/tmp/diff.$$";
  108: 	    my $cmdLine = "cvs -n rdiff -u -kk -r " . $title[1] .  " -r " . $title[2] . " " . $title[0] . ">" . $tmpFile;
  109: 	    system($cmdLine);
  110: 	    
  111: 	    $description .= "<br /><b>Differences:</b><br /><pre>";
  112: 	    open CVSDIFF, "<" . $tmpFile;
  113: 	    foreach my $line (<CVSDIFF>) {
  114: 		$description .= $line;
  115: 	    }
  116: 	    $description .= "</pre>";
  117: 	    unlink($tmpFile);   
  118: 	}
  119:     }
  120: 
  121:     my $link = $cvslink.$title[0];
  122:     if ($title[1] != "NONE") {
  123:         $link .= '.diff?r1='.$title[1].';r2='.$title[2].';f=h';
  124:     }
  125: 
  126:     $rss->add_item(
  127: 		   title => "/" . $title[0] . " - " . $title[1] . "/" . $title[2],
  128: 		   author => $author,
  129: 		   description=> $description,
  130: 		   mode => 'insert',
  131: 		   pubDate => $pubDate,
  132: 		   link => $link
  133: 		   );		
  134: }
  135: 
  136: $rss->save($rssFeed);
  137: 
  138: # Rsync this rss feed to another publically accessable machine.
  139: #my $cmdLine="rsync -r -e ssh --delete /export/www/rss/html/ builder\@monkey:/export/www/rss/html/";
  140: #system($cmdLine);
  141: 
  142: sub bail {
  143:     my @toss = <STDIN>;
  144:     exit @_;
  145: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>