Mercurial > pub > buggler
annotate lib/Benzin/Bugzilla/XmlRpcClient.pm @ 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 |
rev | line source |
---|---|
7 | 1 package Benzin::Bugzilla::XmlRpcClient; |
2 use strict; | |
3 | |
4 use YAML::XS qw(Dump); | |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
5 use URI; |
7 | 6 |
9 | 7 use IMPL::declare { |
8 require => { | |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
9 Bug => 'Benzin::Bugzilla::Bug', |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
10 BugComment => 'Benzin::Bugzilla::BugComment', |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
11 Deserializer => 'Benzin::Bugzilla::XmlRpcDeserializer', |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
12 XmlRpc => 'XMLRPC::Lite' |
9 | 13 }, |
14 base => { 'IMPL::Object::Fields' => undef } | |
7 | 15 }; |
16 | |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
17 use fields qw(url apikey _client); |
7 | 18 |
19 sub CTOR { | |
20 my SELF $this = shift; | |
21 my %params = @_; | |
22 | |
23 $this->{url} = $params{url} or die "An url is required"; | |
24 $this->{apikey} = $params{apikey} if $params{apikey}; | |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
25 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
26 #create slightly modified client to parse datetime values |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
27 my $url = URI->new_abs( 'xmlrpc.cgi', $this->{url} ); |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
28 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
29 $this->{_client} = |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
30 XmlRpc->new( deserializer => Deserializer->new() )->proxy($url); |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
31 |
7 | 32 } |
33 | |
34 sub GetBugs { | |
35 my SELF $this = shift; | |
36 | |
9 | 37 return [ |
38 map Bug->new($_), | |
39 @{ $this->_CallService( 'Bug.get', shift )->{bugs} || [] } | |
40 ]; | |
7 | 41 } |
42 | |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
43 sub GetBugsHierarchy { |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
44 my SELF $this = shift; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
45 my $args = shift || {}; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
46 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
47 my @queue = @{$args->{ids}}; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
48 my %visited; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
49 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
50 my @fetched; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
51 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
52 while (@queue) { |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
53 @queue = grep not( $visited{$_}++ ), @queue; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
54 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
55 last unless @queue; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
56 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
57 my $bugs = $this->GetBugs( { ids => \@queue } ); |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
58 @queue = (); |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
59 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
60 foreach my Bug $bug (@$bugs) { |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
61 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
62 push @queue, @{ $bug->{depends_on} } |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
63 if ( $bug->{depends_on} ); |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
64 push @fetched, $bug; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
65 } |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
66 } |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
67 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
68 return \@fetched; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
69 } |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
70 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
71 sub PopulateBugsComments { |
7 | 72 my SELF $this = shift; |
73 my $bugs = shift || []; | |
74 | |
75 if ( my @ids = map $_->{id}, @$bugs ) { | |
76 | |
9 | 77 my $resp = $this->_CallService( 'Bug.comments', { ids => \@ids } ); |
78 | |
7 | 79 for my Bug $bug (@$bugs) { |
9 | 80 $bug->{comments} = [ |
81 map BugComment->new($_), | |
82 @{ $resp->{bugs}{ $bug->{id} }->{comments} || [] } | |
83 ]; | |
7 | 84 } |
85 } | |
9 | 86 return; |
87 } | |
88 | |
89 sub PopulateBugsHistory { | |
90 my SELF $this = shift; | |
91 | |
92 my %bugs = map { $_->{id}, $_ } @{ shift || [] }; | |
93 | |
94 if ( keys %bugs ) { | |
95 | |
96 my $resp = | |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
97 $this->_CallService( 'Bug.history', { ids => [ keys %bugs ] } ) |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
98 ->{bugs}; |
9 | 99 |
100 for my $data (@$resp) { | |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
101 my Bug $bug = $bugs{ $data->{id} }; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
102 |
9 | 103 $bug->{history} = $data->{history}; |
104 } | |
105 } | |
106 return; | |
7 | 107 } |
108 | |
109 sub _CallService { | |
110 my SELF $this = shift; | |
111 my ( $method, $params ) = @_; | |
112 | |
113 die "Method must be specified" unless $method; | |
114 $params ||= {}; | |
115 | |
116 $params->{api_key} = $this->{apikey}; | |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
117 |
7 | 118 |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
119 my $result = $this->{_client}->call( $method, $params ); |
7 | 120 |
121 die $result->fault if $result->fault; | |
122 return $result->result; | |
123 } | |
124 | |
125 1; |