[bugzilla-gnome-org-extensions] Parse traces when they are submitted and when a bug is updated.



commit 69b1d6de0a4acec25020ac8f21e6b1a0f3b3a89f
Author: Max Kanat-Alexander <mkanat everythingsolved com>
Date:   Thu Aug 6 06:28:05 2009 -0500

    Parse traces when they are submitted and when a bug is updated.

 code/bug-end_of_create.pl |   27 +++++++++++++++++++++++++++
 code/bug-end_of_update.pl |   27 +++++++++++++++++++++++++++
 lib/TraceParser/Hooks.pm  |   24 ++++++++++++++++++++++++
 3 files changed, 78 insertions(+), 0 deletions(-)
---
diff --git a/code/bug-end_of_create.pl b/code/bug-end_of_create.pl
new file mode 100644
index 0000000..c134ded
--- /dev/null
+++ b/code/bug-end_of_create.pl
@@ -0,0 +1,27 @@
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+#
+# The Original Code is the Bugzilla Traceparser Plugin.
+#
+# The Initial Developer of the Original Code is Canonical Ltd.
+# Portions created by Canonical Ltd. are Copyright (C) 2009
+# Canonical Ltd. All Rights Reserved.
+#
+# Contributor(s):
+#   Max Kanat-Alexander <mkanat bugzilla org>
+
+
+use strict;
+use warnings;
+use Bugzilla;
+use TraceParser::Hooks;
+bug_create(%{ Bugzilla->hook_args });
diff --git a/code/bug-end_of_update.pl b/code/bug-end_of_update.pl
new file mode 100644
index 0000000..7a59ff9
--- /dev/null
+++ b/code/bug-end_of_update.pl
@@ -0,0 +1,27 @@
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+#
+# The Original Code is the Bugzilla Traceparser Plugin.
+#
+# The Initial Developer of the Original Code is Canonical Ltd.
+# Portions created by Canonical Ltd. are Copyright (C) 2009
+# Canonical Ltd. All Rights Reserved.
+#
+# Contributor(s):
+#   Max Kanat-Alexander <mkanat bugzilla org>
+
+
+use strict;
+use warnings;
+use Bugzilla;
+use TraceParser::Hooks;
+bug_update(%{ Bugzilla->hook_args });
diff --git a/lib/TraceParser/Hooks.pm b/lib/TraceParser/Hooks.pm
index 9c2332d..65a93c3 100644
--- a/lib/TraceParser/Hooks.pm
+++ b/lib/TraceParser/Hooks.pm
@@ -28,6 +28,8 @@ use Bugzilla::Util qw(detaint_natural);
 use TraceParser::Trace;
 
 our @EXPORT = qw(
+    bug_create
+    bug_update
     install_update_db
     format_comment
     page
@@ -35,6 +37,28 @@ our @EXPORT = qw(
 
 use constant DEFAULT_POPULAR_LIMIT => 20;
 
+sub bug_create {
+    my %params = @_;
+    my $bug = $params{bug};
+    my $comment = $bug->longdescs->[0];
+    my $data = TraceParser::Trace->parse_from_text($comment->{body});
+    return if !$data;
+    TraceParser::Trace->create({ %$data, comment_id => $comment->{id} });
+}
+
+sub bug_update {
+    my %params = @_;
+    my ($bug, $timestamp) = @params{qw(bug timestamp)};
+    return if !$bug->{added_comments};
+    my $comments = Bugzilla::Bug::GetComments($bug->id, 'oldest_to_newest', 
+                                              $bug->delta_ts, $timestamp, 1);
+    foreach my $comment (@$comments) {
+        my $data = TraceParser::Trace->parse_from_text($comment->{body});
+        next if !$data;
+        TraceParser::Trace->create({ %$data, comment_id => $comment->{id} });
+    }
+}
+
 sub install_update_db {
     my $dbh = Bugzilla->dbh;
     my $has_traces = $dbh->selectrow_array('SELECT 1 FROM trace '


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]