Skip to content

Commit

Permalink
Perform comment carryover when comment has flag:carryover
Browse files Browse the repository at this point in the history
  • Loading branch information
asdil12 committed Nov 3, 2023
1 parent 3e5a2e4 commit efc0b05
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/OpenQA/Schema/Result/Comments.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/OpenQA/Schema/Result/Jobs.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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/;
Expand Down
8 changes: 8 additions & 0 deletions lib/OpenQA/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 //= '';
Expand Down

0 comments on commit efc0b05

Please sign in to comment.