0
|
1 #!/usr/bin/perl -w
|
|
2
|
5
|
3 use JSON;
|
|
4 use YAML::XS qw(LoadFile Dump);
|
|
5 use URI;
|
|
6 use XML::Writer;
|
6
|
7 use IPC::Run qw(start finish);
|
5
|
8
|
1
|
9 our @ClassPath = qw(
|
|
10 /usr/share/java/xalan-j2-serializer.jar
|
|
11 /usr/share/java/xalan-j2.jar
|
|
12 /usr/share/java/xerces-j2.jar
|
|
13 /usr/share/java/xml-commons-resolver.jar
|
|
14 .
|
|
15 );
|
|
16
|
5
|
17 my $config = LoadFile("config.yaml");
|
|
18
|
|
19 if ( !( $config->{bugzilla}{url} =~ /\/$/ ) ) {
|
|
20 $config->{bugzilla}{url} .= "/";
|
|
21 }
|
|
22
|
|
23 my $bz = BzRest->new(
|
|
24 url => $config->{bugzilla}{url},
|
|
25 apikey => $config->{bugzilla}{apikey}
|
|
26 );
|
|
27
|
6
|
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
|
5
|
38
|
6
|
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
|
5
|
56 );
|
|
57
|
|
58 my %fieldsMap = (
|
6
|
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',
|
5
|
67 last_change_time => 'delta_ts'
|
1
|
68 );
|
0
|
69
|
6
|
70 local (*HIN);
|
|
71
|
|
72 my $proc = start( [ 'saxon8', '-novw', '-', 'bug-list.xsl' ],
|
|
73 '<pipe', \*HIN, '>', \*STDOUT )
|
|
74 or die "failed to create pipe: $!";
|
|
75
|
|
76 my $writer = XML::Writer->new( OUTPUT => \*HIN, ENCODING => 'utf-8' );
|
5
|
77
|
|
78 $writer->xmlDecl("UTF-8");
|
|
79 $writer->startTag("bugzilla");
|
|
80
|
6
|
81 my %visited;
|
|
82 my @queue = (283);
|
|
83
|
|
84 while (@queue) {
|
|
85 @queue = grep not( $visited{$_}++ ), @queue;
|
|
86
|
|
87 last unless @queue;
|
|
88
|
|
89 print "#Fetching: ", join( ', ', @queue ), "\n";
|
|
90
|
|
91 my $bugs = $bz->GetBugs( { ids => \@queue } );
|
|
92
|
|
93 @queue = ();
|
|
94
|
|
95 foreach my $bug (@$bugs) {
|
|
96
|
|
97 push @queue, @{ $bug->{depends_on} }
|
|
98 if ( $bug->{depends_on} );
|
|
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 }
|
5
|
114 }
|
6
|
115 $writer->endTag();
|
|
116
|
5
|
117 }
|
|
118 }
|
|
119
|
|
120 $writer->endTag();
|
|
121
|
6
|
122 close HIN;
|
|
123 finish($proc);
|
5
|
124
|
|
125 package BzRest;
|
|
126
|
|
127
|
0
|
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
|
1
|
157 =cut
|