Skip to content

Commit 53d61bd

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 5f03a89 commit 53d61bd

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/OpenQA/Schema/ResultSet/Jobs.pm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,16 @@ sub mark_job_linked ($self, $jobid, $referer_url) {
476476
return undef if !$job || ($referer->path_query =~ /^\/?$/);
477477
my $comments = $job->comments;
478478
return undef if $comments->search({text => {like => 'label:linked%'}}, {rows => 1})->first;
479+
return undef unless _specific_issue_exists($referer);
479480
my $user = $self->result_source->schema->resultset('Users')->system({select => ['id']});
480481
$comments->create_with_event({text => "label:linked Job mentioned in $referer_url", user_id => $user->id});
481482
}
482483

484+
sub _specific_issue_exists ($url) {
485+
my $path = $url->path();
486+
my ($issue_id) = $path =~ m/(?:id=|\/)(\d+)/;
487+
# Assume that the url is valid if there is issue_id
488+
return defined $issue_id;
489+
}
490+
483491
1;

t/10-jobs-referal.t

Lines changed: 9 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;
@@ -57,6 +57,14 @@ subtest 'job is marked as linked if accessed from recognized referal' => sub {
5757
$t->get_ok('/tests/' . $job->id . '/modules/' . $module->id . '/steps/1' => {Referer => $test_referer})
5858
->status_is(302);
5959
is job_is_linked($job), 1, 'job linked after accessed from known referer';
60+
61+
subtest 'do not link not existing tickets from recognized referal' => sub {
62+
$test_referer = 'http://test.referer.info/foobar/new';
63+
my $job = _job_create(\%_settings);
64+
is job_is_linked($job), 0, 'new job is not linked';
65+
$t->get_ok('/tests/' . $job->id => {Referer => $test_referer})->status_is(200);
66+
is job_is_linked($job), 0, 'job is not linked from known referer without an issue_id';
67+
};
6068
};
6169

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

0 commit comments

Comments
 (0)