Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3b161b6

Browse files
authoredApr 29, 2021
Revert "ToJSON: allow custom as_json function; JobsetInputs, Jobsets: update schema to align with the API"
1 parent ec288e6 commit 3b161b6

File tree

8 files changed

+80
-81
lines changed

8 files changed

+80
-81
lines changed
 

‎hydra-api.yaml

+9-7
Original file line numberDiff line numberDiff line change
@@ -589,15 +589,17 @@ components:
589589
name:
590590
description: name of the input
591591
type: string
592-
value:
593-
description: value of the input
594-
type: string
595592
type:
596593
description: type of input
597594
type: string
598595
emailresponsible:
599596
description: whether or not to email responsible parties
600597
type: boolean
598+
jobsetinputalts:
599+
type: array
600+
description: ???
601+
items:
602+
type: string
601603

602604
Jobset:
603605
type: object
@@ -642,8 +644,8 @@ components:
642644
enableemail:
643645
description: when true the jobset sends emails when previously-successful builds fail
644646
type: boolean
645-
visible:
646-
description: when true the jobset is visible in the web frontend
647+
hidden:
648+
description: when false the jobset is visible in the web frontend
647649
type: boolean
648650
emailoverride:
649651
description: email address to send notices to instead of the package maintainer (can be a comma separated list)
@@ -667,12 +669,12 @@ components:
667669
type: integer
668670
type:
669671
description: the type of the jobset
670-
type: integer
672+
type: string
671673
flake:
672674
nullable: true
673675
description: the flake uri to evaluate
674676
type: string
675-
inputs:
677+
jobsetinputs:
676678
description: inputs configured for this jobset
677679
type: object
678680
additionalProperties:

‎src/lib/Hydra/Component/ToJSON.pm

-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ use JSON;
1010
sub TO_JSON {
1111
my $self = shift;
1212

13-
if ($self->can("as_json")) {
14-
return $self->as_json();
15-
}
16-
1713
my $hint = $self->json_hint;
1814

1915
my %json = ();

‎src/lib/Hydra/Controller/Jobset.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ sub updateJobset {
270270
$jobset->jobsetinputs->delete;
271271

272272
if ($type == 0) {
273-
foreach my $name (keys %{$c->stash->{params}->{inputs}}) {
274-
my $inputData = $c->stash->{params}->{inputs}->{$name};
273+
foreach my $name (keys %{$c->stash->{params}->{jobsetinputs}}) {
274+
my $inputData = $c->stash->{params}->{jobsetinputs}->{$name};
275275
my $type = $inputData->{type};
276276
my $value = $inputData->{value};
277277
my $emailresponsible = defined $inputData->{emailresponsible} ? 1 : 0;

‎src/lib/Hydra/Schema/JobsetInputs.pm

+14-15
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,21 @@ __PACKAGE__->has_many(
134134
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2020-02-06 12:22:36
135135
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:5uKwEhDXso4IR1TFmwRxiA
136136

137-
sub as_json {
138-
my $self = shift;
139-
140-
my ($input) = $self->jobsetinputalts;
141-
142-
my %json = (
143-
# string_columns
144-
"name" => $self->get_column("name") // "",
145-
"type" => $self->get_column("type") // "",
146-
"value" => $input->value // "",
147-
148-
# boolean_columns
149-
"emailresponsible" => $self->get_column("emailresponsible") ? JSON::true : JSON::false,
150-
);
137+
my %hint = (
138+
string_columns => [
139+
"name",
140+
"type"
141+
],
142+
boolean_columns => [
143+
"emailresponsible"
144+
],
145+
relations => {
146+
"jobsetinputalts" => "value"
147+
}
148+
);
151149

152-
return \%json;
150+
sub json_hint {
151+
return \%hint;
153152
}
154153

155154
1;

‎src/lib/Hydra/Schema/Jobsets.pm

+34-34
Original file line numberDiff line numberDiff line change
@@ -410,40 +410,40 @@ __PACKAGE__->add_column(
410410
"+id" => { retrieve_on_insert => 1 }
411411
);
412412

413-
sub as_json {
414-
my $self = shift;
415-
416-
my %json = (
417-
# columns
418-
"errortime" => $self->get_column("errortime"),
419-
"lastcheckedtime" => $self->get_column("lastcheckedtime"),
420-
"triggertime" => $self->get_column("triggertime"),
421-
"enabled" => $self->get_column("enabled"),
422-
"keepnr" => $self->get_column("keepnr"),
423-
"checkinterval" => $self->get_column("checkinterval"),
424-
"schedulingshares" => $self->get_column("schedulingshares"),
425-
"starttime" => $self->get_column("starttime"),
426-
427-
# string_columns
428-
"name" => $self->get_column("name") // "",
429-
"project" => $self->get_column("project") // "",
430-
"description" => $self->get_column("description") // "",
431-
"nixexprinput" => $self->get_column("nixexprinput") // "",
432-
"nixexprpath" => $self->get_column("nixexprpath") // "",
433-
"errormsg" => $self->get_column("errormsg") // "",
434-
"emailoverride" => $self->get_column("emailoverride") // "",
435-
"fetcherrormsg" => $self->get_column("fetcherrormsg") // "",
436-
"type" => $self->get_column("type") // "",
437-
"flake" => $self->get_column("flake") // "",
438-
439-
# boolean_columns
440-
"enableemail" => $self->get_column("enableemail") ? JSON::true : JSON::false,
441-
"visible" => $self->get_column("hidden") ? JSON::false : JSON::true,
442-
443-
"inputs" => { map { $_->name => $_ } $self->jobsetinputs }
444-
);
445-
446-
return \%json;
413+
my %hint = (
414+
columns => [
415+
"errortime",
416+
"lastcheckedtime",
417+
"triggertime",
418+
"enabled",
419+
"keepnr",
420+
"checkinterval",
421+
"schedulingshares",
422+
"starttime"
423+
],
424+
string_columns => [
425+
"name",
426+
"project",
427+
"description",
428+
"nixexprinput",
429+
"nixexprpath",
430+
"errormsg",
431+
"emailoverride",
432+
"fetcherrormsg",
433+
"type",
434+
"flake"
435+
],
436+
boolean_columns => [
437+
"enableemail",
438+
"hidden"
439+
],
440+
eager_relations => {
441+
jobsetinputs => "name"
442+
}
443+
);
444+
445+
sub json_hint {
446+
return \%hint;
447447
}
448448

449449
1;

‎src/root/edit-jobset.tt

+8-8
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
<thead>
4747
<tr><th></th><th>Input name</th><th>Type</th><th style="width: 50%">Value</th><th>Notify committers</th></tr>
4848
</thead>
49-
<tbody class="inputs">
50-
[% inputs = createFromEval ? eval.jobsetevalinputs : jobset.jobsetinputs; FOREACH input IN inputs %]
49+
<tbody class="jobsetinputs">
50+
[% jobsetinputs = createFromEval ? eval.jobsetevalinputs : jobset.jobsetinputs; FOREACH input IN jobsetinputs %]
5151
[% INCLUDE renderJobsetInput input=input baseName="input-$input.name" %]
5252
[% END %]
5353
<tr>
@@ -220,8 +220,8 @@
220220

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

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

236-
if (!(baseName in inputs))
237-
inputs[baseName] = {};
236+
if (!(baseName in jobsetinputs))
237+
jobsetinputs[baseName] = {};
238238

239239
if (param === "name")
240-
data.inputs[elem.value] = inputs[baseName];
240+
data.jobsetinputs[elem.value] = jobsetinputs[baseName];
241241
else
242-
inputs[baseName][param] = elem.value;
242+
jobsetinputs[baseName][param] = elem.value;
243243
}
244244
}
245245
redirectJSON({

‎t/Controller/Jobset/http.t

+10-8
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ subtest 'Create new jobset "job" as flake type' => sub {
4646
Cookie => $cookie,
4747
Content => encode_json({
4848
enabled => 2,
49-
visible => JSON::true,
49+
visible => 1,
5050
name => "job",
5151
type => 1,
5252
description => "test jobset",
@@ -76,8 +76,8 @@ subtest 'Read newly-created jobset "job"' => sub {
7676
errormsg => "",
7777
fetcherrormsg => "",
7878
flake => "github:nixos/nix",
79-
visible => JSON::true,
80-
inputs => {},
79+
hidden => JSON::false,
80+
jobsetinputs => {},
8181
keepnr => 3,
8282
lastcheckedtime => undef,
8383
name => "job",
@@ -99,12 +99,12 @@ subtest 'Update jobset "job" to legacy type' => sub {
9999
Cookie => $cookie,
100100
Content => encode_json({
101101
enabled => 3,
102-
visible => JSON::true,
102+
visible => 1,
103103
name => "job",
104104
type => 0,
105105
nixexprinput => "ofborg",
106106
nixexprpath => "release.nix",
107-
inputs => {
107+
jobsetinputs => {
108108
ofborg => {
109109
name => "ofborg",
110110
type => "git",
@@ -134,13 +134,15 @@ subtest 'Update jobset "job" to legacy type' => sub {
134134
errormsg => "",
135135
fetcherrormsg => "",
136136
flake => "",
137-
visible => JSON::true,
138-
inputs => {
137+
hidden => JSON::false,
138+
jobsetinputs => {
139139
ofborg => {
140140
name => "ofborg",
141141
type => "git",
142142
emailresponsible => JSON::false,
143-
value => "https://github.com/NixOS/ofborg.git released"
143+
jobsetinputalts => [
144+
"https://github.com/NixOS/ofborg.git released"
145+
]
144146
}
145147
},
146148
keepnr => 1,

‎t/api-test.t

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ subtest "projects" => sub {
8181
};
8282

8383
subtest "jobsets" => sub {
84-
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"} });
84+
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"} });
8585
is($result->code(), 201, "PUTting a new jobset creates it");
8686

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

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

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

9494
subtest "evaluation" => sub {

0 commit comments

Comments
 (0)
Please sign in to comment.