new ticket from slaven
[andk-cpan-tools.git] / bin / send_tr_reports.pl
blobcc817118a5fccb2eeb898e901ae00ed2c6445b92
1 #!/usr/bin/perl
4 # $Id: send_tr_reports.pl,v 1.10 2010/09/03 20:48:26 eserte Exp $
5 # Author: Slaven Rezic
7 # Copyright (C) 2008 Slaven Rezic. All rights reserved.
8 # This program is free software; you can redistribute it and/or
9 # modify it under the same terms as Perl itself.
11 # Mail: slaven@rezic.de
12 # WWW: http://www.rezic.de/eserte/
15 use strict;
16 use Getopt::Long;
17 use Test::Reporter;
18 use Metabase::Resource::cpan::distfile;
19 use File::Basename;
21 my $use_mail;
22 my $opt_transport_uri;
23 GetOptions("mail" => \$use_mail,
24 "transport-uri=s" => \$opt_transport_uri,
26 or die "usage: $0 [--mail] [--transport-uri=TRANSPORT-URI]";
28 $opt_transport_uri //= 'https://metabase.cpantesters.org/api/v1/';
29 my $reportdir = shift || "$ENV{HOME}/var/ctr";
31 my $sync_dir = "$reportdir/sync";
32 my $done_dir = "$reportdir/done";
33 my $process_dir = "$reportdir/process";
34 my $quarantine_dir = "$reportdir/quarantine";
36 if (!-d $sync_dir) {
37 warn "Create $sync_dir and move reports to this directory...";
39 for my $dir ($done_dir, $process_dir, $quarantine_dir) {
40 if (!-d $dir) {
41 mkdir $dir or die "While creating $dir: $!";
45 FILE: for my $file (glob("$sync_dir/pass.*.rpt"),
46 glob("$sync_dir/unknown.*.rpt"),
47 glob("$sync_dir/na.*.rpt"),
48 glob("$sync_dir/fail.*.rpt"),
49 ) {
50 warn "File $file does not exist anymore?", next if !-r $file;
51 warn "$file...\n";
52 my $quarantine_file = $quarantine_dir . "/" . basename($file);
53 if ($file =~ m|/pass\.-0\.01\.|) {
54 warn "skipping to avoid a CPAN::DistnameInfo bug (# 72512)";
55 rename $file, $quarantine_file or die "Could not rename...: $!";
56 next FILE;
59 open my $fh, $file or die "Could not open '$file': $!";
60 local $/ = "\n";
61 my $vdistro;
62 while (<$fh>) {
63 next unless /X-Test-Reporter-Distfile:\s*(\S+)/;
64 $vdistro = $1;
65 last;
67 if ($vdistro) {
68 my $result = eval { Metabase::Resource::cpan::distfile->_validate_distfile($vdistro) };
69 unless ($result) {
70 warn "skipping to avoid killing the toolchain (see 2012-10-20 in 'upgradeadventures')";
71 rename $file, $quarantine_file or die "Could not rename...: $!";
72 next FILE;
76 my $process_file = $process_dir . "/" . basename($file);
77 rename $file, $process_file
78 or die "Cannot move $file to $process_file: $!";
79 my @tr_args;
80 if ($use_mail) {
81 die "not supported";
82 @tr_args = (from => "srezic\@cpan.org",
83 transport => "Net::SMTP",
84 mx => ["localhost"],
86 } else {
87 @tr_args = (transport => 'Metabase',
88 transport_args => [
89 uri => $opt_transport_uri,
90 id_file => '/home/sand/.metabase/id.json',
94 my $r = Test::Reporter->new(@tr_args)->read($process_file);
95 # XXX fix t::r bug?
96 $r->{_subject} =~ s{\n}{}g;
97 unless ($r->send) {
98 warn sprintf "Alert: renaming '$process_file' to '$file' for further considerations";
99 rename $process_file, $file or warn "Could not rename back: $!";
100 die "Alert: error while running $^X $0 against $file: " . $r->errstr . ". Stop.\n";
102 my $done_file = $done_dir . "/" . basename($file);
103 rename $process_file, $done_file
104 or die "Cannot move $process_file to $done_file: $!";
107 __END__
109 =head1 WORKFLOW
111 See CPAN/CPAN::Reporter configuration below:
113 The good (non-fail) reports. On the windows machine
115 ssh 192.168.1.253
116 cd /cygdrive/c/Users/eserte/ctr
117 ls sync/* && echo "sync is not empty" || mv *.rpt sync/
118 rsync -v -a sync/*.rpt eserte@biokovo:var/ctr/new/ && mv sync/*.rpt done/
120 On the unix machine
122 ctr_good_or_invalid.pl
123 send_tr_reports.pl
125 Now review the fail reports on the windows machine. Invalid ones move
126 to the invalid/ subdirectory.
128 =head1 CPAN::REPORTER CONFIGURATION
130 In /cygdrive/c/Users/eserte/Documents/.cpanreporter/config.ini:
132 edit_report=default:no
133 email_from=srezic@cpan.org
134 send_report=default:yes
135 transport=File C:\Users\eserte\ctr
137 Basically the same configuration can be used for cygwin
138 ~/.cpanreporter/config.ini, just use the cygwin path style for the
139 transport directory.
141 edit_report=default:no
142 email_from=srezic@cpan.org
143 send_report=default:yes
144 transport=File /cygdrive/c/Users/eserte/ctr
146 =cut