Move construction of success report message to packet objects
authorJacob Bachmeyer <jcb@gnu.org>
Fri, 4 Aug 2023 23:04:16 +0000 (18:04 -0500)
committerJacob Bachmeyer <jcb@gnu.org>
Fri, 4 Aug 2023 23:04:16 +0000 (18:04 -0500)
This also enables additional messages to be included in the report when
processing loose directives.

gatekeeper.pl

index 417ec9dfb4c4a0a96e79713975622ec6f255424d..27548cb5c9eb5ef4000bbb1f2a2d0572d16cbe22 100755 (executable)
@@ -1628,6 +1628,20 @@ sub read_directive_from_string {
   # return list of messages stored for the report
   sub notices { return @{(shift)->{notices}} }
 
+  sub report_message;
+  # internal base class helper method for report_message
+  sub _report_message {
+    my $self = shift;
+    my @messages = @_; # collect final messages
+
+    # add notices stored in the packet object...
+    unshift @messages, $self->notices, '';
+    # ...and remove any leading blank lines...
+    shift @messages while $messages[0] eq '';
+    # ...before returning the report message text
+    return join "\n", @messages;
+  }
+
   # has this packet been installed into the managed tree?
   sub successful { (shift)->{installation_successful} }
 
@@ -1809,6 +1823,13 @@ sub read_directive_from_string {
 
     $self->SUPER::install;
   }
+
+  sub report_message {
+    my $self = shift;
+
+    return $self->_report_message
+      ('processing of '.$self->directive_file_name.' complete');
+  }
 }
 
 {
@@ -1885,6 +1906,13 @@ sub read_directive_from_string {
 
     $self->SUPER::install;
   }
+
+  sub report_message {
+    my $self = shift;
+
+    return $self->_report_message
+      ('upload of '.join(' and ', $self->target_filepair).' complete');
+  }
 }
 
 \f
@@ -3402,20 +3430,8 @@ foreach my $packet (@packets) {
     push @email_addresses, keyidx_email $packet->auth_signature_fingerprints;
 
     # report success
-    if (not $packet->has_uploaded_file) {
-      mail 'processing of '.$packet->directive_file_name.' complete',
-       to => \@email_addresses, subject => $packet->target_package;
-    } else {
-      my @messages =
-       ('upload of '.join(' and ', $packet->target_filepair).' complete');
-      # add notices stored in the packet object...
-      unshift @messages, $packet->notices, '';
-      # ...and remove any leading blank lines...
-      shift @messages while $messages[0] eq '';
-      # ...before sending the report
-      mail join("\n", @messages),
-       to => \@email_addresses, subject => $packet->target_package;
-    }
+    mail $packet->report_message,
+      to => \@email_addresses, subject => $packet->target_package;
 
     # unlink the directive file
     unlink File::Spec->catfile(CONF_DIR_Scratch, $packet->directive_file_name)