@@ -12,6 +12,7 @@ use Mojo::Util 'decode';
12
12
use OpenQA::Utils qw( ensure_timestamp_appended find_bug_number locate_needle needledir testcasedir) ;
13
13
use OpenQA::Jobs::Constants;
14
14
use File::Basename;
15
+ use File::Path ' make_path' ;
15
16
use File::Which ' which' ;
16
17
use POSIX ' strftime' ;
17
18
use Mojo::JSON ' decode_json' ;
@@ -91,6 +92,29 @@ sub view ($self) {
91
92
$self -> viewimg;
92
93
}
93
94
95
+ sub _create_tmpdir_for_needles_refspec ($self , $job ) {
96
+ return undef unless $self -> app-> config-> {' scm git' }-> {checkout_needles_sha } eq ' yes' ;
97
+ my $needle_dir = $job -> needle_dir;
98
+ $needle_dir = realpath($needle_dir ) // $needle_dir ;
99
+ return undef unless my $casedir = $job -> settings-> single({key => ' CASEDIR' });
100
+ my $casedir_url = Mojo::URL-> new($casedir -> value);
101
+ return undef unless $casedir_url -> scheme;
102
+ my $casedir_refspec = $casedir_url -> fragment;
103
+ eval {
104
+ my $vars_json = Mojo::File-> new($job -> result_dir(), ' vars.json' )-> slurp;
105
+ my $vars = decode_json($vars_json );
106
+ $casedir_refspec = $vars -> {TEST_GIT_HASH };
107
+ };
108
+ chomp ($casedir_refspec );
109
+ my $needle_dir_basename = basename(dirname($needle_dir ));
110
+ my $new_path = " /tmp/$needle_dir_basename /worktrees/$casedir_refspec /needles" ;
111
+ if (!-d $new_path ) {
112
+ make_path(" /tmp/$needle_dir_basename /worktrees/$casedir_refspec /needles" );
113
+ qx{ git -C "$needle_dir " fetch --depth 1 origin "$casedir_refspec " &>/dev/null} ;
114
+ }
115
+ return $casedir_refspec ;
116
+ }
117
+
94
118
# Needle editor
95
119
sub edit ($self ) {
96
120
return $self -> reply-> not_found unless $self -> _init && $self -> check_tabmode();
@@ -101,6 +125,7 @@ sub edit ($self) {
101
125
my $distri = $job -> DISTRI;
102
126
my $dversion = $job -> VERSION || ' ' ;
103
127
my $needle_dir = $job -> needle_dir;
128
+ my $needle_ref = $self -> _create_tmpdir_for_needles_refspec($job );
104
129
my $app = $self -> app;
105
130
my $needles_rs = $app -> schema-> resultset(' Needles' );
106
131
@@ -130,7 +155,7 @@ sub edit ($self) {
130
155
# Second position: the only needle (with the same matches)
131
156
my $needle_info
132
157
= $self -> _extended_needle_info($needle_dir , $needle_name , \%basic_needle_data , $module_detail -> {json },
133
- 0, \@error_messages );
158
+ 0, \@error_messages , $needle_ref );
134
159
if ($needle_info ) {
135
160
$needle_info -> {matches } = $screenshot -> {matches };
136
161
push (@needles , $needle_info );
@@ -144,10 +169,10 @@ sub edit ($self) {
144
169
# $needle contains information from result, in which 'areas' refers to the best matches.
145
170
# We also use $area for transforming the match information into a real area
146
171
for my $needle (@$module_detail_needles ) {
147
- my $needle_info = $self -> _extended_needle_info(
148
- $needle_dir , $needle -> {name }, \%basic_needle_data ,
149
- $needle -> {json }, $needle -> {error }, \@error_messages
150
- ) || next ;
172
+ my $needle_info
173
+ = $self -> _extended_needle_info( $needle_dir , $needle -> {name }, \%basic_needle_data ,
174
+ $needle -> {json }, $needle -> {error }, \@error_messages , $needle_ref )
175
+ || next ;
151
176
my $matches = $needle_info -> {matches };
152
177
for my $match (@{$needle -> {area }}) {
153
178
my %area = (
@@ -188,7 +213,7 @@ sub edit ($self) {
188
213
# get needle info to show the needle also in selection
189
214
my $needle_info
190
215
= $self -> _extended_needle_info($needle_dir , $new_needle -> name, \%basic_needle_data , $new_needle -> path,
191
- undef , \@error_messages )
216
+ undef , \@error_messages , $needle_ref )
192
217
|| next ;
193
218
$needle_info -> {title } = ' new: ' . $needle_info -> {title };
194
219
push (@needles , $needle_info );
@@ -274,9 +299,9 @@ sub _new_screenshot ($self, $tags, $image_name, $matches = undef) {
274
299
return \%screenshot ;
275
300
}
276
301
277
- sub _basic_needle_info ($self , $name , $distri , $version , $file_name , $needles_dir ) {
302
+ sub _basic_needle_info ($self , $name , $distri , $version , $file_name , $needles_dir , $needle_ref ) {
278
303
$file_name //= " $name .json" ;
279
- $file_name = locate_needle($file_name , $needles_dir ) if !-f $file_name ;
304
+ $file_name = locate_needle($file_name , $needles_dir , $needle_ref ) if !-f $file_name ;
280
305
return (undef , ' File not found' ) unless defined $file_name ;
281
306
282
307
my $needle ;
@@ -303,11 +328,14 @@ sub _basic_needle_info ($self, $name, $distri, $version, $file_name, $needles_di
303
328
return ($needle , undef );
304
329
}
305
330
306
- sub _extended_needle_info ($self , $needle_dir , $needle_name , $basic_needle_data , $file_name , $error , $error_messages ) {
331
+ sub _extended_needle_info ($self , $needle_dir , $needle_name , $basic_needle_data , $file_name , $error , $error_messages ,
332
+ $needle_ref )
333
+ {
307
334
my $overall_list_of_tags = $basic_needle_data -> {tags };
308
335
my $distri = $basic_needle_data -> {distri };
309
336
my $version = $basic_needle_data -> {version };
310
- my ($needle_info , $err ) = $self -> _basic_needle_info($needle_name , $distri , $version , $file_name , $needle_dir );
337
+ my ($needle_info , $err )
338
+ = $self -> _basic_needle_info($needle_name , $distri , $version , $file_name , $needle_dir , $needle_ref );
311
339
unless (defined $needle_info ) {
312
340
push (@$error_messages , " Could not parse needle $needle_name for $distri $version : $err " );
313
341
return undef ;
@@ -465,6 +493,7 @@ sub viewimg ($self) {
465
493
my $distri = $job -> DISTRI;
466
494
my $dversion = $job -> VERSION || ' ' ;
467
495
my $needle_dir = $job -> needle_dir;
496
+ my $needle_ref = $self -> _create_tmpdir_for_needles_refspec($job );
468
497
my $real_needle_dir = realpath($needle_dir ) // $needle_dir ;
469
498
my $needles_rs = $self -> app-> schema-> resultset(' Needles' );
470
499
@@ -477,7 +506,7 @@ sub viewimg ($self) {
477
506
my $append_needle_info = sub ($tags , $needle_info ) {
478
507
# add timestamps and URLs from database
479
508
$self -> populate_hash_with_needle_timestamps_and_urls(
480
- $needles_rs -> find_needle($real_needle_dir , " $needle_info ->{name}.json" ), $needle_info );
509
+ $needles_rs -> find_needle($job -> needle_dir , " $needle_info ->{name}.json" ), $needle_info );
481
510
482
511
# handle case when the needle has (for some reason) no tags
483
512
if (!$tags ) {
@@ -500,7 +529,8 @@ sub viewimg ($self) {
500
529
# load primary needle match
501
530
my $primary_match ;
502
531
if (my $needle = $module_detail -> {needle }) {
503
- my ($needleinfo ) = $self -> _basic_needle_info($needle , $distri , $dversion , $module_detail -> {json }, $needle_dir );
532
+ my ($needleinfo )
533
+ = $self -> _basic_needle_info($needle , $distri , $dversion , $module_detail -> {json }, $needle_dir , $needle_ref );
504
534
if ($needleinfo ) {
505
535
my $info = {
506
536
name => $needle ,
@@ -522,7 +552,8 @@ sub viewimg ($self) {
522
552
if ($module_detail -> {needles }) {
523
553
for my $needle (@{$module_detail -> {needles }}) {
524
554
my $needlename = $needle -> {name };
525
- my ($needleinfo ) = $self -> _basic_needle_info($needlename , $distri , $dversion , $needle -> {json }, $needle_dir );
555
+ my ($needleinfo )
556
+ = $self -> _basic_needle_info($needlename , $distri , $dversion , $needle -> {json }, $needle_dir , $needle_ref );
526
557
next unless $needleinfo ;
527
558
my $info = {
528
559
name => $needlename ,
0 commit comments