annotate lib/Benzin/Bugzilla/Bug.pm @ 9:cc7244ab1b9f

implemented time reports on bugs
author cin
date Sat, 05 Sep 2015 22:01:12 +0300
parents 29309bc8d932
children 14a966369278
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 {
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
49 require => {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
50 Strptime => 'DateTime::Format::Strptime'
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
51 },
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
52 base => [
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
53 'IMPL::Object::Fields' => undef
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
54 ]
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
55 };
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
56
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
57 use fields @fields;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
58
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
59 my $dtparser = Strptime->new(
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
60 pattern => '%Y%m%dT%H:%M:%S',
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
61 time_zone => 'UTC',
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
62 on_error => 'croak'
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
63 );
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
64
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
65 sub CTOR {
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
66 my SELF $this = shift;
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
67 my $data = shift;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
68 $this->{$_} = $data->{$_}
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
69 foreach grep exists $data->{$_}, @{ SELF->BUG_FIELDS };
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
70 }
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
71
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
72 # returns {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
73 # reports => [
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
74 # { who => email:string, when => report-date-time:DateTime, work_time => hours:double }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
75 # ],
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
76 # actual => hours
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
77 # remaining => hours
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
78 # }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
79 sub GetTimeReports {
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
80 my SELF $this = shift;
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
81 my $resolution = shift || 0.25;
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
82
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
83 warn "Processing: $this->{id}";
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
84
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
85 my @bookings;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
86 my $actual = 0;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
87
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
88 for my $history ( @{ $this->{history} || [] } ) {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
89 my $who = $history->{who};
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
90 warn $history->{when};
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
91 my $when = $dtparser->parse_datetime( $history->{when} );
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
92 my $changes = $history->{changes};
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
93
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
94 for my $change ( @{ $changes || [] } ) {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
95 if ( $change->{field_name} eq 'work_time' ) {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
96 my $prev = $change->{removed} || 0;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
97 my $value = $change->{added} || 0;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
98 if ( looks_like_number($prev) and looks_like_number($value) ) {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
99 my $dt = coarsen( $value - $prev, $resolution );
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
100
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
101 if ($dt) {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
102 push @bookings,
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
103 {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
104 who => $who,
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
105 when => $when->iso8601(),
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
106 work_time => $dt,
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
107 start => $when->clone()->subtract( hours => $dt )->iso8601()
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
108 };
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
109 $actual += $dt;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
110 }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
111 }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
112 }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
113 }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
114 }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
115
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
116 return {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
117 reports => \@bookings,
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
118 actual => $actual,
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
119 remaining => coarsen( $this->{remaining_time}, $resolution )
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
120 };
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
121 }
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
122
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
123 sub coarsen {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
124 my ( $value, $resolution ) = @_;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
125 return $resolution ? ceil( $value / $resolution ) * $resolution : $value;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
126 }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
127
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
128 1;