Skip to content

Commit 340721a

Browse files
committed
Link a job only with existing tracking issues
Assume that the referer has a issue_id otherwise do not link the URL in the comments. Once a ticket has been created the referer should contain an ID despite where it comes from. It could go one step further to send a request and check the response but it doesn't seem to be necessary. https://progress.opensuse.org/issues/176826
1 parent 0e363ab commit 340721a

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/OpenQA/Schema/ResultSet/Jobs.pm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,19 @@ sub mark_job_linked {
485485
return undef if !$job || ($referer->path_query =~ /^\/?$/);
486486
my $comments = $job->comments;
487487
return undef if $comments->search({text => {like => 'label:linked%'}}, {rows => 1})->first;
488+
return undef unless _specific_issue_exists($referer);
488489
my $user = $self->result_source->schema->resultset('Users')->system({select => ['id']});
489490
$comments->create_with_event({text => "label:linked Job mentioned in $referer_url", user_id => $user->id});
490491
}
491492

493+
sub _specific_issue_exists {
494+
my ($referer_url) = @_;
495+
my $url = Mojo::URL->new($referer_url);
496+
my $path = $url->path();
497+
my ($issue_id) = $path =~ m{\d+};
498+
# Assume that the url is valid if there is issue_id
499+
return 1 if defined $issue_id;
500+
return 0;
501+
}
502+
492503
1;

t/10-jobs-referal.t

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ sub job_is_linked ($job) {
3232
}
3333

3434
subtest 'job is marked as linked if accessed from recognized referal' => sub {
35-
my $test_referer = 'http://test.referer.info/foobar';
35+
my $test_referer = 'http://test.referer.info/foobar/123';
3636
$t->app->config->{global}->{recognized_referers}
3737
= ['test.referer.info', 'test.referer1.info', 'test.referer2.info', 'test.referer3.info'];
3838
my %_settings = %settings;
@@ -61,6 +61,17 @@ subtest 'job is marked as linked if accessed from recognized referal' => sub {
6161
->status_is(302);
6262
$linked = job_is_linked($job);
6363
is($linked, 1, 'job linked after accessed from known referer');
64+
65+
66+
subtest 'do not link not existing tickets from recognized referal' => sub {
67+
$test_referer = 'http://test.referer.info/foobar/new';
68+
my $job = _job_create(\%_settings);
69+
my $linked = job_is_linked($job);
70+
is($linked, 0, 'new job is not linked');
71+
$t->get_ok('/tests/' . $job->id => {Referer => $test_referer})->status_is(200);
72+
$linked = job_is_linked($job);
73+
is($linked, 0, 'job is not linked from known referer without an issue_id');
74+
};
6475
};
6576

6677
subtest 'job is not marked as linked if accessed from unrecognized referal' => sub {

0 commit comments

Comments
 (0)