forked from lix-project/hydra
Project: add declfile, decltype, declvalue to API
This makes it possible to create declarative projects via a PUT request, and also exposes the currently-configured values to GET requests.
This commit is contained in:
parent
e9a06113c9
commit
ad13d13436
|
@ -181,6 +181,10 @@ paths:
|
||||||
visible:
|
visible:
|
||||||
description: when set to true the project is displayed in the web interface
|
description: when set to true the project is displayed in the web interface
|
||||||
type: boolean
|
type: boolean
|
||||||
|
declarative:
|
||||||
|
description: declarative input configured for this project
|
||||||
|
type: object
|
||||||
|
$ref: '#/components/schemas/DeclarativeInput'
|
||||||
responses:
|
responses:
|
||||||
'400':
|
'400':
|
||||||
description: bad request
|
description: bad request
|
||||||
|
@ -577,12 +581,29 @@ components:
|
||||||
enabled:
|
enabled:
|
||||||
description: when set to true the project gets scheduled for evaluation
|
description: when set to true the project gets scheduled for evaluation
|
||||||
type: boolean
|
type: boolean
|
||||||
|
declarative:
|
||||||
|
description: declarative input configured for this project
|
||||||
|
type: object
|
||||||
|
$ref: '#/components/schemas/DeclarativeInput'
|
||||||
jobsets:
|
jobsets:
|
||||||
description: list of jobsets belonging to this project
|
description: list of jobsets belonging to this project
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
|
|
||||||
|
DeclarativeInput:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
file:
|
||||||
|
description: The file in `value` which contains the declarative spec file. Relative to the root of `value`.
|
||||||
|
type: string
|
||||||
|
type:
|
||||||
|
description: The type of the declarative input.
|
||||||
|
type: string
|
||||||
|
value:
|
||||||
|
description: The value of the declarative input.
|
||||||
|
type: string
|
||||||
|
|
||||||
JobsetInput:
|
JobsetInput:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
|
|
@ -157,9 +157,9 @@ sub updateProject {
|
||||||
, enabled => defined $c->stash->{params}->{enabled} ? 1 : 0
|
, enabled => defined $c->stash->{params}->{enabled} ? 1 : 0
|
||||||
, hidden => defined $c->stash->{params}->{visible} ? 0 : 1
|
, hidden => defined $c->stash->{params}->{visible} ? 0 : 1
|
||||||
, owner => $owner
|
, owner => $owner
|
||||||
, declfile => trim($c->stash->{params}->{declfile})
|
, declfile => trim($c->stash->{params}->{declarative}->{file})
|
||||||
, decltype => trim($c->stash->{params}->{decltype})
|
, decltype => trim($c->stash->{params}->{declarative}->{type})
|
||||||
, declvalue => trim($c->stash->{params}->{declvalue})
|
, declvalue => trim($c->stash->{params}->{declarative}->{value})
|
||||||
});
|
});
|
||||||
if (length($project->declfile)) {
|
if (length($project->declfile)) {
|
||||||
$project->jobsets->update_or_create(
|
$project->jobsets->update_or_create(
|
||||||
|
|
|
@ -246,25 +246,31 @@ __PACKAGE__->many_to_many("usernames", "projectmembers", "username");
|
||||||
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-25 14:38:14
|
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-25 14:38:14
|
||||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+4yWd9UjCyxxLZYDrVUAxA
|
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+4yWd9UjCyxxLZYDrVUAxA
|
||||||
|
|
||||||
my %hint = (
|
sub as_json {
|
||||||
string_columns => [
|
my $self = shift;
|
||||||
"name",
|
|
||||||
"displayname",
|
my %json = (
|
||||||
"description",
|
# string_columns
|
||||||
"homepage",
|
"name" => $self->get_column("name") // "",
|
||||||
"owner"
|
"displayname" => $self->get_column("displayname") // "",
|
||||||
],
|
"description" => $self->get_column("description") // "",
|
||||||
boolean_columns => [
|
"homepage" => $self->get_column("homepage") // "",
|
||||||
"enabled",
|
"owner" => $self->get_column("owner") // "",
|
||||||
"hidden"
|
|
||||||
],
|
# boolean_columns
|
||||||
relations => {
|
"enabled" => $self->get_column("enabled") ? JSON::true : JSON::false,
|
||||||
jobsets => "name"
|
"hidden" => $self->get_column("hidden") ? JSON::true : JSON::false,
|
||||||
}
|
|
||||||
|
"declarative" => {
|
||||||
|
"file" => $self->get_column("declfile") // "",
|
||||||
|
"type" => $self->get_column("decltype") // "",
|
||||||
|
"value" => $self->get_column("declvalue") // ""
|
||||||
|
},
|
||||||
|
|
||||||
|
"jobsets" => [ map { $_->name } $self->jobsets ]
|
||||||
);
|
);
|
||||||
|
|
||||||
sub json_hint {
|
return \%json;
|
||||||
return \%hint;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -79,13 +79,28 @@
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$("#submit-project").click(function() {
|
$("#submit-project").click(function() {
|
||||||
|
var formElements = $(this).parents("form").serializeArray();
|
||||||
|
var data = { 'declarative': {} };
|
||||||
|
var decl = {};
|
||||||
|
for (var i = 0; formElements.length > i; i++) {
|
||||||
|
var elem = formElements[i];
|
||||||
|
var match = elem.name.match(/^decl(file|type|value)$/);
|
||||||
|
if (match === null) {
|
||||||
|
data[elem.name] = elem.value;
|
||||||
|
} else {
|
||||||
|
var param = match[1];
|
||||||
|
decl[param] = elem.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data.declarative = decl;
|
||||||
redirectJSON({
|
redirectJSON({
|
||||||
[% IF create %]
|
[% IF create %]
|
||||||
url: "[% c.uri_for('/project' '.new') %]",
|
url: "[% c.uri_for('/project' '.new') %]",
|
||||||
[% ELSE %]
|
[% ELSE %]
|
||||||
url: "[% c.uri_for('/project' project.name) %]",
|
url: "[% c.uri_for('/project' project.name) %]",
|
||||||
[% END %]
|
[% END %]
|
||||||
data: $(this).parents("form").serialize(),
|
data: JSON.stringify(data),
|
||||||
|
contentType: 'application/json',
|
||||||
type: 'PUT'
|
type: 'PUT'
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -32,7 +32,12 @@ is(decode_json($projectinfo->content), {
|
||||||
homepage => "",
|
homepage => "",
|
||||||
jobsets => [],
|
jobsets => [],
|
||||||
name => "tests",
|
name => "tests",
|
||||||
owner => "root"
|
owner => "root",
|
||||||
|
declarative => {
|
||||||
|
file => "",
|
||||||
|
type => "",
|
||||||
|
value => ""
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
Loading…
Reference in a new issue