annotate lib/Benzin/Bugzilla/XmlRpcClient.pm @ 12:52b34ea50eff default tip

sync: work time projection doesn't seem to be working anyway
author cin
date Sun, 13 Sep 2015 19:37:16 +0300
parents 14a966369278
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
1 package Benzin::Bugzilla::XmlRpcClient;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
2 use strict;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
3
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
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
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
6
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
7 use IMPL::declare {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
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
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
13 },
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
14 base => { 'IMPL::Object::Fields' => undef }
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
15 };
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
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
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
18
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
19 sub CTOR {
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
20 my SELF $this = shift;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
21 my %params = @_;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
22
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
23 $this->{url} = $params{url} or die "An url is required";
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
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
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
32 }
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
33
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
34 sub GetBugs {
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
35 my SELF $this = shift;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
36
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
37 return [
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
38 map Bug->new($_),
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
39 @{ $this->_CallService( 'Bug.get', shift )->{bugs} || [] }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
40 ];
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
41 }
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
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
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
72 my SELF $this = shift;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
73 my $bugs = shift || [];
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
74
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
75 if ( my @ids = map $_->{id}, @$bugs ) {
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
76
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
77 my $resp = $this->_CallService( 'Bug.comments', { ids => \@ids } );
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
78
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
79 for my Bug $bug (@$bugs) {
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
80 $bug->{comments} = [
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
81 map BugComment->new($_),
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
82 @{ $resp->{bugs}{ $bug->{id} }->{comments} || [] }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
83 ];
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
84 }
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
85 }
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
86 return;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
87 }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
88
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
89 sub PopulateBugsHistory {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
90 my SELF $this = shift;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
91
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
92 my %bugs = map { $_->{id}, $_ } @{ shift || [] };
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
93
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
94 if ( keys %bugs ) {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
95
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
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
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
99
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
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
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
103 $bug->{history} = $data->{history};
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
104 }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
105 }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
106 return;
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
107 }
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
108
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
109 sub _CallService {
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
110 my SELF $this = shift;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
111 my ( $method, $params ) = @_;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
112
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
113 die "Method must be specified" unless $method;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
114 $params ||= {};
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
115
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
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
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
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
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
120
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
121 die $result->fault if $result->fault;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
122 return $result->result;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
123 }
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
124
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
125 1;