====== 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. 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'; } } ?>