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