forked from rjbs/misc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bugagg
executable file
·190 lines (151 loc) · 4.12 KB
/
bugagg
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/perl
use strict;
use warnings;
use Compress::Zlib;
use Email::Send;
use Email::Simple;
use Email::Simple::Creator;
use HTML::TreeBuilder;
use String::Truncate
trunc => { length => 4, -as => 'sev_trunc' },
elide => { length => 47, -as => 'subj_elide' };
use Text::Table;
use Time::Duration::Parse;
use WWW::Mechanize;
my $CPAN = $ENV{BUGAGG_CPAN} || '/home/rjbs/minicpan';
my %CONFIG = (
rjbs => {
subject => 'RJBS Bugs',
to => '[email protected]',
via => 'a.mx.manxome.org',
dist_re => qr{/RJBS/([-.\w]+)-\d.+.tar.gz},
},
pep => {
subject => 'Perl Email Bugs',
to => '[email protected]',
via => 'thorn.listbox.com',
headers => [ Approved => '8939392E-95A9-11DB-991D-3BF496CB58F4' ],
dist_re => qr{/((?:(?:E?mail)|MIME)[-.\w]+)-\d.+.tar.gz},
},
);
my %config = eval { %{ $CONFIG{ $ARGV[0] } } } or die "usage: bugagg <setname>";
my $dist_re = $config{dist_re};
my %SEVERITY = (
Critical => 100,
Important => 90,
Normal => 80,
Unimportant => 70,
Wishlist => 60,
);
sub sev_value {
my ($severity) = @_;
return 0 unless exists $SEVERITY{ $severity };
return $SEVERITY{ $severity };
}
my $packages_gz = gzopen(
"$CPAN/modules/02packages.details.txt.gz",
'rb',
);
my @dists = do {
my $line;
my %dists;
while ($packages_gz->gzreadline($line) > 0) {
next unless $line =~ $dist_re;
$dists{$1} = 1;
}
keys %dists;
};
sub compress_name {
my ($dist, $extra) = @_;
my @split = split /-/, $dist;
my $last = pop @split;
join '', (map { substr $_, 0, 1 } @split),
substr $last, 0, $extra + 1;
}
my %unique_name;
{
my $i = 0;
$unique_name{$_} = compress_name($_, $i) for @dists;
while (1) {
my %seen;
$seen{$_}++ for values %unique_name;
my @abbr = grep { $seen{$_} > 1 } keys %seen;
last unless @abbr;
for my $abbr (@abbr) {
for my $dist (grep { $unique_name{$_} eq $abbr } @dists) {
$unique_name{ $dist } = compress_name($dist, $i);
}
}
$i++;
}
}
my $mech = WWW::Mechanize->new;
my @bugs;
for my $dist (@dists) {
my $url
= sprintf "http://rt.cpan.org/Public/Dist/Display.html?Name=%s", $dist;
$mech->get($url);
my $tree = HTML::TreeBuilder->new_from_content($mech->content);
my @rows = (
$tree->look_down(_tag => 'tr', class => 'oddline'),
$tree->look_down(_tag => 'tr', class => 'evenline')
);
for my $bug (@rows) {
my %bug;
@bug{qw(id subject status severity last_update broken_in fixed_in)}
= map { $_->as_text } $bug->look_down(_tag => 'td');
$bug{sev_value} = sev_value($bug{severity});
$bug{last_update} =~ s/ ago$//;
$bug{ago_value} = parse_duration($bug{last_update});
$bug{dist} = $dist;
push @bugs, \%bug;
}
}
my @columns = qw(id severity dist subject last_update);
my @headers = map {
my $c = $_;
$c =~ s/severity/sev/;
$c =~ s/last_//;
$c, \' | '
} @columns;
pop @headers;
my $table = Text::Table->new(@headers);
my $html = "<table><tr>"
. join('', map { "<th>$_</th>" } grep { ! ref $_ } @headers)
. "</tr>";
my %xform = (
severity => \&sev_trunc,
subject => \&subj_elide,
dist => sub { $unique_name{$_[0]} },
last_update => sub { my $v = $_[0]; $v =~ s/(\s..)\S+$/$1/g; $v },
);
sub bug_sort {
$b->{sev_value} <=> $a->{sev_value}
|| $b->{ago_value} <=> $a->{ago_value}
}
for my $bug (sort bug_sort @bugs) {
$table->add(map {
exists $xform{$_} ? $xform{$_}($bug->{$_}) : $bug->{$_}
} @columns);
$html .= "<tr>"
. join('', map {
"<td>"
. (exists $xform{$_} ? $xform{$_}($bug->{$_}) : $bug->{$_})
. "</td>"
} @columns)
. "</tr>";
}
my $email = Email::Simple->create(
header => [
From => 'MechaRJBS <[email protected]>',
To => $config{to},
Subject => "$config{subject} " . scalar localtime,
@{ $config{headers} || [] },
],
body => "$table"
);
print $html;
my $sender = Email::Send->new({ mailer => 'SMTP' });
$sender->mailer_args([ Host => $config{via} ]);
#my $rv = $sender->send($email);
#die "failed to send: $rv" unless $rv;