2010-09-21 19:40:32 +04:00
#!/usr/bin/perl
use strict ;
use warnings ;
use BZ::Client ;
use BZ::Client::Bug ;
use Config::Record ;
my $ cfg = Config::Record - > new ( file = > "todo.cfg" ) ;
my $ server = $ cfg - > get ( "bugzilla/server" , "https://bugzilla.redhat.com" ) ;
my $ username = $ cfg - > get ( "bugzilla/username" ) ;
my $ password = $ cfg - > get ( "bugzilla/password" ) ;
my $ product = $ cfg - > get ( "query/product" , "Virtualization Tools" ) ;
my $ todoalias = $ cfg - > get ( "query/todoalias" , "libvirtTodo" ) ;
my $ title = $ cfg - > get ( "output/title" , undef ) ;
my $ blurb = $ cfg - > get ( "output/blurb" , undef ) ;
$ SIG { __DIE__ } = sub {
my $ err = shift ;
if ( UNIVERSAL:: isa ( $ err , "BZ::Client::Exception" ) ) {
2012-07-27 16:51:28 +04:00
die "Unable to access bugzilla: " . $ err - > message ;
2010-09-21 19:40:32 +04:00
}
die $ err ;
} ;
my $ client = BZ::Client - > new ( url = > $ server ,
2012-07-27 16:51:28 +04:00
user = > $ username ,
password = > $ password ) ;
2010-09-21 19:40:32 +04:00
my $ todo = BZ::Client::Bug - > search ( $ client , { 'product' = > $ product ,
2012-07-27 16:51:28 +04:00
'alias' = > $ todoalias } ) ;
2010-09-21 19:40:32 +04:00
die "Cannot find bug alias 'libvirtTodo'" unless $# { $ todo } > - 1 ;
my $ todoid = $ todo - > [ 0 ] - > { 'bug_id' } ;
my $ todosummary = $ todo - > [ 0 ] - > { 'short_desc' } ;
$ todosummary =~ s/^\s*RFE\s*:\s*// ;
$ todosummary =~ s/^\s*\[\s*RFE\s*\]\s*:?\s*// ;
$ todosummary =~ s/^\s*Tracker\s*:\s*// ;
my $ trackers = BZ::Client::Bug - > search ( $ client , { 'product' = > $ product ,
2012-07-27 16:51:28 +04:00
'blocked' = > $ todoid } ) ;
2010-09-21 19:40:32 +04:00
my @ trackers ;
foreach my $ tracker ( @ { $ trackers } ) {
2011-07-07 19:03:22 +04:00
next if $ tracker - > { 'bug_status' } eq "CLOSED" ;
2010-09-21 19:40:32 +04:00
my $ summary = $ tracker - > { 'short_desc' } ;
$ summary =~ s/^\s*RFE\s*:\s*// ;
$ summary =~ s/^\s*\[\s*RFE\s*\]\s*:?\s*// ;
$ summary =~ s/^\s*Tracker\s*:\s*// ;
push @ trackers , {
2012-07-27 16:51:28 +04:00
id = > $ tracker - > { 'bug_id' } ,
summary = > $ summary ,
features = > [] ,
2010-09-21 19:40:32 +04:00
} ;
}
foreach my $ tracker ( @ trackers ) {
my $ features = BZ::Client::Bug - > search ( $ client , { 'product' = > $ product ,
2012-07-27 16:51:28 +04:00
'blocked' = > $ tracker - > { id } } ) ;
2010-09-21 19:40:32 +04:00
foreach my $ feature ( @ { $ features } ) {
2012-07-27 16:51:28 +04:00
next if $ feature - > { 'bug_status' } eq "CLOSED" ;
2011-07-07 19:03:22 +04:00
2012-07-27 16:51:28 +04:00
my $ summary = $ feature - > { 'short_desc' } ;
$ summary =~ s/^\s*RFE\s*:\s*// ;
$ summary =~ s/^\s*\[\s*RFE\s*\]\s*:?\s*// ;
2010-09-21 19:40:32 +04:00
2012-07-27 16:51:28 +04:00
push @ { $ tracker - > { features } } , {
id = > $ feature - > { 'bug_id' } ,
summary = > $ summary ,
} ;
2010-09-21 19:40:32 +04:00
}
}
sub escape {
my $ txt = shift ;
$ txt =~ s/&/&/g ;
$ txt =~ s/</</g ;
$ txt =~ s/>/>/g ;
return $ txt ;
} ;
2013-05-07 14:18:10 +04:00
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ;
print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n" ;
print "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" ;
2010-09-21 19:40:32 +04:00
print " <body>\n" ;
if ( defined $ title ) {
print " <h1>" , & escape ( $ title ) , "</h1>\n" ;
} else {
print " <h1>" , & escape ( $ todosummary ) , "</h1>\n" ;
}
if ( defined $ blurb ) {
print " <p>\n" ;
print $ blurb ;
print " </p>\n" ;
}
foreach my $ tracker ( sort { $ a - > { summary } cmp $ b - > { summary } } @ trackers ) {
2010-11-05 16:24:04 +03:00
next unless $# { $ tracker - > { features } } >= 0 ;
2010-09-21 19:40:32 +04:00
my $ summary = & escape ( $ tracker - > { summary } ) ;
my $ id = $ tracker - > { id } ;
print " <h2><a href=\"$server/$id\">$summary</a></h2>\n" ;
print " <ul>\n" ;
foreach my $ feature ( sort { $ a - > { summary } cmp $ b - > { summary } } @ { $ tracker - > { features } } ) {
2012-07-27 16:51:28 +04:00
$ summary = & escape ( $ feature - > { summary } ) ;
$ summary =~ s , ^ ( [ ^ : ] + ) : , <strong> $ 1 </strong> , ;
2010-09-21 19:40:32 +04:00
2012-07-27 16:51:28 +04:00
$ id = $ feature - > { id } ;
print " <li>$summary (<strong>rhbz <a href=\"$server/$id\">$id</a></strong>)</li>\n" ;
2010-09-21 19:40:32 +04:00
}
print " </ul>\n" ;
}
print " <p>\n" ;
print " This page is automatically generated from <a href=\"$server/$todoid\">" , & escape ( $ todosummary ) , "</a>\n" ;
print " </p>\n" ;
print " </body>\n" ;
print "</html>\n" ;