2009-02-25 12:03:13 +00:00
|
|
|
|
package Hydra::Helper::CatalystUtils;
|
|
|
|
|
|
2013-02-26 16:56:19 +01:00
|
|
|
|
use utf8;
|
2009-02-25 12:03:13 +00:00
|
|
|
|
use strict;
|
|
|
|
|
use Exporter;
|
2009-03-02 10:23:40 +00:00
|
|
|
|
use Readonly;
|
2011-11-30 15:25:28 +01:00
|
|
|
|
use Nix::Store;
|
2009-03-04 13:08:09 +00:00
|
|
|
|
use Hydra::Helper::Nix;
|
2009-02-25 12:03:13 +00:00
|
|
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
2009-03-02 10:23:40 +00:00
|
|
|
|
our @EXPORT = qw(
|
2013-02-21 13:45:11 +01:00
|
|
|
|
getBuild getPreviousBuild getNextBuild getPreviousSuccessfulBuild
|
2015-04-26 07:37:37 +02:00
|
|
|
|
searchBuildsAndEvalsForJobset
|
2021-04-26 11:28:42 -07:00
|
|
|
|
error notFound gone accessDenied badRequest
|
2017-12-30 08:28:23 -05:00
|
|
|
|
forceLogin requireUser requireProjectOwner requireRestartPrivileges requireAdmin requirePost isAdmin isProjectOwner
|
2019-11-05 19:24:51 +01:00
|
|
|
|
requireBumpPrivileges
|
2019-11-05 19:29:36 +01:00
|
|
|
|
requireCancelBuildPrivileges
|
2009-03-04 10:59:14 +00:00
|
|
|
|
trim
|
2014-11-19 15:22:30 +01:00
|
|
|
|
getLatestFinishedEval getFirstEval
|
2013-03-04 15:25:23 +01:00
|
|
|
|
paramToList
|
|
|
|
|
backToReferer
|
2014-09-25 16:43:17 +02:00
|
|
|
|
$pathCompRE $relPathRE $relNameRE $projectNameRE $jobsetNameRE $jobNameRE $systemRE $userNameRE $inputNameRE
|
2012-03-07 22:20:15 +01:00
|
|
|
|
@buildListColumns
|
2013-06-27 18:08:00 +02:00
|
|
|
|
parseJobsetName
|
|
|
|
|
showJobName
|
|
|
|
|
showStatus
|
2013-10-07 09:44:51 -04:00
|
|
|
|
getResponsibleAuthors
|
2014-11-06 14:31:04 +01:00
|
|
|
|
setCacheHeaders
|
2015-07-10 15:08:34 +02:00
|
|
|
|
approxTableSize
|
2016-03-02 15:08:53 +01:00
|
|
|
|
requireLocalStore
|
2016-03-16 15:19:18 +01:00
|
|
|
|
dbh
|
2009-03-02 10:23:40 +00:00
|
|
|
|
);
|
2009-02-25 12:03:13 +00:00
|
|
|
|
|
|
|
|
|
|
2012-03-07 22:20:15 +01:00
|
|
|
|
# Columns from the Builds table needed to render build lists.
|
2015-10-27 15:37:17 +01:00
|
|
|
|
Readonly our @buildListColumns => ('id', 'finished', 'timestamp', 'stoptime', 'project', 'jobset', 'job', 'nixname', 'system', 'buildstatus', 'releasename');
|
2012-03-07 22:20:15 +01:00
|
|
|
|
|
|
|
|
|
|
2009-02-25 12:03:13 +00:00
|
|
|
|
sub getBuild {
|
|
|
|
|
my ($c, $id) = @_;
|
|
|
|
|
my $build = $c->model('DB::Builds')->find($id);
|
|
|
|
|
return $build;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-06 00:20:06 +01:00
|
|
|
|
|
2010-02-22 13:21:34 +00:00
|
|
|
|
sub getPreviousBuild {
|
2013-06-27 18:08:00 +02:00
|
|
|
|
my ($build) = @_;
|
2010-07-27 11:21:21 +00:00
|
|
|
|
return undef if !defined $build;
|
2020-10-28 13:29:02 +01:00
|
|
|
|
# FIXME: slow
|
2020-05-27 20:09:36 +02:00
|
|
|
|
return $build->jobset->builds->search(
|
2010-02-22 13:21:34 +00:00
|
|
|
|
{ finished => 1
|
|
|
|
|
, system => $build->system
|
2013-01-22 14:41:02 +01:00
|
|
|
|
, 'me.id' => { '<' => $build->id }
|
2020-10-28 13:29:02 +01:00
|
|
|
|
, job => $build->job
|
|
|
|
|
, -not => { buildstatus => { -in => [4, 3]} }
|
2013-06-27 18:08:00 +02:00
|
|
|
|
}, { rows => 1, order_by => "me.id DESC" })->single;
|
2010-02-22 13:21:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-06 00:20:06 +01:00
|
|
|
|
|
2010-07-14 07:31:14 +00:00
|
|
|
|
sub getNextBuild {
|
|
|
|
|
my ($c, $build) = @_;
|
2010-07-27 11:21:21 +00:00
|
|
|
|
return undef if !defined $build;
|
|
|
|
|
|
2010-07-14 07:31:14 +00:00
|
|
|
|
(my $nextBuild) = $c->model('DB::Builds')->search(
|
|
|
|
|
{ finished => 1
|
|
|
|
|
, system => $build->system
|
2021-06-01 11:16:47 -04:00
|
|
|
|
, jobset_id => $build->get_column('jobset_id')
|
2019-08-13 17:42:19 +02:00
|
|
|
|
, job => $build->get_column('job')
|
2013-01-22 14:41:02 +01:00
|
|
|
|
, 'me.id' => { '>' => $build->id }
|
2011-03-14 14:05:32 +00:00
|
|
|
|
}, {rows => 1, order_by => "me.id ASC"});
|
2013-01-22 14:41:02 +01:00
|
|
|
|
|
2010-07-14 07:31:14 +00:00
|
|
|
|
return $nextBuild;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-06 00:20:06 +01:00
|
|
|
|
|
2010-02-22 13:21:34 +00:00
|
|
|
|
sub getPreviousSuccessfulBuild {
|
|
|
|
|
my ($c, $build) = @_;
|
2010-07-27 11:21:21 +00:00
|
|
|
|
return undef if !defined $build;
|
|
|
|
|
|
2012-03-05 21:52:47 +01:00
|
|
|
|
(my $prevBuild) = $c->model('DB::Builds')->search(
|
2010-02-22 13:21:34 +00:00
|
|
|
|
{ finished => 1
|
|
|
|
|
, system => $build->system
|
2021-06-01 11:16:47 -04:00
|
|
|
|
, jobset_id => $build->get_column('jobset_id')
|
2019-08-13 17:42:19 +02:00
|
|
|
|
, job => $build->get_column('job')
|
2010-02-22 13:21:34 +00:00
|
|
|
|
, buildstatus => 0
|
2013-01-22 14:41:02 +01:00
|
|
|
|
, 'me.id' => { '<' => $build->id }
|
2011-03-14 14:05:32 +00:00
|
|
|
|
}, {rows => 1, order_by => "me.id DESC"});
|
2013-01-22 14:41:02 +01:00
|
|
|
|
|
2010-02-22 13:21:34 +00:00
|
|
|
|
return $prevBuild;
|
|
|
|
|
}
|
2009-02-25 12:03:13 +00:00
|
|
|
|
|
2012-03-06 00:20:06 +01:00
|
|
|
|
|
2015-04-26 07:37:37 +02:00
|
|
|
|
sub searchBuildsAndEvalsForJobset {
|
|
|
|
|
my ($jobset, $condition, $maxBuilds) = @_;
|
|
|
|
|
|
|
|
|
|
my @evals = $jobset->jobsetevals->search(
|
|
|
|
|
{ hasnewbuilds => 1},
|
|
|
|
|
{ order_by => "id desc",
|
|
|
|
|
rows => 20
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
my $evals = {};
|
|
|
|
|
my %builds;
|
|
|
|
|
my $nrBuilds = 0;
|
|
|
|
|
|
|
|
|
|
foreach my $eval (@evals) {
|
|
|
|
|
my @allBuilds = $eval->builds->search(
|
|
|
|
|
$condition,
|
|
|
|
|
{ columns => ['id', 'job', 'finished', 'buildstatus'] }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
foreach my $b (@allBuilds) {
|
|
|
|
|
my $jobName = $b->get_column('job');
|
|
|
|
|
|
|
|
|
|
$evals->{$eval->id}->{timestamp} = $eval->timestamp;
|
|
|
|
|
$evals->{$eval->id}->{builds}->{$jobName} = {
|
|
|
|
|
id => $b->id,
|
|
|
|
|
finished => $b->finished,
|
|
|
|
|
buildstatus => $b->buildstatus
|
|
|
|
|
};
|
|
|
|
|
$builds{$jobName} = 1;
|
|
|
|
|
$nrBuilds++;
|
|
|
|
|
}
|
|
|
|
|
last if $maxBuilds && $nrBuilds >= $maxBuilds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ($evals, \%builds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-02-25 12:03:13 +00:00
|
|
|
|
sub error {
|
2013-07-09 12:02:15 +02:00
|
|
|
|
my ($c, $msg, $status) = @_;
|
|
|
|
|
$c->response->status($status) if defined $status;
|
2009-02-25 12:03:13 +00:00
|
|
|
|
$c->error($msg);
|
2009-03-02 16:03:41 +00:00
|
|
|
|
$c->detach; # doesn't return
|
2009-02-25 12:03:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-02-25 14:34:29 +00:00
|
|
|
|
sub notFound {
|
|
|
|
|
my ($c, $msg) = @_;
|
2013-07-09 12:02:15 +02:00
|
|
|
|
error($c, $msg, 404);
|
2009-02-25 14:34:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-02-26 11:38:02 +01:00
|
|
|
|
sub gone {
|
|
|
|
|
my ($c, $msg) = @_;
|
|
|
|
|
error($c, $msg, 410);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-10-14 18:01:04 +02:00
|
|
|
|
sub accessDenied {
|
|
|
|
|
my ($c, $msg) = @_;
|
2013-11-05 11:11:48 +01:00
|
|
|
|
error($c, $msg, 403);
|
2013-10-14 18:01:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 11:28:42 -07:00
|
|
|
|
sub badRequest {
|
|
|
|
|
my ($c, $msg) = @_;
|
|
|
|
|
error($c, $msg, 400);
|
|
|
|
|
}
|
2013-10-14 18:01:04 +02:00
|
|
|
|
|
2013-03-04 15:25:23 +01:00
|
|
|
|
sub backToReferer {
|
|
|
|
|
my ($c) = @_;
|
|
|
|
|
$c->response->redirect($c->session->{referer} || $c->uri_for('/'));
|
|
|
|
|
$c->session->{referer} = undef;
|
|
|
|
|
$c->detach;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-10-14 18:01:04 +02:00
|
|
|
|
sub forceLogin {
|
2009-03-02 16:03:41 +00:00
|
|
|
|
my ($c) = @_;
|
2013-03-04 15:25:23 +01:00
|
|
|
|
$c->session->{referer} = $c->request->uri;
|
2013-11-05 11:11:48 +01:00
|
|
|
|
accessDenied($c, "This page requires you to sign in.");
|
2009-03-02 16:03:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-07 22:20:15 +01:00
|
|
|
|
|
2013-10-14 18:01:04 +02:00
|
|
|
|
sub requireUser {
|
|
|
|
|
my ($c) = @_;
|
|
|
|
|
forceLogin($c) if !$c->user_exists;
|
2009-03-02 16:03:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-06-04 14:43:28 +00:00
|
|
|
|
sub isProjectOwner {
|
|
|
|
|
my ($c, $project) = @_;
|
2013-10-14 18:01:04 +02:00
|
|
|
|
return
|
|
|
|
|
$c->user_exists &&
|
|
|
|
|
(isAdmin($c) ||
|
|
|
|
|
$c->user->username eq $project->owner->username ||
|
|
|
|
|
defined $c->model('DB::ProjectMembers')->find({ project => $project, userName => $c->user->username }));
|
2010-06-04 14:43:28 +00:00
|
|
|
|
}
|
2009-03-02 16:03:41 +00:00
|
|
|
|
|
2019-11-05 19:29:36 +01:00
|
|
|
|
sub hasCancelBuildRole {
|
|
|
|
|
my ($c) = @_;
|
|
|
|
|
return $c->user_exists && $c->check_user_roles('cancel-build');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub mayCancelBuild {
|
|
|
|
|
my ($c, $project) = @_;
|
|
|
|
|
return
|
|
|
|
|
$c->user_exists &&
|
|
|
|
|
(isAdmin($c) ||
|
|
|
|
|
hasCancelBuildRole($c) ||
|
|
|
|
|
isProjectOwner($c, $project));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub requireCancelBuildPrivileges {
|
|
|
|
|
my ($c, $project) = @_;
|
|
|
|
|
requireUser($c);
|
|
|
|
|
accessDenied($c, "Only the project members, administrators, and accounts with cancel-build privileges can perform this operation.")
|
|
|
|
|
unless mayCancelBuild($c, $project);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-05 19:24:51 +01:00
|
|
|
|
sub hasBumpJobsRole {
|
|
|
|
|
my ($c) = @_;
|
|
|
|
|
return $c->user_exists && $c->check_user_roles('bump-to-front');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub mayBumpJobs {
|
|
|
|
|
my ($c, $project) = @_;
|
|
|
|
|
return
|
|
|
|
|
$c->user_exists &&
|
|
|
|
|
(isAdmin($c) ||
|
|
|
|
|
hasBumpJobsRole($c) ||
|
|
|
|
|
isProjectOwner($c, $project));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub requireBumpPrivileges {
|
|
|
|
|
my ($c, $project) = @_;
|
|
|
|
|
requireUser($c);
|
|
|
|
|
accessDenied($c, "Only the project members, administrators, and accounts with bump-to-front privileges can perform this operation.")
|
|
|
|
|
unless mayBumpJobs($c, $project);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-30 08:28:23 -05:00
|
|
|
|
sub hasRestartJobsRole {
|
|
|
|
|
my ($c) = @_;
|
|
|
|
|
return $c->user_exists && $c->check_user_roles('restart-jobs');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub mayRestartJobs {
|
|
|
|
|
my ($c, $project) = @_;
|
|
|
|
|
return
|
|
|
|
|
$c->user_exists &&
|
|
|
|
|
(isAdmin($c) ||
|
|
|
|
|
hasRestartJobsRole($c) ||
|
|
|
|
|
isProjectOwner($c, $project));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub requireRestartPrivileges {
|
|
|
|
|
my ($c, $project) = @_;
|
|
|
|
|
requireUser($c);
|
|
|
|
|
accessDenied($c, "Only the project members, administrators, and accounts with restart-jobs privileges can perform this operation.")
|
|
|
|
|
unless mayRestartJobs($c, $project);
|
|
|
|
|
}
|
2012-03-07 22:20:15 +01:00
|
|
|
|
|
2009-03-02 16:03:41 +00:00
|
|
|
|
sub requireProjectOwner {
|
|
|
|
|
my ($c, $project) = @_;
|
2013-10-14 18:01:04 +02:00
|
|
|
|
requireUser($c);
|
|
|
|
|
accessDenied($c, "Only the project members or administrators can perform this operation.")
|
2010-06-04 14:43:28 +00:00
|
|
|
|
unless isProjectOwner($c, $project);
|
2009-03-02 16:03:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-06-04 14:43:28 +00:00
|
|
|
|
sub isAdmin {
|
|
|
|
|
my ($c) = @_;
|
|
|
|
|
return $c->user_exists && $c->check_user_roles('admin');
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-04 10:59:14 +00:00
|
|
|
|
sub requireAdmin {
|
|
|
|
|
my ($c) = @_;
|
2013-10-14 18:01:04 +02:00
|
|
|
|
requireUser($c);
|
|
|
|
|
accessDenied($c, "Only administrators can perform this operation.")
|
2010-06-04 14:43:28 +00:00
|
|
|
|
unless isAdmin($c);
|
2009-03-04 10:59:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-04-02 16:15:57 +00:00
|
|
|
|
sub requirePost {
|
|
|
|
|
my ($c) = @_;
|
|
|
|
|
error($c, "Request must be POSTed.") if $c->request->method ne "POST";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-03-04 10:59:14 +00:00
|
|
|
|
sub trim {
|
|
|
|
|
my $s = shift;
|
|
|
|
|
$s =~ s/^\s+|\s+$//g;
|
|
|
|
|
return $s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-04-03 11:28:59 +02:00
|
|
|
|
sub getLatestFinishedEval {
|
2013-11-11 21:17:22 +00:00
|
|
|
|
my ($jobset) = @_;
|
2012-04-03 11:28:59 +02:00
|
|
|
|
my ($eval) = $jobset->jobsetevals->search(
|
|
|
|
|
{ hasnewbuilds => 1 },
|
|
|
|
|
{ order_by => "id DESC", rows => 1
|
|
|
|
|
, where => \ "not exists (select 1 from JobsetEvalMembers m join Builds b on m.build = b.id where m.eval = me.id and b.finished = 0)"
|
|
|
|
|
});
|
|
|
|
|
return $eval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-11-19 15:22:30 +01:00
|
|
|
|
sub getFirstEval {
|
|
|
|
|
my ($build) = @_;
|
|
|
|
|
return $build->jobsetevals->search(
|
|
|
|
|
{ hasnewbuilds => 1},
|
|
|
|
|
{ rows => 1, order_by => ["id"] })->single;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-03-04 15:25:23 +01:00
|
|
|
|
# Catalyst request parameters can be an array or a scalar or
|
|
|
|
|
# undefined, making them annoying to handle. So this utility function
|
|
|
|
|
# always returns a request parameter as a list.
|
|
|
|
|
sub paramToList {
|
|
|
|
|
my ($c, $name) = @_;
|
2013-06-17 12:34:21 -04:00
|
|
|
|
my $x = $c->stash->{params}->{$name};
|
2013-03-04 15:25:23 +01:00
|
|
|
|
return () unless defined $x;
|
|
|
|
|
return @$x if ref($x) eq 'ARRAY';
|
|
|
|
|
return ($x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-03-02 10:23:40 +00:00
|
|
|
|
# Security checking of filenames.
|
2013-05-27 13:01:23 +02:00
|
|
|
|
Readonly our $pathCompRE => "(?:[A-Za-z0-9-\+\._\$][A-Za-z0-9-\+\._\$:]*)";
|
2012-04-17 08:53:00 +00:00
|
|
|
|
Readonly our $relPathRE => "(?:$pathCompRE(?:/$pathCompRE)*)";
|
2013-06-18 16:00:24 +02:00
|
|
|
|
Readonly our $relNameRE => "(?:[A-Za-z0-9-_][A-Za-z0-9-\._]*)";
|
2013-01-11 12:16:21 +01:00
|
|
|
|
Readonly our $attrNameRE => "(?:[A-Za-z_][A-Za-z0-9-_]*)";
|
2012-04-17 08:53:00 +00:00
|
|
|
|
Readonly our $projectNameRE => "(?:[A-Za-z_][A-Za-z0-9-_]*)";
|
2013-09-24 15:15:44 +02:00
|
|
|
|
Readonly our $jobsetNameRE => "(?:[A-Za-z_][A-Za-z0-9-_\.]*)";
|
2012-04-17 08:53:00 +00:00
|
|
|
|
Readonly our $jobNameRE => "(?:$attrNameRE(?:\\.$attrNameRE)*)";
|
|
|
|
|
Readonly our $systemRE => "(?:[a-z0-9_]+-[a-z0-9_]+)";
|
2013-02-27 18:33:47 +01:00
|
|
|
|
Readonly our $userNameRE => "(?:[a-z][a-z0-9_\.]*)";
|
2014-09-25 16:43:17 +02:00
|
|
|
|
Readonly our $inputNameRE => "(?:[A-Za-z_][A-Za-z0-9-_]*)";
|
2009-03-02 10:23:40 +00:00
|
|
|
|
|
|
|
|
|
|
2013-02-25 21:04:10 +01:00
|
|
|
|
sub parseJobsetName {
|
|
|
|
|
my ($s) = @_;
|
Enable declarative projects.
This allows fully declarative project specifications. This is best
illustrated by example:
* I create a new project, setting the declarative spec file to
"spec.json" and the declarative input to a git repo pointing
at git://github.com/shlevy/declarative-hydra-example.git
* hydra creates a special ".jobsets" jobset alongside the project
* Just before evaluating the ".jobsets" jobset, hydra fetches
declarative-hydra-example.git, reads spec.json as a jobset spec,
and updates the jobset's configuration accordingly:
{
"enabled": 1,
"hidden": false,
"description": "Jobsets",
"nixexprinput": "src",
"nixexprpath": "default.nix",
"checkinterval": 300,
"schedulingshares": 100,
"enableemail": false,
"emailoverride": "",
"keepnr": 3,
"inputs": {
"src": { "type": "git", "value": "git://github.com/shlevy/declarative-hydra-example.git", "emailresponsible": false },
"nixpkgs": { "type": "git", "value": "git://github.com/NixOS/nixpkgs.git release-16.03", "emailresponsible": false }
}
}
* When the "jobsets" job of the ".jobsets" jobset completes, hydra
reads its output as a JSON representation of a dictionary of
jobset specs and creates a jobset named "master" configured
accordingly (In this example, this is the same configuration as
.jobsets itself, except using release.nix instead of default.nix):
{
"enabled": 1,
"hidden": false,
"description": "js",
"nixexprinput": "src",
"nixexprpath": "release.nix",
"checkinterval": 300,
"schedulingshares": 100,
"enableemail": false,
"emailoverride": "",
"keepnr": 3,
"inputs": {
"src": { "type": "git", "value": "git://github.com/shlevy/declarative-hydra-example.git", "emailresponsible": false },
"nixpkgs": { "type": "git", "value": "git://github.com/NixOS/nixpkgs.git release-16.03", "emailresponsible": false }
}
}
2016-03-11 18:14:58 -05:00
|
|
|
|
$s =~ /^($projectNameRE):(\.?$jobsetNameRE)$/ or die "invalid jobset specifier ‘$s’\n";
|
2013-02-25 21:04:10 +01:00
|
|
|
|
return ($1, $2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-06-27 18:08:00 +02:00
|
|
|
|
sub showJobName {
|
|
|
|
|
my ($build) = @_;
|
2019-08-13 17:42:19 +02:00
|
|
|
|
return $build->get_column('project') . ":" . $build->get_column('jobset') . ":" . $build->get_column('job');
|
2013-06-27 18:08:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub showStatus {
|
|
|
|
|
my ($build) = @_;
|
|
|
|
|
|
|
|
|
|
my $status = "Failed";
|
2014-12-12 11:27:17 +01:00
|
|
|
|
if ($build->buildstatus == 0) { $status = "Success"; }
|
|
|
|
|
elsif ($build->buildstatus == 1) { $status = "Failed"; }
|
|
|
|
|
elsif ($build->buildstatus == 2) { $status = "Dependency failed"; }
|
|
|
|
|
elsif ($build->buildstatus == 4) { $status = "Cancelled"; }
|
|
|
|
|
elsif ($build->buildstatus == 6) { $status = "Failed with output"; }
|
|
|
|
|
|
|
|
|
|
return $status;
|
2013-06-27 18:08:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-10-07 09:44:51 -04:00
|
|
|
|
# Determine who broke/fixed the build.
|
|
|
|
|
sub getResponsibleAuthors {
|
|
|
|
|
my ($build, $plugins) = @_;
|
|
|
|
|
|
|
|
|
|
my $prevBuild = getPreviousBuild($build);
|
2014-11-19 15:22:30 +01:00
|
|
|
|
return ({}, 0, []) unless $prevBuild;
|
2013-10-07 09:44:51 -04:00
|
|
|
|
|
|
|
|
|
my $nrCommits = 0;
|
|
|
|
|
my %authors;
|
2013-10-08 14:47:24 -04:00
|
|
|
|
my @emailable_authors;
|
2013-10-07 09:44:51 -04:00
|
|
|
|
|
2014-11-19 15:22:30 +01:00
|
|
|
|
my $prevEval = getFirstEval($prevBuild);
|
|
|
|
|
my $eval = getFirstEval($build);
|
|
|
|
|
|
|
|
|
|
foreach my $curInput ($eval->jobsetevalinputs) {
|
|
|
|
|
next unless ($curInput->type eq "git" || $curInput->type eq "hg");
|
|
|
|
|
my $prevInput = $prevEval->jobsetevalinputs->find({ name => $curInput->name });
|
|
|
|
|
next unless defined $prevInput;
|
|
|
|
|
|
|
|
|
|
next if $curInput->type ne $prevInput->type;
|
|
|
|
|
next if $curInput->uri ne $prevInput->uri;
|
|
|
|
|
next if $curInput->revision eq $prevInput->revision;
|
|
|
|
|
|
|
|
|
|
my @commits;
|
|
|
|
|
foreach my $plugin (@{$plugins}) {
|
|
|
|
|
push @commits, @{$plugin->getCommits($curInput->type, $curInput->uri, $prevInput->revision, $curInput->revision)};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach my $commit (@commits) {
|
|
|
|
|
#print STDERR "$commit->{revision} by $commit->{author}\n";
|
|
|
|
|
$authors{$commit->{author}} = $commit->{email};
|
|
|
|
|
my $inputSpec = $build->jobset->jobsetinputs->find({ name => $curInput->name });
|
|
|
|
|
push @emailable_authors, $commit->{email} if $inputSpec && $inputSpec->emailresponsible;
|
|
|
|
|
$nrCommits++;
|
2013-10-07 09:44:51 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-08 14:47:24 -04:00
|
|
|
|
return (\%authors, $nrCommits, \@emailable_authors);
|
2013-10-07 09:44:51 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-11-06 14:31:04 +01:00
|
|
|
|
# Set HTTP headers for the Nix binary cache.
|
|
|
|
|
sub setCacheHeaders {
|
|
|
|
|
my ($c, $expiration) = @_;
|
|
|
|
|
$c->response->headers->expires(time + $expiration);
|
|
|
|
|
delete $c->response->cookies->{hydra_session};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-07-10 15:08:34 +02:00
|
|
|
|
sub approxTableSize {
|
|
|
|
|
my ($c, $name) = @_;
|
|
|
|
|
return $c->model('DB')->schema->storage->dbh->selectrow_hashref(
|
|
|
|
|
"select reltuples::int from pg_class where relname = lower(?)", { }, $name)->{"reltuples"};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-03-02 15:08:53 +01:00
|
|
|
|
sub requireLocalStore {
|
|
|
|
|
my ($c) = @_;
|
2017-10-18 12:23:07 +02:00
|
|
|
|
notFound($c, "Nix channels are not supported by this Hydra server.") if !Hydra::Helper::Nix::isLocalStore();
|
2016-03-02 15:08:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-03-16 15:19:18 +01:00
|
|
|
|
sub dbh {
|
|
|
|
|
my ($c) = @_;
|
|
|
|
|
return $c->model('DB')->schema->storage->dbh;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-02-25 12:03:13 +00:00
|
|
|
|
1;
|