summaryrefslogtreecommitdiff
path: root/docs/todo.pl
blob: 36698e8ade0ded18cb91b3d9ec94f863a8908e76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/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")) {
        die "Unable to access bugzilla: " . $err->message;
    }
    die $err;
};

my $client = BZ::Client->new(url => $server,
                             user => $username,
                             password => $password);

my $todo = BZ::Client::Bug->search($client, {'product' => $product,
                                             'alias' => $todoalias});

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,
                                                 'blocked' => $todoid });

my @trackers;

foreach my $tracker (@{$trackers}) {
    next if $tracker->{'bug_status'} eq "CLOSED";

    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, {
        id => $tracker->{'bug_id'},
        summary => $summary,
        features => [],
    };
}

foreach my $tracker (@trackers) {
    my $features = BZ::Client::Bug->search($client, {'product' => $product,
                                                     'blocked' => $tracker->{id}});

    foreach my $feature (@{$features}) {
        next if $feature->{'bug_status'} eq "CLOSED";

        my $summary = $feature->{'short_desc'};
        $summary =~ s/^\s*RFE\s*:\s*//;
        $summary =~ s/^\s*\[\s*RFE\s*\]\s*:?\s*//;

        push @{$tracker->{features}}, {
            id => $feature->{'bug_id'},
            summary => $summary,
        };
    }
}

sub escape {
    my $txt = shift;
    $txt =~ s/&/&/g;
    $txt =~ s/</&lt;/g;
    $txt =~ s/>/&gt;/g;
    return $txt;
};

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";
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) {
    next unless $#{$tracker->{features}} >= 0;

    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}}) {
        $summary = &escape($feature->{summary});
        $summary =~ s,^([^:]+):,<strong>$1</strong>,;

        $id = $feature->{id};
        print "      <li>$summary (<strong>rhbz <a href=\"$server/$id\">$id</a></strong>)</li>\n";
    }
    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";