| 1 |
#! /usr/bin/perl -w |
| 2 |
|
| 3 |
use warnings; |
| 4 |
use strict; |
| 5 |
|
| 6 |
use Debbugs::Config qw(:globals); |
| 7 |
|
| 8 |
use Debbugs::Bugs qw(count_bugs); |
| 9 |
use Debbugs::Status qw(get_bug_status); |
| 10 |
|
| 11 |
package main; |
| 12 |
|
| 13 |
my $startdate = time; |
| 14 |
die "failed to get time: $!" unless defined $startdate; |
| 15 |
|
| 16 |
# check the ctime of '/org/bugs.debian.org/www/stats/bugclosers.txt' |
| 17 |
use File::stat; |
| 18 |
my $ob = stat '/org/bugs.debian.org/www/stats/bugclosers.txt'; |
| 19 |
if (defined $ob and (time - $ob->ctime) < 60*60*12) { |
| 20 |
# If less than 12 hours have passed since we last ran this file, |
| 21 |
# don't rebuild it. |
| 22 |
exit 0; |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
my %bugclosers = count_bugs(function => sub { |
| 27 |
my %d = @_; |
| 28 |
return () unless $d{status} eq 'done'; |
| 29 |
|
| 30 |
my $status = get_bug_status(bug => $d{bug}); |
| 31 |
return () unless %$status; |
| 32 |
my @merged = sort split ' ', $status->{mergedwith}; |
| 33 |
return () if @merged and $merged[0] < $d{bug}; |
| 34 |
|
| 35 |
return ($status->{done}); |
| 36 |
}); |
| 37 |
|
| 38 |
open BUGCLOSERS, '> /org/bugs.debian.org/www/stats/bugclosers.txt.new' |
| 39 |
or die "can't open bugclosers.txt.new: $!"; |
| 40 |
binmode(BUGCLOSERS,':raw:encoding(UTF-8)'); |
| 41 |
for my $closer (sort { $bugclosers{$a} <=> $bugclosers{$b} } keys %bugclosers) { |
| 42 |
printf BUGCLOSERS "%4d %s\n", $bugclosers{$closer}, $closer |
| 43 |
or die "can't write to bugclosers.txt.new: $!"; |
| 44 |
} |
| 45 |
close BUGCLOSERS or die "can't close bugclosers.txt.new: $!"; |
| 46 |
rename '/org/bugs.debian.org/www/stats/bugclosers.txt.new', |
| 47 |
'/org/bugs.debian.org/www/stats/bugclosers.txt' |
| 48 |
or die "can't rename bugclosers.txt.new to bugclosers.txt: $!"; |