User Tools

Site Tools


cvs2rss.php

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
cvs2rss.php [2006/11/13 12:40] 209.8.22.198cvs2rss.php [2006/11/13 13:32] (current) – old revision restored andi
Line 1: Line 1:
 +====== CVS2RSS ======
  
 +Sometimes you want to monitor changes in a CVS server were you have access to install a script like [[http://rebma.cit.cornell.edu/~bs235/projects/cvs2rss/|this one]]. This is when the following script comes in handy. It fetches the needed data from the remote CVS server and converts it to RSS to read in your RSS reader.
 +
 +You need the [[http://www.bitfolge.de/rsscreator-en.html|feedcreator class]] and the cvs commandline utility. 
 +
 +<code php>
 +<?php
 +//you need the feedcreator class from http://www.bitfolge.de/rsscreator-en.html
 +include("feedcreator.class.php");
 +
 +$CVS_BIN  = '/usr/bin/cvs'; #Path to the binary
 +$CVS_ROOT = ':pserver:anonymous@cvs.sourceforge.net:/cvsroot/videodb'; #The CVS root
 +$CVS_REP  = 'videodb'; #The repository in the above root
 +$CVS_DATE = '1 days ago'; #This is to limit the amount of data returned (CVS Date Syntax)
 +$CVS_LINK = 'http://cvs.sourceforge.net/viewcvs.py/videodb/'; #The URL to WebCVS of the project
 +$FILE     = 'cvs-videodb.xml'; #were to cache the resulting feed
 +
 +//Create the feed object
 +$rss = new UniversalFeedCreator();
 +$rss->useCached();
 +$rss->title = "CVS commits for $CVS_REP";
 +$rss->description = "Autogenerated RSS feed for all $CVS_REP commits $CVS_DATE";
 +$rss->link = "$CVS_LINK";
 +#$rss->syndicationURL = ; //FIXME
 +
 +//make params safe
 +$CVS_ROOT = escapeshellarg($CVS_ROOT);
 +$CVS_REP  = escapeshellarg($CVS_REP);
 +$CVS_DATE = escapeshellarg($CVS_DATE);
 +
 +//fetch data
 +$changes = cvs_commits();
 +
 +//add items if any
 +foreach($changes as $change){
 +  $fields = preg_split('!\s+!',$change);
 +
 +  ($fields[7] == 'CVSROOT') ? $dir = '' : $dir = $fields[7];
 +
 +  $file = $dir.'/'.$fields[6];
 +
 +  $item = new FeedItem();
 +  $item->title  = $file.' '.cvs_flags($fields[0]);
 +  $item->link   = $CVS_LINK.$file.'?rev='.$fields[5];
 +  $item->author = $fields[4];
 +  $item->date   = strtotime($fields[1].' '.$fields[2].' '.$fields[3]);
 +  $item->description = cvs_details($file,$fields[5]);
 +  $rss->addItem($item);
 +
 +}
 +
 +
 +$rss->saveFeed("RSS2.0", $FILE);
 +//endof main
 +
 +
 +
 +// fetch commit data
 +function cvs_commits(){
 +  global $CVS_BIN;
 +  global $CVS_ROOT;
 +  global $CVS_REP;
 +  global $CVS_DATE;
 +
 +  $changes = array();
 +  $cmd = "$CVS_BIN -d $CVS_ROOT history -c -a -l -p $CVS_REP -D $CVS_DATE";
 +  $changes = split("\n",shell_exec($cmd));
 +
 +  if(count($changes) == 0 || $changes[0] == 'No records selected.'){
 +    return array();
 +  }
 +  return $changes;
 +}
 +
 +// fetch file description
 +function cvs_details($file,$rev){
 +  global $CVS_BIN;
 +  global $CVS_ROOT;
 +
 +  @set_time_limit(30); //reset execution time
 +
 +  $file = escapeshellarg($file);
 +  $cmd  = "$CVS_BIN -d $CVS_ROOT rlog -r$rev $file";
 +
 +  $out = shell_exec($cmd);
 +
 +  if(preg_match('!description:(.*)$!s',$out,$matches)){
 +    $out = trim($matches[1]);
 +    $out = trim($out,'=-');
 +    $out = nl2br($out);
 +  }
 +  return $out;
 +}
 +
 +
 +// realname for cvs flags
 +function cvs_flags($flag){
 +  switch ($flag){
 +    case 'O': return 'checked out';
 +    case 'T': return 'tagged';
 +    case 'F': return 'released';
 +    case 'W': return 'removed from form entries';
 +    case 'U': return 'overwritten';
 +    case 'G': return 'merged';
 +    case 'C': return 'merged with conflicts';
 +    case 'M': return 'modified';
 +    case 'A': return 'added';
 +    case 'R': return 'removed file';
 +    case 'E': return 'exported';
 +  }
 +}
 +
 +?>
 +</code>
cvs2rss.php.txt · Last modified: 2006/11/13 13:32 by andi