]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
switch to uuids for report pings
authorDylan William Hardison <dylan@hardison.net>
Wed, 29 May 2019 15:01:06 +0000 (11:01 -0400)
committerGitHub <noreply@github.com>
Wed, 29 May 2019 15:01:06 +0000 (11:01 -0400)
Bugzilla/App/Command/report_ping.pm
Bugzilla/Report/Ping.pm
Bugzilla/Report/Ping/Simple.pm
t/report-ping-simple.t

index c423bf384859ca98c5022800e1a1cd71644affbc..d61df7b32e9eaaa7872a73a15adf5c440bca4f33 100644 (file)
@@ -79,9 +79,9 @@ sub run {
       'Testing',
       sub {
         foreach my $result (@_) {
-          my @error = $report->test($result);
+          my @error = $report->test_row($result);
           if (@error) {
-            my (undef, $doc) = $report->prepare($result);
+            my $doc = $report->extract_content($result);
             die $json->encode({errors => \@error, result => $doc});
           }
         }
@@ -94,7 +94,8 @@ sub run {
       'Dumping',
       sub {
         foreach my $result (@_) {
-          my ($id, $doc) = $report->prepare($result);
+          my $doc = $report->extract_content($result);
+          my $id = $result->id;
           path($working_dir, "$id.json")->spurt($json->encode($doc));
         }
       }
@@ -105,7 +106,7 @@ sub run {
       $report,
       'Sending',
       sub {
-        Mojo::Promise->all(map { $report->send($_) } @_)->wait;
+        Mojo::Promise->all(map { $report->send_row($_) } @_)->wait;
       }
     );
   }
index 8ea553e083f404c91ecef084c6c85fd86de4b0a7..e3460ffa4d978afac7d15f8004e413158b7458a7 100644 (file)
@@ -9,12 +9,13 @@ package Bugzilla::Report::Ping;
 use 5.10.1;
 use Moo::Role;
 
-use Type::Utils qw(class_type);
 use Bugzilla::Types qw(URL);
-use Types::Standard qw(Str Num Int);
-use Scalar::Util qw(blessed);
 use JSON::Validator;
 use Mojo::Promise;
+use Scalar::Util qw(blessed);
+use Type::Utils qw(class_type);
+use Types::Standard qw(Str Num Int);
+use UUID::Tiny qw(:std);
 
 has 'model' =>
   (is => 'ro', required => 1, isa => class_type({class => 'Bugzilla::Model'}));
@@ -89,19 +90,37 @@ sub _build_docversion {
   return $self->VERSION;
 }
 
-requires 'prepare';
+has 'uuid_namespace' => (is => 'lazy', init_arg => undef, isa => Str);
+
+sub _build_uuid_namespace {
+  my ($self) = @_;
+
+  my $name = $self->namespace . '/' . $self->doctype . ':' . $self->docversion;
+  return create_uuid(UUID_SHA1, UUID_NIL, $name);
+}
+
+requires 'extract_id', 'extract_content';
+
+around 'extract_id' => sub {
+  my ($method, $self, $row) = @_;
+
+  return create_uuid_as_string(UUID_SHA1, $self->uuid_namespace, $self->$method($row));
+};
 
-sub send {
+sub send_row {
   my ($self, $row) = @_;
-  my ($id, $doc) = $self->prepare($row);
-  my $url = $self->base_url;
+  my $url     = $self->base_url;
+  my $id      = $self->extract_id($row);
+  my $content = $self->extract_content($row);
   push @{$url->path}, $self->namespace, $self->doctype, $self->docversion, $id;
-  return $self->user_agent->put_p($url, json => $doc);
+  return $self->user_agent->put_p($url, json => $content);
 }
 
-sub test {
+sub test_row {
   my ($self, $row) = @_;
-  my ($id, $doc) = $self->prepare($row);
+  my $id  = $self->extract_id($row);
+  my $doc = $self->extract_content($row);
+  die 'id is not a uuid string' unless is_uuid_string($id);
 
   return $self->validate($doc);
 }
index d63553c7cdcc5371902dd9fea0bc8104a8935d94..6e47a0afa31523768b8c4eb36455436dcd2cea3f 100644 (file)
@@ -63,9 +63,9 @@ sub _build_resultset {
   return $bugs->search($query, $options);
 }
 
-sub prepare {
+sub extract_content {
   my ($self, $bug) = @_;
-  my $doc = {
+  return {
     reporter         => $bug->reporter->id,
     assigned_to      => $bug->assigned_to->id,
     qa_contact       => $bug->qa_contact ? $bug->qa_contact->id : undef,
@@ -84,21 +84,19 @@ sub prepare {
     duplicates       => [map { $_->id } $bug->duplicates->all],
     blocked_by       => [map { $_->dependson } $bug->map_blocked_by->all],
     depends_on       => [map { $_->blocked } $bug->map_depends_on->all],
-    flags            => [map { $self->_prepare_flag($_) } $bug->flags->all],
-    delta_ts         => $bug->delta_ts . "",
-    creation_ts      => $bug->creation_ts . "",
+    flags            => [map { $self->_extract_flag($_) } $bug->flags->all],
+    delta_ts         => $bug->delta_ts . '',
+    creation_ts      => $bug->creation_ts . '',
   };
-
-  return ($self->_prepare_doc_id($bug), $doc);
 }
 
-sub _prepare_doc_id {
+sub extract_id {
   my ($self, $bug) = @_;
 
-  return sprintf("%d-%d", $bug->id, $bug->delta_ts->epoch);
+  return sprintf('%d-%d', $bug->id, $bug->delta_ts->epoch);
 }
 
-sub _prepare_flag {
+sub _extract_flag {
   my ($self, $flag) = @_;
 
   return {
index f2cf56decf5fd9d7300af27f65a652bba2e3dde9..ee207cd53cf2cdba4b33033c8ce17f8887f4f0f6 100644 (file)
@@ -70,17 +70,15 @@ is($rs->first->id, 1, "first bug of page 1 is 1");
 
 my ($first, $second, $third, @rest) = $rs->all;
 {
-  my ($id, $doc) = $report->prepare( $first );
+  my $doc = $report->extract_content( $first );
 
-  is($id, "1-$time{1}", "doc id is correct");
   is($doc->{product}, 'Firefox');
   is($doc->{keywords}, []);
   is([map { "$_" } $report->validate($doc)], [], "No errors for first doc");
 }
 
 {
-  my ($id, $doc) = $report->prepare( $third );
-  is($id, "3-$time{3}", "doc id is correct");
+  my $doc = $report->extract_content( $third );
   is($doc->{product}, 'Firefox');
   is($doc->{keywords}, ['regression']);
 }