comparison translate.pl @ 9:cc7244ab1b9f

implemented time reports on bugs
author cin
date Sat, 05 Sep 2015 22:01:12 +0300
parents 29309bc8d932
children 14a966369278
comparison
equal deleted inserted replaced
8:ff9c0c788382 9:cc7244ab1b9f
1 #!/usr/bin/perl -w 1 #!/usr/bin/perl -w
2 2
3 use JSON; 3 use IMPL::require {
4 BzClient => 'Benzin::Bugzilla::XmlRpcClient',
5 Bug => 'Benzin::Bugzilla::Bug'
6 };
4 use YAML::XS qw(LoadFile Dump); 7 use YAML::XS qw(LoadFile Dump);
5 use URI;
6 use XML::Writer; 8 use XML::Writer;
7 use IPC::Run qw(start finish); 9 use IPC::Run qw(start finish);
8 10
9 our @ClassPath = qw( 11 our @ClassPath = qw(
10 /usr/share/java/xalan-j2-serializer.jar 12 /usr/share/java/xalan-j2-serializer.jar
18 20
19 if ( !( $config->{bugzilla}{url} =~ /\/$/ ) ) { 21 if ( !( $config->{bugzilla}{url} =~ /\/$/ ) ) {
20 $config->{bugzilla}{url} .= "/"; 22 $config->{bugzilla}{url} .= "/";
21 } 23 }
22 24
23 my $bz = BzRest->new( 25 my $bz = BzClient->new(
24 url => $config->{bugzilla}{url}, 26 url => $config->{bugzilla}{url},
25 apikey => $config->{bugzilla}{apikey} 27 apikey => $config->{bugzilla}{apikey}
26 );
27
28 my @fields = qw(
29 id
30 summary
31 creation_time
32 last_change_time
33 creator
34 assigned_to
35
36 status
37 resolution
38
39 priority
40 severity
41 url
42
43 blocks
44 depends_on
45 cc
46
47 component
48 product
49 classification
50 version
51
52 actual_time
53 estimated_time
54 remainig_time
55 deadline
56 );
57
58 my %fieldsMap = (
59 summary => 'short_desc',
60 id => 'bug_id',
61 creator => 'reporter',
62 status => 'bug_status',
63 severity => 'bug_severity',
64 blocks => 'blocked',
65 depends_on => 'dependson',
66 creation_time => 'creation_ts',
67 last_change_time => 'delta_ts'
68 ); 28 );
69 29
70 local (*HIN); 30 local (*HIN);
71 31
72 my $proc = start( [ 'saxon8', '-novw', '-', 'bug-list.xsl' ], 32 my $proc = start( [ 'saxon8', '-novw', '-', 'bug-list.xsl' ],
73 '<pipe', \*HIN, '>', \*STDOUT ) 33 '<pipe', \*HIN, '>', \*STDOUT )
74 or die "failed to create pipe: $!"; 34 or die "failed to create pipe: $!";
75 35
76 my $writer = XML::Writer->new( OUTPUT => \*HIN, ENCODING => 'utf-8' ); 36 eval {
37 my %visited;
38 my @queue = (283);
39 my @fetched;
77 40
78 $writer->xmlDecl("UTF-8"); 41 while (@queue) {
79 $writer->startTag("bugzilla"); 42 @queue = grep not( $visited{$_}++ ), @queue;
80 43
81 my %visited; 44 last unless @queue;
82 my @queue = (283);
83 45
84 while (@queue) { 46 print "#Fetching: ", join( ', ', @queue ), "\n";
85 @queue = grep not( $visited{$_}++ ), @queue;
86 47
87 last unless @queue; 48 my $bugs = $bz->GetBugs( { ids => \@queue } );
49 @queue = ();
88 50
89 print "#Fetching: ", join( ', ', @queue ), "\n"; 51 foreach my $bug (@$bugs) {
90 52
91 my $bugs = $bz->GetBugs( { ids => \@queue } ); 53 push @queue, @{ $bug->{depends_on} }
54 if ( $bug->{depends_on} );
55 push @fetched, $bug;
56 }
57 }
58 print Dump( \@fetched );
92 59
93 @queue = (); 60 $bz->PopulateBugsWithComments( \@fetched );
61 $bz->PopulateBugsHistory( \@fetched );
94 62
95 foreach my $bug (@$bugs) { 63 print Dump( [ map $_->GetTimeReports(0.25), @fetched ] );
96 64
97 push @queue, @{ $bug->{depends_on} } 65 };
98 if ( $bug->{depends_on} ); 66 warn Dump($@) and die $@ if $@;
99
100 $writer->startTag("bug");
101 foreach my $field (@fields) {
102 next unless $bug->{$field};
103
104 my $tagName = $fieldsMap{$field} || $field;
105 my @values =
106 ref( $bug->{$field} )
107 && ref( $bug->{$field} ) eq 'ARRAY'
108 ? @{ $bug->{$field} }
109 : $bug->{$field};
110
111 foreach my $v (@values) {
112 $writer->dataElement( $tagName, $v );
113 }
114 }
115 $writer->endTag();
116
117 }
118 }
119
120 $writer->endTag();
121 67
122 close HIN; 68 close HIN;
123 finish($proc); 69 finish($proc);
124 70
125 package BzRest; 71 1;
126
127
128
129 __END__
130
131 =pod
132
133 =head1 NAME
134
135 C<translate.pl> - translates bugzilla xml buglist to TaskJuggler format
136
137 =head1 METHODS
138
139 =head2 xalan(%args)
140
141 =over
142
143 =item * -IN
144
145 Input file
146
147 =item * -OUT
148
149 Output file
150
151 =item * -XSL
152
153 XSLT file
154
155 =back
156
157 =cut