Annotation of CVSROOT/cvs2rss.pl, revision 1.1
1.1 ! albertel 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: # Important note:
! 17: # If you have html files (or files with html in them) in your CVS Repository, look in your RSS.pm for:
! 18: #
! 19: # $text =~ s/</</g;
! 20: #
! 21: # I suggest commenting out this line because it will screw up this script (I think its a bug in the parser)
! 22: # If you do not, when this script uses XML:RSS's parsefile(), it will mess up any <descriptions> that
! 23: # contain HTML.
! 24: #
! 25: # P.S. The "other" cvs2rss.pl isn't really cvs2rss, it is more like cvs2xml, boo!
! 26: # P.P.S. Parts of this are stolen from commit2rss.rb and the XML::RSS examples.
! 27: #
! 28: # Version 1.0 - 08.24.04 RSS Compliant, no cvs diff capability yet..
! 29: # Version 1.1 - 08.31.04 Adding CVS Diff capability
! 30: #
! 31:
! 32: use strict;
! 33: use XML::RSS;
! 34: use POSIX;
! 35:
! 36: # Stuff you need to setup
! 37: my $rssFeed ="/home/loninst/public_html/loncapa.rss";
! 38: my $emailDomain = "loncapa.org";
! 39: my $channelTitle = "Lon-CAPA RSS Feed";
! 40: my $channelLink = "http://install.loncapa.org/cvs.rss";
! 41: my $numEntries = 200;
! 42:
! 43: # Set this to 1 to enable cvs rdiff (is pretty broken if you are diffing html content)
! 44: my $cvsDiff = 1;
! 45:
! 46: # Leave everything else alone
! 47: my $author = getpwuid(getuid()) . "\@" . $emailDomain;
! 48: $author = 'guy' . "\@" . 'albertelli.com';
! 49: my $pubDate = strftime('%a, %d %b %Y %H:%M:%S %Z',localtime(time));
! 50: my $description;
! 51: my @title=split(",",$ARGV[0]);
! 52:
! 53: my $rss = new XML::RSS(version => '2.0');
! 54: $rss->channel(
! 55: title=> $channelTitle,
! 56: link => $channelLink,
! 57: language => 'en',
! 58: description => $channelTitle,
! 59: copyright => '(c) 2005 MSU Board of Trustees.'
! 60: );
! 61:
! 62: # If rssFeed exists, parse it
! 63: if (-r "$rssFeed") {
! 64: $rss->parsefile($rssFeed);
! 65: }
! 66:
! 67: # Limit entries in the feed to $numEntries
! 68: pop(@{$rss->{'items'}}) while (@{$rss->{'items'}} >= $numEntries);
! 69:
! 70: # Format title of the rss item
! 71: # Remove space, append / and set title to /file/that/changed - oldversion/newversion
! 72: $title[0] =~s/ /\//;
! 73:
! 74: # Format the cvslog msg itself
! 75: while (<STDIN>) {
! 76: chomp($_);
! 77: if ($_=~/^[A-Z].*:\s*$/) {
! 78: $_ = "<br /><b>" . $_ . "</b><br />";
! 79: }
! 80: else {
! 81: $_ .= "<br />";
! 82: }
! 83: $description .= $_;
! 84: }
! 85:
! 86: if ($cvsDiff == 1) {
! 87: # 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)
! 88: # This will rdiff it against the previous version, and include that diff in the rss feed
! 89:
! 90: if (($title[1] != "NONE") && ($title[0]=~/(.*).(txt|java)$/)){
! 91: my $tmpFile = "/tmp/diff.$$";
! 92: my $cmdLine = "cvs -n rdiff -kk -r " . $title[1] . " -r " . $title[2] . " " . $title[0] . ">" . $tmpFile;
! 93: system($cmdLine);
! 94:
! 95: $description .= "<br /><b>Differences:</b><br />";
! 96: open CVSDIFF, "<" . $tmpFile;
! 97: foreach my $line (<CVSDIFF>) {
! 98: chomp($line);
! 99: $description .= $line . "<br />";
! 100: }
! 101: unlink($tmpFile);
! 102: }
! 103: }
! 104:
! 105: $rss->add_item(
! 106: title => "/" . $title[0] . " - " . $title[1] . "/" . $title[2],
! 107: author => $author,
! 108: pubDate => $pubDate,
! 109: description=> $description,
! 110: mode => 'insert'
! 111: );
! 112:
! 113: # XML::RSS doesn't like HTML in the XML so Escape the description body with <![CDATA[ ]]>
! 114: # 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.
! 115: # Certain RSS readers will try and render the HTML regardless of if it is wrapped in a CDATA tag or not so um, deal.
! 116: foreach my $element (@{$rss->{'items'}}) {
! 117: $element->{'description'} = "<![CDATA[" . $element->{'description'} . "]]>";
! 118: }
! 119:
! 120: $rss->save($rssFeed);
! 121:
! 122: # Rsync this rss feed to another publically accessable machine.
! 123: #my $cmdLine="rsync -r -e ssh --delete /export/www/rss/html/ builder\@monkey:/export/www/rss/html/";
! 124: #system($cmdLine);
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>