Skip to content

Commit 2fa0e5e

Browse files
committed
Add statuses_url attribute
1 parent 26cf918 commit 2fa0e5e

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

lib/OpenQA/Schema/Result/ScheduledProducts.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -935,13 +935,13 @@ sub _format_check_description ($verb, $count, $total) {
935935
sub report_status_to_git ($self, $callback = undef) {
936936
my $id = $self->id;
937937
my $settings = $self->{_settings} // $self->settings;
938-
return undef unless my $github_statuses_url = $settings->{GITHUB_STATUSES_URL};
938+
my $vcs = OpenQA::VcsProvider->new(app => OpenQA::App->singleton);
939+
$vcs->read_settings($settings) or return undef;
939940
my ($state, $verb, $count, $total) = $self->state_for_ci_status;
940941
return undef unless $state;
941-
my $vcs = OpenQA::VcsProvider->new(app => OpenQA::App->singleton);
942942
my $base_url = $settings->{CI_TARGET_URL};
943943
my %params = (state => $state, description => _format_check_description($verb, $count, $total));
944-
$vcs->report_status_to_git($github_statuses_url, \%params, $id, $base_url, $callback);
944+
$vcs->report_status_to_git(\%params, $id, $base_url, $callback);
945945
}
946946

947947
sub cancel ($self, $reason = undef) {

lib/OpenQA/VcsProvider.pm

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,21 @@ use Mojo::JSON qw(encode_json);
88
use Mojo::URL;
99

1010
has 'app';
11+
has 'statuses_url';
1112

12-
sub report_status_to_git ($self, $statuses_url, $params, $scheduled_product_id, $base_url, $callback = undef) {
13+
sub read_settings ($self, $settings) {
14+
$self->statuses_url($settings->{GITHUB_STATUSES_URL});
15+
return undef unless $self->statuses_url;
16+
return 1;
17+
}
18+
19+
sub report_status_to_git ($self, $params, $scheduled_product_id, $base_url, $callback = undef) {
1320
$params->{context} //= 'openqa';
1421
$params->{description} //= 'openQA test run';
1522
$params->{target_url} //= "$base_url/admin/productlog?id=$scheduled_product_id"
1623
if $scheduled_product_id && $base_url;
1724

18-
my $url = Mojo::URL->new($statuses_url);
25+
my $url = Mojo::URL->new($self->statuses_url);
1926
my $app = $self->app;
2027
my $ua = $app->ua;
2128
my $tx = $ua->build_tx(POST => $url);

lib/OpenQA/WebAPI/Controller/API/V1/Webhook.pm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ sub product ($self) {
153153
return $self->render(json => $scheduled_product->enqueue_minion_job(\%params));
154154
};
155155
$scheduled_product->discard_changes; # load value of columns that have a default value
156-
my $tx = $vcs->report_status_to_git($statuses_url, {state => 'pending'}, $scheduled_product->id, $base_url, $cb);
156+
$vcs->statuses_url($statuses_url);
157+
# $vcs->read_settings($settings) or return undef;
158+
my $tx = $vcs->report_status_to_git({state => 'pending'}, $scheduled_product->id, $base_url, $cb);
157159
}
158160

159161
1;

t/16-utils-vcs-provider.t

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ subtest 'reporting status to GitHub' => sub {
2222

2323
my $git = OpenQA::VcsProvider->new(app => $app);
2424
my $url = 'http://127.0.0.1/repos/some/repo/statuses/some-sha';
25-
my $tx = $git->report_status_to_git($url, {state => 'pending'}, '42', 'https://openqa.opensuse.org');
25+
$git->read_settings({GITHUB_STATUSES_URL => $url});
26+
my $tx = $git->report_status_to_git({state => 'pending'}, '42', 'https://openqa.opensuse.org');
2627
my $req = $tx->req;
2728
is $req->method, 'POST', 'method';
2829
is $req->url, $url, 'URL';

t/api/16-webhooks.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ my $expected_ci_check_state = 'pending';
101101
my $expected_ci_check_desc = undef;
102102
$vcs_mock->redefine(
103103
report_status_to_git =>
104-
sub ($self, $statuses_url, $params, $scheduled_product_id, $base_url_from_req, $callback) {
104+
sub ($self, $params, $scheduled_product_id, $base_url_from_req, $callback) {
105105
my $tx = $ua->build_tx(POST => 'http://dummy');
106-
is $statuses_url, $expected_statuses_url, 'URL from webhook payload used for reporting back';
106+
is $self->statuses_url, $expected_statuses_url, 'URL from webhook payload used for reporting back';
107107
is $params->{state}, $expected_ci_check_state, "check reported to be $expected_ci_check_state";
108108
is $params->{description}, $expected_ci_check_desc, 'check description';
109109
++$status_reports;

0 commit comments

Comments
 (0)