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 13, 2023
1 parent 3e5a2e4 commit 2af1b5c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 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 text_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 text_flags ($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 if !$comment->bugref && !exists($comment->text_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
5 changes: 4 additions & 1 deletion t/17-labels_carry_over.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use Test::Output 'combined_from';
use OpenQA::Test::Case;
use OpenQA::Test::TimeLimit '10';
use OpenQA::Test::Utils qw(assume_all_assets_exist);
use Mojo::DOM;
use Mojo::JSON qw(decode_json);

my $test_case = OpenQA::Test::Case->new;
Expand All @@ -26,7 +27,9 @@ $test_case->login($t, 'percival');
assume_all_assets_exist;

my $comment_must
= '<a href="https://bugzilla.suse.com/show_bug.cgi?id=1234">bsc#1234</a>(Automatic takeover from <a href="/tests/99962">t#99962</a>)';
= Mojo::DOM->new(
'<span class="openqa-bugref" title="Bug referenced: bsc#1234"><a href="https://bugzilla.suse.com/show_bug.cgi?id=1234"><i class="test-label label_bug fa fa-bug"></i>&nbsp;bsc#1234</a></span>(Automatic takeover from <a href="/tests/99962">t#99962</a>)'
)->to_string;
my $carry_over_note = "\n(The hook script will not be executed.)";
sub comments ($url) {
$t->get_ok("$url/comments_ajax")->status_is(200)->tx->res->dom->find('.media-comment > p')->map('content');
Expand Down
2 changes: 1 addition & 1 deletion t/ui/14-dashboard.t
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ log_debug('build_url: ' . $build_url);
is(scalar @{$driver->find_elements('.h4', 'css')}, 5, 'number of builds for opensuse');
is(
$driver->find_element_by_id('group_description')->get_text(),
"Test description\nwith bugref bsc#1234",
"Test description\nwith bugref bsc#1234", # second space comes nbsp used in bugref span
'description shown'
);
is(
Expand Down

0 comments on commit 2af1b5c

Please sign in to comment.