File:  [LON-CAPA] / CVSROOT / cvs2rss.pl
Revision 1.3: download - view: text, annotated - select for diffs
Wed Oct 12 16:50:42 2005 UTC (18 years, 5 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- switch to using unified diffs

    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 $rssFeed ="/home/loninst/public_html/loncapa.rss";
   33: my $emailDomain = "loncapa.org";
   34: my $channelTitle = "Lon-CAPA RSS Feed";
   35: my $channelLink = "http://install.loncapa.org/loncapa.rss";
   36: my $numEntries = 200;
   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()) . "\@" . $emailDomain;
   43: $author = 'guy' . "\@" . 'albertelli.com';
   44: my $pubDate = strftime('%a, %d %b %Y %H:%M:%S %Z',localtime(time));
   45: my $description;
   46: my @title=split(",",$ARGV[0]);
   47: 
   48: my $rss = new XML::RSS(version => '2.0');
   49: $rss->channel(
   50: 	title=> $channelTitle,
   51: 	link => $channelLink,
   52: 	language => 'en',
   53: 	description => $channelTitle,
   54: 	copyright => '(c) 2005 MSU Board of Trustees.'
   55: );
   56: 
   57: # If rssFeed exists, parse it
   58: if (-r "$rssFeed") {
   59: 	$rss->parsefile($rssFeed);
   60: }
   61: 
   62: # Limit entries in the feed to $numEntries
   63: pop(@{$rss->{'items'}}) while (@{$rss->{'items'}} >= $numEntries);
   64: 
   65: # Format title of the rss item
   66: # Remove space, append / and set title to /file/that/changed - oldversion/newversion
   67: $title[0] =~s/ /\//;
   68: 
   69: # Format the cvslog msg itself
   70: while (<STDIN>) {
   71: 	chomp($_);
   72: 	if ($_=~/^[A-Z].*:\s*$/) {
   73: 		$_ = "<br /><b>" . $_ . "</b><br />";
   74: 	}
   75: 	else {
   76: 		$_ .= "<br />";
   77: 	}
   78: 	$description .= $_;
   79: }
   80: 
   81: if ($cvsDiff == 1) {
   82: 	# 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)
   83: 	# This will rdiff it against the previous version, and include that diff in the rss feed
   84: 
   85: 	if (($title[1] != "NONE") && ($title[0]=~/(.*).(pm)$/)){
   86: 		my $tmpFile = "/tmp/diff.$$";
   87: 		my $cmdLine = "cvs -n rdiff -u -kk -r " . $title[1] .  " -r " . $title[2] . " " . $title[0] . ">" . $tmpFile;
   88: 		system($cmdLine);
   89: 
   90: 		$description .= "<br /><b>Differences:</b><br /><pre>";
   91: 		open CVSDIFF, "<" . $tmpFile;
   92: 		foreach my $line (<CVSDIFF>) {
   93: 			$description .= &HTML::Entities::encode($line,'<>&"');
   94: 		}
   95: 		$description .= "</pre>";
   96: 		unlink($tmpFile);   
   97: 	} 
   98: }
   99: 
  100: $rss->add_item(
  101: 	title => "/" . $title[0] . " - " . $title[1] . "/" . $title[2],
  102: 	author => $author,
  103: 	pubDate => $pubDate, 
  104: 	description=> $description,
  105: 	mode => 'insert'
  106: );		
  107: 
  108: foreach my $element (@{$rss->{'items'}}) {
  109: 	$element->{'description'} = &HTML::Entities::encode($element->{'description'},'<>&"'); 
  110: }
  111: 
  112: $rss->save($rssFeed);
  113: 
  114: # Rsync this rss feed to another publically accessable machine.
  115: #my $cmdLine="rsync -r -e ssh --delete /export/www/rss/html/ builder\@monkey:/export/www/rss/html/";
  116: #system($cmdLine);

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