File:  [LON-CAPA] / CVSROOT / cvs2rss.pl
Revision 1.11: download - view: text, annotated - select for diffs
Tue Oct 25 14:09:48 2005 UTC (16 years, 8 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- ugh, okay now I think I got the multi file commit correct

    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: #
   25: 
   26: use strict;
   27: use HTML::Entities();
   28: use XML::RSS;
   29: use POSIX;
   30: 
   31: # Stuff you need to setup 
   32: my $cvslink = 'http://install.loncapa.org/cgi-bin/cvsweb.cgi/';
   33: my $rssFeed ="/home/loninst/public_html/loncapa.rss";
   34: my $emailDomain = "loncapa.org";
   35: my $channelTitle = "Lon-CAPA RSS Feed";
   36: my $channelLink = "http://install.loncapa.org/loncapa.rss";
   37: my $numEntries = 200;
   38: 
   39: # Set this to 1 to enable cvs rdiff
   40: my $cvsDiff = 1;
   41: 
   42: # Leave everything else alone
   43: my $author = getpwuid(getuid());
   44: my $pubDate = strftime('%a, %d %b %Y %H:%M:%S %Z',localtime(time));
   45: 
   46: my @args = split(" ", $ARGV[0]);
   47: my $dir = shift(@args);
   48: 
   49: # bail when this is a new directory
   50: &bail if $args[0] eq '-' && "$args[1] $args[2]" eq 'New directory';
   51: # bail if this is an import
   52: &bail if $args[0] eq '-' && $args[1] eq 'Imported';
   53: 
   54: 
   55: my $rss = new XML::RSS(version => '2.0');
   56: 
   57: # If rssFeed exists, parse it
   58: if (-r "$rssFeed") {
   59:     $rss->parsefile($rssFeed);
   60: }
   61: 
   62: $rss->channel(
   63: 	      title=> $channelTitle,
   64: 	      link => $channelLink,
   65: 	      language => 'en',
   66: 	      description => $channelTitle,
   67: 	      copyright => '(c) 2005 MSU Board of Trustees.',
   68: 	      pubDate => $pubDate 
   69: 	      );
   70: 
   71: # Limit entries in the feed to $numEntries
   72: pop(@{$rss->{'items'}}) while (@{$rss->{'items'}} >= $numEntries);
   73: 
   74: my $commit_msg;
   75: while (<STDIN>) {
   76:     chomp($_);
   77:     if ($_=~/^[A-Z].*:\s*$/) {
   78: 	$_ = "<br /><b>" . &HTML::Entities::encode($_,'<>&"') . "</b><br />";
   79:     } else {
   80: 	$_ = &HTML::Entities::encode($_,'<>&"');
   81: 	$_ .= "<br />";
   82:     }
   83:     $commit_msg .= $_;
   84: }
   85: 
   86: $commit_msg .= '<br /><b>Author:</b><br />'.$author.'<br />';
   87: 
   88: foreach my $file (@args) {
   89:     my @title=split(",",$file);
   90: 
   91:     my $description = $commit_msg;
   92:     # Format title of the rss item
   93:     # Remove space, append / and set title to /file/that/changed - oldversion/newversion
   94:     $title[0] =~s/ /\//;
   95:     $title[0] = $dir.'/'.$title[0];
   96: 
   97:     # Format the cvslog msg itself
   98: 
   99:     if ($cvsDiff == 1) { 
  100: 
  101: 	# If the old version of the file is not NONE (if
  102: 	# it isn't a new file), and if it is a pm/pl/conf/tab file.
  103: 	# This will rdiff it against the previous version, and
  104: 	# include that diff in the rss feed
  105: 
  106: 	if (($title[1] != "NONE") && ($title[0]=~/(.*).(pm|pl|conf|tab)$/)){
  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 .= &HTML::Entities::encode($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: foreach my $element (@{$rss->{'items'}}) {
  137:     $element->{'description'} = 
  138: 	&HTML::Entities::encode($element->{'description'},'<>&"');
  139: }
  140: 
  141: $rss->save($rssFeed);
  142: 
  143: # Rsync this rss feed to another publically accessable machine.
  144: #my $cmdLine="rsync -r -e ssh --delete /export/www/rss/html/ builder\@monkey:/export/www/rss/html/";
  145: #system($cmdLine);
  146: 
  147: sub bail {
  148:     my @toss = <STDIN>;
  149:     exit @_;
  150: }

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