Skip to content

Commit 3b86459

Browse files
committed
Add the build steps to the build/<id>/api/get-info endpoint.
1 parent e275604 commit 3b86459

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/lib/Hydra/Controller/Build.pm

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use warnings;
66
use base 'Hydra::Base::Controller::NixChannel';
77
use Hydra::Helper::Nix;
88
use Hydra::Helper::CatalystUtils;
9+
use Hydra::Controller::API;
910
use File::Basename;
1011
use File::stat;
1112
use Data::Dump qw(dump);
@@ -569,13 +570,52 @@ sub bump : Chained('buildChain') PathPart('bump') {
569570
}
570571

571572

573+
sub buildStepToHash {
574+
my ($buildstep) = @_;
575+
return {
576+
build => $buildstep->get_column('build'),
577+
busy => $buildstep->busy,
578+
drvpath => $buildstep->drvpath,
579+
errormsg => $buildstep->errormsg,
580+
isnondeterministic => $buildstep->isnondeterministic,
581+
machine => $buildstep->machine,
582+
overhead => $buildstep->overhead,
583+
# The propagatedfrom field will hold a Build type if it was propagated, we'd like to display that info, so we
584+
# convert the that record to a hash here and inline it, we already have the data on hand and it saves clients a
585+
# request to obtain the actual reason why something happened.
586+
propagatedfrom => defined($buildstep->propagatedfrom) ? Hydra::Controller::API::buildToHash($buildstep->propagatedfrom) : undef,
587+
starttime => $buildstep->starttime,
588+
status => $buildstep->status,
589+
stepnr => $buildstep->stepnr,
590+
stoptime => $buildstep->stoptime,
591+
system => $buildstep->system,
592+
timesbuilt => $buildstep->timesbuilt,
593+
type => $buildstep->type,
594+
haserrormsg => defined($buildstep->errormsg) && $buildstep->errormsg ne "" ? JSON::MaybeXS::true : JSON::MaybeXS::false
595+
};
596+
}
597+
598+
572599
sub get_info : Chained('buildChain') PathPart('api/get-info') Args(0) {
573600
my ($self, $c) = @_;
574601
my $build = $c->stash->{build};
602+
603+
# Since this is the detailed info of the build, lets start with populating it with
604+
# the info we can obtain form the build.
605+
$c->stash->{json} = Hydra::Controller::API::buildToHash($build);
606+
607+
# Provide the original get-info endpoint attributes.
575608
$c->stash->{json}->{buildId} = $build->id;
576609
$c->stash->{json}->{drvPath} = $build->drvpath;
577610
my $out = getMainOutput($build);
578611
$c->stash->{json}->{outPath} = $out->path if defined $out;
612+
613+
# Finally, provide information about all the buildsteps that made up this build.
614+
my @buildsteps = $build->buildsteps->search({}, {order_by => "stepnr asc"});
615+
my @buildsteplist;
616+
push @buildsteplist, buildStepToHash($_) foreach @buildsteps;
617+
$c->stash->{json}->{steps} = \@buildsteplist;
618+
579619
$c->forward('View::JSON');
580620
}
581621

0 commit comments

Comments
 (0)