annotate lib/Benzin/Bugzilla/Bug.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 4eb9fdf4efa9
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::Bug;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
2 use strict;
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
3 use POSIX;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
4 use Scalar::Util qw(looks_like_number);
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
5 use DateTime;
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 my @fields;
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
8
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
9 BEGIN {
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
10 @fields = qw(
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
11 id
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
12 summary
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
13 creation_time
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
14 last_change_time
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
15 creator
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
16 assigned_to
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
17 qa_contact
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
18 cc
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
19
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
20 is_open
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
21 status
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
22 resolution
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
23
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
24 priority
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
25 severity
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
26 url
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
27
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
28 blocks
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
29 depends_on
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
30
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
31 component
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
32 product
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
33 classification
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
34 version
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
35
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
36 actual_time
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
37 estimated_time
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
38 remaining_time
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
39 deadline
9
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 comments
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
42 history
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
43 );
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
44 }
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
45
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
46 use constant { BUG_FIELDS => \@fields };
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
47
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
48 use IMPL::declare {
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents: 9
diff changeset
49 base => [ 'IMPL::Object::Fields' => undef ]
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
50 };
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
51 use fields @fields;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
52
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
53 sub CTOR {
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
54 my SELF $this = shift;
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
55 my $data = shift;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
56 $this->{$_} = $data->{$_}
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
57 foreach grep exists $data->{$_}, @{ SELF->BUG_FIELDS };
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
58 }
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
59
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
60 # returns {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
61 # reports => [
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents: 9
diff changeset
62 # { who => email:string, start => work-start-date-time:DateTime, end => report-date-time:DateTime, work_time => hours:double }
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
63 # ],
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
64 # actual => hours
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
65 # remaining => hours
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
66 # }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
67 sub GetTimeReports {
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
68 my SELF $this = shift;
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
69 my $resolution = shift || 0.25;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
70
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
71 my @bookings;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
72 my $actual = 0;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
73
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
74 for my $history ( @{ $this->{history} || [] } ) {
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents: 9
diff changeset
75 my $who = $history->{who};
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents: 9
diff changeset
76 my $when = $history->{when};
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
77 my $changes = $history->{changes};
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
78
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
79 for my $change ( @{ $changes || [] } ) {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
80 if ( $change->{field_name} eq 'work_time' ) {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
81 my $prev = $change->{removed} || 0;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
82 my $value = $change->{added} || 0;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
83 if ( looks_like_number($prev) and looks_like_number($value) ) {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
84 my $dt = coarsen( $value - $prev, $resolution );
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
85
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
86 if ($dt) {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
87 push @bookings,
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
88 {
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents: 9
diff changeset
89 end => $who,
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
90 when => $when->iso8601(),
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
91 work_time => $dt,
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents: 9
diff changeset
92 start => $when->clone()->subtract( hours => $dt )
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents: 9
diff changeset
93 ->iso8601()
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
94 };
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
95 $actual += $dt;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
96 }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
97 }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
98 }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
99 }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
100 }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
101
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
102 return {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
103 reports => \@bookings,
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
104 actual => $actual,
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
105 remaining => coarsen( $this->{remaining_time}, $resolution )
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
106 };
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
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
109 sub coarsen {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
110 my ( $value, $resolution ) = @_;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
111 return $resolution ? ceil( $value / $resolution ) * $resolution : $value;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
112 }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
113
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents: 9
diff changeset
114 1;