Skip to content

Commit

Permalink
Revert "ToJSON: allow custom as_json function; JobsetInputs, Jobsets:…
Browse files Browse the repository at this point in the history
… update schema to align with the API"
  • Loading branch information
grahamc committed Apr 29, 2021
1 parent ec288e6 commit 3b161b6
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 81 deletions.
16 changes: 9 additions & 7 deletions hydra-api.yaml
Expand Up @@ -589,15 +589,17 @@ components:
name:
description: name of the input
type: string
value:
description: value of the input
type: string
type:
description: type of input
type: string
emailresponsible:
description: whether or not to email responsible parties
type: boolean
jobsetinputalts:
type: array
description: ???
items:
type: string

Jobset:
type: object
Expand Down Expand Up @@ -642,8 +644,8 @@ components:
enableemail:
description: when true the jobset sends emails when previously-successful builds fail
type: boolean
visible:
description: when true the jobset is visible in the web frontend
hidden:
description: when false the jobset is visible in the web frontend
type: boolean
emailoverride:
description: email address to send notices to instead of the package maintainer (can be a comma separated list)
Expand All @@ -667,12 +669,12 @@ components:
type: integer
type:
description: the type of the jobset
type: integer
type: string
flake:
nullable: true
description: the flake uri to evaluate
type: string
inputs:
jobsetinputs:
description: inputs configured for this jobset
type: object
additionalProperties:
Expand Down
4 changes: 0 additions & 4 deletions src/lib/Hydra/Component/ToJSON.pm
Expand Up @@ -10,10 +10,6 @@ use JSON;
sub TO_JSON {
my $self = shift;

if ($self->can("as_json")) {
return $self->as_json();
}

my $hint = $self->json_hint;

my %json = ();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Hydra/Controller/Jobset.pm
Expand Up @@ -270,8 +270,8 @@ sub updateJobset {
$jobset->jobsetinputs->delete;

if ($type == 0) {
foreach my $name (keys %{$c->stash->{params}->{inputs}}) {
my $inputData = $c->stash->{params}->{inputs}->{$name};
foreach my $name (keys %{$c->stash->{params}->{jobsetinputs}}) {
my $inputData = $c->stash->{params}->{jobsetinputs}->{$name};
my $type = $inputData->{type};
my $value = $inputData->{value};
my $emailresponsible = defined $inputData->{emailresponsible} ? 1 : 0;
Expand Down
29 changes: 14 additions & 15 deletions src/lib/Hydra/Schema/JobsetInputs.pm
Expand Up @@ -134,22 +134,21 @@ __PACKAGE__->has_many(
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2020-02-06 12:22:36
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:5uKwEhDXso4IR1TFmwRxiA

sub as_json {
my $self = shift;

my ($input) = $self->jobsetinputalts;

my %json = (
# string_columns
"name" => $self->get_column("name") // "",
"type" => $self->get_column("type") // "",
"value" => $input->value // "",

# boolean_columns
"emailresponsible" => $self->get_column("emailresponsible") ? JSON::true : JSON::false,
);
my %hint = (
string_columns => [
"name",
"type"
],
boolean_columns => [
"emailresponsible"
],
relations => {
"jobsetinputalts" => "value"
}
);

return \%json;
sub json_hint {
return \%hint;
}

1;
68 changes: 34 additions & 34 deletions src/lib/Hydra/Schema/Jobsets.pm
Expand Up @@ -410,40 +410,40 @@ __PACKAGE__->add_column(
"+id" => { retrieve_on_insert => 1 }
);

sub as_json {
my $self = shift;

my %json = (
# columns
"errortime" => $self->get_column("errortime"),
"lastcheckedtime" => $self->get_column("lastcheckedtime"),
"triggertime" => $self->get_column("triggertime"),
"enabled" => $self->get_column("enabled"),
"keepnr" => $self->get_column("keepnr"),
"checkinterval" => $self->get_column("checkinterval"),
"schedulingshares" => $self->get_column("schedulingshares"),
"starttime" => $self->get_column("starttime"),

# string_columns
"name" => $self->get_column("name") // "",
"project" => $self->get_column("project") // "",
"description" => $self->get_column("description") // "",
"nixexprinput" => $self->get_column("nixexprinput") // "",
"nixexprpath" => $self->get_column("nixexprpath") // "",
"errormsg" => $self->get_column("errormsg") // "",
"emailoverride" => $self->get_column("emailoverride") // "",
"fetcherrormsg" => $self->get_column("fetcherrormsg") // "",
"type" => $self->get_column("type") // "",
"flake" => $self->get_column("flake") // "",

# boolean_columns
"enableemail" => $self->get_column("enableemail") ? JSON::true : JSON::false,
"visible" => $self->get_column("hidden") ? JSON::false : JSON::true,

"inputs" => { map { $_->name => $_ } $self->jobsetinputs }
);

return \%json;
my %hint = (
columns => [
"errortime",
"lastcheckedtime",
"triggertime",
"enabled",
"keepnr",
"checkinterval",
"schedulingshares",
"starttime"
],
string_columns => [
"name",
"project",
"description",
"nixexprinput",
"nixexprpath",
"errormsg",
"emailoverride",
"fetcherrormsg",
"type",
"flake"
],
boolean_columns => [
"enableemail",
"hidden"
],
eager_relations => {
jobsetinputs => "name"
}
);

sub json_hint {
return \%hint;
}

1;
16 changes: 8 additions & 8 deletions src/root/edit-jobset.tt
Expand Up @@ -46,8 +46,8 @@
<thead>
<tr><th></th><th>Input name</th><th>Type</th><th style="width: 50%">Value</th><th>Notify committers</th></tr>
</thead>
<tbody class="inputs">
[% inputs = createFromEval ? eval.jobsetevalinputs : jobset.jobsetinputs; FOREACH input IN inputs %]
<tbody class="jobsetinputs">
[% jobsetinputs = createFromEval ? eval.jobsetevalinputs : jobset.jobsetinputs; FOREACH input IN jobsetinputs %]
[% INCLUDE renderJobsetInput input=input baseName="input-$input.name" %]
[% END %]
<tr>
Expand Down Expand Up @@ -220,8 +220,8 @@

$("#submit-jobset").click(function() {
var formElements = $(this).parents("form").serializeArray();
var data = { 'inputs': {} };
var inputs = {};
var data = { 'jobsetinputs': {} };
var jobsetinputs = {};
for (var i = 0; formElements.length > i; i++) {
var elem = formElements[i];
var match = elem.name.match(/^input-([\w-]+)-(\w+)$/);
Expand All @@ -233,13 +233,13 @@

if (baseName === "template") continue;

if (!(baseName in inputs))
inputs[baseName] = {};
if (!(baseName in jobsetinputs))
jobsetinputs[baseName] = {};

if (param === "name")
data.inputs[elem.value] = inputs[baseName];
data.jobsetinputs[elem.value] = jobsetinputs[baseName];
else
inputs[baseName][param] = elem.value;
jobsetinputs[baseName][param] = elem.value;
}
}
redirectJSON({
Expand Down
18 changes: 10 additions & 8 deletions t/Controller/Jobset/http.t
Expand Up @@ -46,7 +46,7 @@ subtest 'Create new jobset "job" as flake type' => sub {
Cookie => $cookie,
Content => encode_json({
enabled => 2,
visible => JSON::true,
visible => 1,
name => "job",
type => 1,
description => "test jobset",
Expand Down Expand Up @@ -76,8 +76,8 @@ subtest 'Read newly-created jobset "job"' => sub {
errormsg => "",
fetcherrormsg => "",
flake => "github:nixos/nix",
visible => JSON::true,
inputs => {},
hidden => JSON::false,
jobsetinputs => {},
keepnr => 3,
lastcheckedtime => undef,
name => "job",
Expand All @@ -99,12 +99,12 @@ subtest 'Update jobset "job" to legacy type' => sub {
Cookie => $cookie,
Content => encode_json({
enabled => 3,
visible => JSON::true,
visible => 1,
name => "job",
type => 0,
nixexprinput => "ofborg",
nixexprpath => "release.nix",
inputs => {
jobsetinputs => {
ofborg => {
name => "ofborg",
type => "git",
Expand Down Expand Up @@ -134,13 +134,15 @@ subtest 'Update jobset "job" to legacy type' => sub {
errormsg => "",
fetcherrormsg => "",
flake => "",
visible => JSON::true,
inputs => {
hidden => JSON::false,
jobsetinputs => {
ofborg => {
name => "ofborg",
type => "git",
emailresponsible => JSON::false,
value => "https://github.com/NixOS/ofborg.git released"
jobsetinputalts => [
"https://github.com/NixOS/ofborg.git released"
]
}
},
keepnr => 1,
Expand Down
6 changes: 3 additions & 3 deletions t/api-test.t
Expand Up @@ -81,14 +81,14 @@ subtest "projects" => sub {
};

subtest "jobsets" => sub {
my $result = request_json({ uri => '/jobset/sample/default', method => 'PUT', data => { nixexprpath => "default.nix", nixexprinput => "my-src", inputs => { "my-src" => { type => "path", value => $jobsetdir } }, enabled => "1", visible => "1", checkinterval => "3600"} });
my $result = request_json({ uri => '/jobset/sample/default', method => 'PUT', data => { nixexprpath => "default.nix", nixexprinput => "my-src", jobsetinputs => { "my-src" => { type => "path", value => $jobsetdir } }, enabled => "1", visible => "1", checkinterval => "3600"} });
is($result->code(), 201, "PUTting a new jobset creates it");

my $jobset = decode_json(request_json({ uri => '/jobset/sample/default' })->content());

ok(exists $jobset->{inputs}->{"my-src"}, "The new jobset has a 'my-src' input");
ok(exists $jobset->{jobsetinputs}->{"my-src"}, "The new jobset has a 'my-src' input");

is($jobset->{inputs}->{"my-src"}->{value}, $jobsetdir, "The 'my-src' input is in $jobsetdir");
is($jobset->{jobsetinputs}->{"my-src"}->{"jobsetinputalts"}->[0], $jobsetdir, "The 'my-src' input is in $jobsetdir");
};

subtest "evaluation" => sub {
Expand Down

0 comments on commit 3b161b6

Please sign in to comment.