From efc0b0554b19a0e1e9432c8ce1f16812bbe5a269 Mon Sep 17 00:00:00 2001 From: Dominik Heidler Date: Fri, 3 Nov 2023 15:13:24 +0100 Subject: [PATCH] Perform comment carryover when comment has flag:carryover Ticket: https://progress.opensuse.org/issues/136244 --- lib/OpenQA/Schema/Result/Comments.pm | 13 ++++++++++++- lib/OpenQA/Schema/Result/Jobs.pm | 2 +- lib/OpenQA/Utils.pm | 8 ++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/OpenQA/Schema/Result/Comments.pm b/lib/OpenQA/Schema/Result/Comments.pm index 2b96a5e07baa..40c6a658544b 100644 --- a/lib/OpenQA/Schema/Result/Comments.pm +++ b/lib/OpenQA/Schema/Result/Comments.pm @@ -5,7 +5,7 @@ package OpenQA::Schema::Result::Comments; use Mojo::Base 'DBIx::Class::Core', -signatures; use OpenQA::Jobs::Constants; -use OpenQA::Utils qw(find_labels find_bugref find_bugrefs); +use OpenQA::Utils qw(find_labels find_flags find_bugref find_bugrefs); use OpenQA::Markdown qw(markdown_to_html); use List::Util qw(first); @@ -107,6 +107,17 @@ sub label ($self) { return find_labels($self->text)->[0]; } +=head2 flags + +Returns flag values if C<$self> is has flags, e.g. 'flag:carryover flag:foobar' returns a hashref with the keys 'carryover' and 'foobar' +=cut +sub label ($self) { + my $flags = find_flags($self->text); + my %flag_hash; + @flag_hash{@$flags} = (); + return \%flag_hash; +} + =head2 force_result Returns new result value if C<$self> is a special "force_result" label, e.g. diff --git a/lib/OpenQA/Schema/Result/Jobs.pm b/lib/OpenQA/Schema/Result/Jobs.pm index 0a5ce49a2c83..609709ad7854 100644 --- a/lib/OpenQA/Schema/Result/Jobs.pm +++ b/lib/OpenQA/Schema/Result/Jobs.pm @@ -1713,7 +1713,7 @@ sub carry_over_bugrefs ($self) { my $comments = $prev->comments->search({}, {order_by => {-desc => 'me.id'}}); for my $comment ($comments->all) { - next unless $comment->bugref; + next unless ($comment->bugref or exists($comment->flags->{carryover})); my $text = $comment->text; my $prev_id = $prev->id; $text .= "\n\n(Automatic takeover from t#$prev_id)" if $text !~ qr/Automatic takeover/; diff --git a/lib/OpenQA/Utils.pm b/lib/OpenQA/Utils.pm index 0881bd20be1a..40f764890ceb 100644 --- a/lib/OpenQA/Utils.pm +++ b/lib/OpenQA/Utils.pm @@ -103,6 +103,7 @@ our @EXPORT = qw( run_cmd_with_log_return_error parse_assets_from_settings find_labels + find_flags find_bugref find_bugrefs bugurl @@ -431,6 +432,13 @@ sub find_labels { return \@labels; } +sub find_flags { + my $text = shift // ''; + my @flags; + push @flags, $+{match} while $text =~ /${\FLAG_REGEX}/g; + return \@flags; +} + sub find_bugref { my ($text) = @_; $text //= '';