comparison translate.pl @ 10:14a966369278

working version of exporting bugs from bugzilla in tj3 format (without bookings)
author cin
date Mon, 07 Sep 2015 01:37:11 +0300
parents cc7244ab1b9f
children 4eb9fdf4efa9
comparison
equal deleted inserted replaced
9:cc7244ab1b9f 10:14a966369278
1 #!/usr/bin/perl -w 1 #!/usr/bin/perl -w
2 2
3 use IMPL::require { 3 use IMPL::require {
4 BzClient => 'Benzin::Bugzilla::XmlRpcClient', 4 BzClient => 'Benzin::Bugzilla::XmlRpcClient',
5 Bug => 'Benzin::Bugzilla::Bug' 5 BugWriter => 'Benzin::Bugzilla::XmlWriter'
6 }; 6 };
7 use YAML::XS qw(LoadFile Dump); 7 use YAML::XS qw(LoadFile Dump);
8 use XML::Writer; 8 use XML::Writer;
9 use IPC::Run qw(start finish); 9 use IPC::Run qw(start finish);
10
11 our @ClassPath = qw(
12 /usr/share/java/xalan-j2-serializer.jar
13 /usr/share/java/xalan-j2.jar
14 /usr/share/java/xerces-j2.jar
15 /usr/share/java/xml-commons-resolver.jar
16 .
17 );
18 10
19 my $config = LoadFile("config.yaml"); 11 my $config = LoadFile("config.yaml");
20 12
21 if ( !( $config->{bugzilla}{url} =~ /\/$/ ) ) { 13 if ( !( $config->{bugzilla}{url} =~ /\/$/ ) ) {
22 $config->{bugzilla}{url} .= "/"; 14 $config->{bugzilla}{url} .= "/";
25 my $bz = BzClient->new( 17 my $bz = BzClient->new(
26 url => $config->{bugzilla}{url}, 18 url => $config->{bugzilla}{url},
27 apikey => $config->{bugzilla}{apikey} 19 apikey => $config->{bugzilla}{apikey}
28 ); 20 );
29 21
22 my $bugs = $config->{bugzilla}{bugs} or die "No bugs specified";
23 $bugs = [$bugs] unless ref $bugs eq 'ARRAY';
24
30 local (*HIN); 25 local (*HIN);
31 26
32 my $proc = start( [ 'saxon8', '-novw', '-', 'bug-list.xsl' ], 27 my $proc = start(
33 '<pipe', \*HIN, '>', \*STDOUT ) 28 [ 'saxon8', '-novw', '-', 'bug-list.xsl' ],
34 or die "failed to create pipe: $!"; 29 #[ 'cat' ],
30 '<pipe', \*HIN, '>', \*STDOUT
31 ) or die "failed to create pipe: $!";
32
33 binmode *HIN, ":encoding(utf-8)";
34 my $writer =
35 BugWriter->new( OUTPUT => *HIN, DATA_INDENT => 2, DATA_MODE => 'on' );
35 36
36 eval { 37 eval {
37 my %visited; 38 my %visited;
38 my @queue = (283);
39 my @fetched;
40 39
41 while (@queue) { 40 my $fetched = $bz->GetBugsHierarchy( { ids => [283] } );
42 @queue = grep not( $visited{$_}++ ), @queue;
43 41
44 last unless @queue; 42 $bz->PopulateBugsComments($fetched);
43 $bz->PopulateBugsHistory($fetched);
45 44
46 print "#Fetching: ", join( ', ', @queue ), "\n"; 45 $writer->WriteBugList($fetched);
47
48 my $bugs = $bz->GetBugs( { ids => \@queue } );
49 @queue = ();
50
51 foreach my $bug (@$bugs) {
52
53 push @queue, @{ $bug->{depends_on} }
54 if ( $bug->{depends_on} );
55 push @fetched, $bug;
56 }
57 }
58 print Dump( \@fetched );
59
60 $bz->PopulateBugsWithComments( \@fetched );
61 $bz->PopulateBugsHistory( \@fetched );
62
63 print Dump( [ map $_->GetTimeReports(0.25), @fetched ] );
64 46
65 }; 47 };
66 warn Dump($@) and die $@ if $@; 48 warn Dump($@) and die $@ if $@;
67 49
68 close HIN; 50 close HIN;