#!/usr/bin/perl -w use strict; # 2009-03-01 s/git-log/git log/, thanks to Olivier Berger =head1 NAME git2rss --- generate an RSS summary of a git repo =head1 SYNOPSIS git2rss --url repo-url [--max 20] >name.xml =head1 DESCRIPTION git2rss should be run from a git repo. It parses the output of git log, reading up to the last $max (20 default) entries, and generates an RSS feed on stdout. The url arg is mandatory. =cut use Getopt::Long; use XML::RSS::SimpleGen; use IO::File; use Fatal qw(IO::File::new IO::Handle::close); my $url = undef; my $max = 20; my $syntax = "syntax: $0 --url repo-url [--max 20]\n"; GetOptions("url=s" => \$url, "max=i" => \$max) or die $syntax; die "$0: url option is required\n" unless defined $url; my $gitlog = IO::File->new("git log --max-count=$max|"); my $rss = XML::RSS::SimpleGen->new($url, "Bent Linux", "Distro based on uClibc, static linking, bpm packaging"); $rss->webMaster('bet@rahul.net'); sub display { my ($title, $date, $desc) = @_; if ($title =~ /\s/) { $rss->item($url, $title, $date . "\n" . $desc); } else { $rss->item("$url/$title", $title, $date . "\n" . $desc); } } my ($date, $title, $desc); while (defined($_ = $gitlog->getline)) { chomp; if (/^Author: / and defined $title) { display($title, $date, $desc); $date = $title = $desc = undef; } elsif (s/^Date:\s*//) { $date = $_; } elsif (/^\s*$/) { $title = $gitlog->getline; for ($title) { s/^\s*//; s/\s*$//; } while (defined($_ = $gitlog->getline)) { last if /^commit /; $desc .= $_; } } } if (defined $title) { display($title, $date, $desc); } print $rss->as_string;