Folks:
Please find attached a patch we use to support Bugzilla's time tracking
feature. We use this feature heavily to track development efforts,
estimate schedules & plan accordingly.
We are finding scmbug integration useful but found it awkward to have to
go back to Bugzilla to add our hours worked for a given commit.
This patch supports a commit message such as:
bug 123: Fixed the problem with character handling in foo()
status 123: resolved fixed
worktime 1.2
Where worktime 1.2 represents 1.2 hours.
We did not bother to implement worktime on a per-bug basis. It is
assumed that it will be applied to the comment for the specified bug or
bugs. It doesn't make much sense to add time spent without a comment
and we don't want to encourage people to add time worked on unrelated
commits.
I hope someone finds this patch useful. I'm sure it has some flaws and
could be improved but it meets our needs for the moment.
Cheers,
Matt
--
Matt Adams
Development & Network Services
Cypress Interactive
http://cypressinteractive.com, http://edsuite.com
Index: usr/share/scmbug/lib/Scmbug/Daemon/Bugzilla.pm
===================================================================
--- usr/share/scmbug/lib/Scmbug/Daemon/Bugzilla.pm (revision 191)
+++ usr/share/scmbug/lib/Scmbug/Daemon/Bugzilla.pm (revision 192)
@@ -512,9 +512,77 @@
# AppendComment was fixed in Bugzilla 2.22. Should use the
# native version
my $userid = Bugzilla::User::login_to_id( $username );
+ my $work_time = 0;
+ # Look for the WORKTIME keyword
+ if ($comment =~ /\bWORKTIME\b/i) {
+ if ($comment =~ /\b(WORKTIME)\s+?([0-9]+(?:\.[0-9]+)?)\b/i) {
+
+ $work_time = $2;
+
+ # Remove keyword & value from commit line
+ $comment =~ s/$1\s+?$2//;
+
+ # Remove trailing `.' if supplied
+ $work_time =~ s/\.$//;
+
+ # Trap for invalid entries
+ if ($work_time <= 0) {
+ return ( 1, "WORKTIME keyword value must be greater then zero. Please review 'Tracking Time' in the wiki Development web.\n");
+ }
+
+ # Retrieve existing values for bug
+ my $bug2 = new Bugzilla::Bug($bugid);
+
+ my $dbh = Bugzilla->dbh;
+ # Lock database tables, avoid mid-air collisions
+ $dbh->bz_lock_tables('bugs WRITE', 'bugs_activity WRITE', 'duplicates WRITE', 'longdescs WRITE', 'fielddefs READ', 'profiles READ');
+
+ my $timestamp = $dbh->selectrow_array("SELECT NOW()"); # use same timestamp for all modifications
+
+ my $sql = "UPDATE bugs SET remaining_time = ? WHERE bug_id = ?";
+
+ my $remaining_time = $bug2->remaining_time - $work_time;
+
+ # Prevent negative values
+ if ($remaining_time < 0) {
+ $remaining_time = 0;
+ }
+
+ my @params = ();
+ push(@params, $remaining_time);
+ push(@params, $bugid);
+
+ my $result = $dbh->do($sql, undef, @params);
+
+ if ($result) {
+ # Finally add values to bug's activity log
+
+ ##
+ # Keep track of change, record work time
+ #
+ Bugzilla::Bug::LogActivityEntry($bugid, 'work_time', '', $work_time, $userid, $timestamp);
+
+ ##
+ # Record difference in remaining time, record old vs. new remaining time (but only if original remaining time >0)
+ #
+ if ($bug2->remaining_time > 0) {
+ Bugzilla::Bug::LogActivityEntry($bugid, 'remaining_time', $bug2->remaining_time, $remaining_time, $userid, $timestamp);
+ }
+ } else {
+ $dbh->bz_unlock_tables();
+ return ( 1, "Error while updating the status resolution of bug 'bugid'.\n");
+ }
+
+ $dbh->bz_unlock_tables();
+ } else {
+ # WORKTIME usage did not meet expected syntax; error out
+ return ( 1, "WORKTIME keyword found but usage did not meet expected syntax. Please review 'Tracking Time' in the wiki Development web.\n");
+ }
+ }
+
if ( $userid > 0 ) {
- Bugzilla::Bug::AppendComment( $bugid, $userid, $comment );
+ Bugzilla::Bug::AppendComment( $bugid, $userid, $comment, undef, undef, $work_time );
return 0;
} else {
# This should never happen. Each user should have a
Index: usr/share/scmbug/lib/Scmbug/Glue/SCM.pm
===================================================================
--- usr/share/scmbug/lib/Scmbug/Glue/SCM.pm (revision 191)
+++ usr/share/scmbug/lib/Scmbug/Glue/SCM.pm (revision 192)
@@ -302,6 +302,21 @@
if ( $self->activity()->name() eq $ACTIVITY_COMMIT ||
$self->activity()->name() eq $ACTIVITY_VERIFY ) {
+
+ # Ensure that any use of WORKTIME keyword is valid (see Scmbug/Daemon/Bugzilla.pm for the other side of this hack)
+ if ($self->activity()->original_log_message() =~ /\bWORKTIME\b/i) {
+ if ($self->activity()->original_log_message() =~ /\b(WORKTIME)\s+?([0-9]+(?:\.[0-9]+)?)\b/i) {
+ my $work_time = $2;
+ $work_time =~ s/\.$//;
+
+ if ($work_time <= 0) {
+ log_fatal_error( $GLUE_ERROR_INVALID_ACTIVITY, "WORKTIME value must be greater then 0. Refer to 'Tracking Time' in SubversionIntegration the wiki Development web topic.\n" );
+ }
+ } else {
+ log_fatal_error( $GLUE_ERROR_INVALID_ACTIVITY, "WORKTIME keyword found but does not meet expected syntax. Refer to 'Tracking Time' in SubversionIntegration the wiki Development web topic.\n" );
+ }
+ }
+
my $log_message_without_resolution = "";
$logger->info( "Searching for resolution bug ids\n");
#
_______________________________________________
scmbug-users mailing list
[email protected]
http://lists.mkgnu.net/cgi-bin/mailman/listinfo/scmbug-users