From 45ced33ab6923ad8885dcb5275253d4cb8cbc983 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 24 May 2021 15:22:25 -0700 Subject: [PATCH] Projects: don't respond with unnecessary declarative field If the project isn't declarative, who cares about it in the response? After setting the `declfile` to an empty string, everything related to declarative- ness is wiped out, anyways. --- src/lib/Hydra/Schema/Projects.pm | 10 +++++++--- t/Controller/projects.t | 14 ++------------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/lib/Hydra/Schema/Projects.pm b/src/lib/Hydra/Schema/Projects.pm index 8413481a..fab0d4fa 100644 --- a/src/lib/Hydra/Schema/Projects.pm +++ b/src/lib/Hydra/Schema/Projects.pm @@ -263,15 +263,19 @@ sub as_json { "enabled" => $self->get_column("enabled") ? JSON::true : JSON::false, "hidden" => $self->get_column("hidden") ? JSON::true : JSON::false, + "jobsets" => [ map { $_->name } $self->jobsets ] + ); + + my %decl = ( "declarative" => { "file" => $self->get_column("declfile") // "", "type" => $self->get_column("decltype") // "", "value" => $self->get_column("declvalue") // "" - }, - - "jobsets" => [ map { $_->name } $self->jobsets ] + } ); + %json = (%json, %decl) if !($decl{"declarative"}->{"file"} eq ""); + return \%json; } diff --git a/t/Controller/projects.t b/t/Controller/projects.t index af3db3d8..fb7df6ad 100644 --- a/t/Controller/projects.t +++ b/t/Controller/projects.t @@ -49,12 +49,7 @@ subtest "Read project 'tests'" => sub { homepage => "", jobsets => [], name => "tests", - owner => "root", - declarative => { - file => "", - type => "", - value => "" - } + owner => "root" }); }; @@ -136,12 +131,7 @@ subtest "Transitioning from declarative project to normal" => sub { homepage => "", jobsets => [], name => "tests", - owner => "root", - declarative => { - file => "", - type => "", - value => "" - } + owner => "root" }); }; };