Browse files

initial extension, version 1.0

  • Loading branch information...
1 parent faa6f39 commit 2180f4fa213ec150bae9c4a18b3db788e9e80237 @yaniviny yaniviny committed Dec 30, 2012
Showing with 212 additions and 1 deletion.
  1. +54 −0 Config.pm
  2. +145 −0 Extension.pm
  3. +13 −1 README.md
View
54 Config.pm
@@ -0,0 +1,54 @@
+# -*- 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 Bug Tracking System.
+#
+# The Initial Developer of the Original Code is Everything Solved, Inc.
+# Portions created by the Initial Developers are Copyright (C) 2009 the
+# Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+# Michael K <mgsstms@gmail.com>
+
+package Bugzilla::Extension::PractiTest;
+use strict;
+use constant NAME => 'PractiTest';
+use constant REQUIRED_MODULES => [
+ {
+ package => 'Data-Dumper',
+ module => 'Data::Dumper',
+ version => 0,
+ },
+ {
+ package => 'REST-Client',
+ module => 'REST::Client',
+ version => 0,
+ },
+ {
+ package => 'JSON',
+ module => 'JSON',
+ version => 0,
+ },
+ {
+ package => 'Digest-MD5',
+ module => 'Digest::MD5',
+ version => 0,
+ },
+
+];
+
+use constant CONFIG_HOST=>'https://prod.practitest.com'; #or http://demo.practitest.com
+use constant CONFIG_API_KEY=>'key-apikey'; #copy this from your account settings
+use constant CONFIG_API_SECRET_KEY=>'you_api_secret_key'; #copy this from your account settings
+use constant CONFIG_VERSION=>'1.0';
+
+__PACKAGE__->NAME;
View
145 Extension.pm
@@ -0,0 +1,145 @@
+# -*- 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 Bug Tracking System.
+#
+# The Initial Developer of the Original Code is Everything Solved, Inc.
+# Portions created by the Initial Developers are Copyright (C) 2009 the
+# Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+# Michael K <mgsstms@gmail.com>
+
+package Bugzilla::Extension::PractiTest;
+use strict;
+use base qw(Bugzilla::Extension);
+
+use Data::Dumper;
+use REST::Client;
+use JSON;
+use Digest::MD5 qw(md5_hex);
+
+our $VERSION = '1.0';
+
+sub bug_end_of_create
+{
+ my ($self, $args) = @_;
+
+ my $bug = $args->{'bug'};
+
+ my $is_pt_bug = &_is_pt_bug($bug);
+ my $is_updated = $is_pt_bug ? 1 : 0;
+ if ($is_updated eq '1')
+ {
+ &_notify_practitest($bug);
+ }
+}
+
+sub bug_end_of_update
+{
+ my ($self, $args) = @_;
+
+ my $bug = $args->{'bug'};
+ my $changes = $args->{'changes'};
+
+ my $is_pt_bug = &_is_pt_bug($bug);
+ my $is_updated = 0 ;
+ if ($is_pt_bug eq '1')
+ {
+ $is_updated = &_is_pt_bug_changes($bug, $changes);
+ }
+ if ($is_updated eq '1')
+ {
+ &_notify_practitest($bug);
+ }
+}
+
+sub _is_pt_bug
+{
+ my ($bug) = shift;
+
+ my $result = (defined $bug->cf_pt_id) && ($bug->cf_pt_id ne '') ? 1 : 0;
+ return $result;
+}
+
+sub _is_pt_bug_changes
+{
+ my ($bug, $changes) = @_;
+
+ if (defined $changes->{cf_pt_id} && ($changes->{cf_pt_id}->[0] ne $changes->{cf_pt_id}->[1]) && ($changes->{cf_pt_id}->[1] ne '') && ($changes->{cf_pt_id}->[1] ne '0'))
+ {
+ return 1;
+ }
+
+ if (defined $changes->{short_desc} && ($changes->{short_desc}->[0] ne $changes->{short_desc}->[1]))
+ {
+ return 1;
+ }
+ if (defined $changes->{bug_status} && ($changes->{bug_status}->[0] ne $changes->{bug_status}->[1]))
+ {
+ return 1;
+ }
+
+ return 0;
+}
+
+sub _create_authorization_value
+{
+ my $timestamp = time;
+ my $signature=md5_hex(CONFIG_API_KEY.CONFIG_API_SECRET_KEY . $timestamp);
+
+ my $result = '';
+ $result .= "custom api_key=".CONFIG_API_KEY;
+ $result .= ", signature=" . $signature;
+ $result .= ", ts=" . $timestamp;
+
+ return $result;
+}
+
+sub _notify_practitest
+{
+ my ($bug) = shift;
+
+ my $host = CONFIG_HOST;
+ $host .= '/' unless $host =~ m(\/$);
+ my $url = "api/integration_issues/" . $bug->cf_pt_id .".json?v=".CONFIG_VERSION;
+
+ my %json_data = (
+ integration_issue => {
+ external_id => $bug->id,
+ description => $bug->short_desc,
+ status => $bug->bug_status
+ }
+ );
+ #translate the perl hash in json notation
+ my $payload = encode_json(\%json_data);
+
+ my $headers = {Content_Type => 'application/json', Accept => 'application/json', Authorization => _create_authorization_value()};
+
+ my $client = REST::Client->new();
+ $client->setHost($host);
+ $client->PUT(
+ $url,
+ $payload,
+ $headers
+ );
+ my $response =decode_json ($client->responseContent());
+ # warn "_notify_practitest_response=".Dumper($response);
+ if (defined $response->{'error'})
+ {
+ warn "Practitest error response=".$response->{'error'};
+ }
+ return 1;
+}
+
+# This must be the last line of your extension.
+__PACKAGE__->NAME;
View
14 README.md
@@ -1,4 +1,16 @@
Bugzilla-Test-Management
========================
-Bugzilla extension to synchronize its issues with PractiTest (two way integration)
+Bugzilla extension to synchronize its issues with PractiTest (two way integration)
+
+1. Install Bugzilla
+2. Install extra perl modules: REST::Client, JSON, Digest::MD5, Crypt::SSLeay, Data::Dumper (via cpan)
+3. Copy this folder to the 'extensions' directory of bugzilla
+4. Rename this directory to PractiTest
+5. In Config.pm, update the the following constants (line 49-51): CONFIG_HOST, CONFIG_API_KEY, CONFIG_API_SECRET_KEY.
+6. Add custom field - cf_pt_id (Type is 'Free Text')
+7. Restart bugzilla
+
+
+* If you need disable extension, create empty file with name 'disabled'
+

0 comments on commit 2180f4f

Please sign in to comment.