From ddb7e271987fdd0ada780abadb46a035ee90b5c8 Mon Sep 17 00:00:00 2001 From: Jacob Bachmeyer Date: Fri, 4 Aug 2023 18:04:16 -0500 Subject: [PATCH] Move construction of success report message to packet objects This also enables additional messages to be included in the report when processing loose directives. --- gatekeeper.pl | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/gatekeeper.pl b/gatekeeper.pl index 417ec9d..27548cb 100755 --- a/gatekeeper.pl +++ b/gatekeeper.pl @@ -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'); + } } @@ -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) -- 2.25.1