-
Notifications
You must be signed in to change notification settings - Fork 220
PoC: Report status to Gitea when scheduled product finishes #6774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
69530dd
26cf918
2fa0e5e
2022c29
9957f4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # Copyright SUSE LLC | ||
| # SPDX-License-Identifier: GPL-2.0-or-later | ||
|
|
||
| package OpenQA::VcsProvider::Base; | ||
|
|
||
| use Mojo::Base -base, -signatures; | ||
| use Mojo::JSON qw(encode_json); | ||
| use Mojo::URL; | ||
|
|
||
| has 'app'; | ||
| has 'base_url'; | ||
| has 'statuses_url'; | ||
|
|
||
| sub add_params ($self, $params, $scheduled_product_id) { | ||
| $params->{context} //= 'openqa'; | ||
| $params->{description} //= 'openQA test run'; | ||
| my $base_url = $self->base_url; | ||
| $params->{target_url} //= "$base_url/admin/productlog?id=$scheduled_product_id" | ||
| if $scheduled_product_id && $base_url; | ||
| } | ||
|
|
||
| sub create_request ($self, $params) { | ||
| my $app = $self->app; | ||
| my $ua = $app->ua; | ||
| # TODO Note that anyone who can create an openQA job can set settings | ||
| # with a webhook id and a statuses URL. Maybe we should configure the | ||
| # base url for each git provider and double check the url, because | ||
| # we are making an API request with a token to an otherwise unchecked URL | ||
| my $url = Mojo::URL->new($self->statuses_url); | ||
| my $tx = $ua->build_tx(POST => $url); | ||
| my $req = $tx->req; | ||
| my $json = encode_json($params); | ||
| $req->body($json); | ||
| my $headers = $req->headers; | ||
| $headers->content_type('application/json'); | ||
| $headers->content_length(length $json); | ||
|
|
||
| return $tx; | ||
| } | ||
|
|
||
| sub report_status_to_git ($self, $params, $scheduled_product_id, $callback = undef) { | ||
| $self->add_params($params, $scheduled_product_id); | ||
|
|
||
| my $tx = $self->create_request($params); | ||
| $self->app->ua->start($tx, $callback); | ||
| return $tx; | ||
| } | ||
|
|
||
| 1; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Copyright SUSE LLC | ||
| # SPDX-License-Identifier: GPL-2.0-or-later | ||
|
|
||
| package OpenQA::VcsProvider::GitHub; | ||
|
|
||
| use Mojo::Base 'OpenQA::VcsProvider::Base', -signatures; | ||
|
|
||
| sub read_settings ($self, $settings) { | ||
| $self->statuses_url($settings->{GITHUB_STATUSES_URL}); | ||
| $self->base_url($settings->{CI_TARGET_URL}); | ||
| return undef unless $self->statuses_url; | ||
| return 1; | ||
| } | ||
|
|
||
| sub create_request ($self, $params) { | ||
| my $tx = $self->SUPER::create_request($params); | ||
|
|
||
| my $headers = $tx->req->headers; | ||
| my $github_token = $self->app->config->{secrets}->{github_token}; | ||
| $headers->header(Accept => 'application/vnd.github+json'); | ||
| $headers->header(Authorization => "Bearer $github_token"); | ||
| $headers->header('X-GitHub-Api-Version' => '2022-11-28'); | ||
|
|
||
| return $tx; | ||
| } | ||
|
|
||
| 1; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Copyright SUSE LLC | ||
| # SPDX-License-Identifier: GPL-2.0-or-later | ||
|
|
||
| package OpenQA::VcsProvider::Gitea; | ||
|
|
||
| use Mojo::Base 'OpenQA::VcsProvider::Base', -signatures; | ||
|
|
||
| sub read_settings ($self, $settings) { | ||
| $self->statuses_url($settings->{GITEA_STATUSES_URL}); | ||
| $self->base_url($settings->{CI_TARGET_URL}); | ||
| return undef unless $self->statuses_url; | ||
| return 1; | ||
| } | ||
|
|
||
| sub create_request ($self, $params) { | ||
| my $tx = $self->SUPER::create_request($params); | ||
|
|
||
| my $headers = $tx->req->headers; | ||
| # TODO there might be more than one gitea server -> add sections? | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just commenting to be able to link to this more easily
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably need to be able to configure one token per instance, so yes we probably need multiple sections. |
||
| my $token = $self->app->config->{secrets}->{gitea_token}; | ||
| $headers->header(Accept => 'application/json'); | ||
| $headers->header(Authorization => "Bearer $token"); | ||
|
|
||
| return $tx; | ||
| } | ||
|
|
||
| 1; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just commenting to be able to link to this more easily
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should definitely add such a check.