This commit is contained in:
Eelco Dolstra 2008-11-18 12:48:58 +00:00
parent 6aa0ddda51
commit 9f1f939226
4 changed files with 36 additions and 28 deletions

View file

@ -31,6 +31,13 @@ sub error {
} }
sub trim {
my $s = shift;
$s =~ s/^\s+|\s+$//g;
return $s;
}
sub getBuild { sub getBuild {
my ($c, $id) = @_; my ($c, $id) = @_;
(my $build) = $c->model('DB::Builds')->search({ id => $id }); (my $build) = $c->model('DB::Builds')->search({ id => $id });
@ -57,16 +64,16 @@ sub index :Path :Args(0) {
sub updateProject { sub updateProject {
my ($c, $project) = @_; my ($c, $project) = @_;
my $projectName = $c->request->params->{name}; my $projectName = trim $c->request->params->{name};
die "Invalid project name: $projectName" unless $projectName =~ /^[[:alpha:]]\w*$/; die "Invalid project name: $projectName" unless $projectName =~ /^[[:alpha:]]\w*$/;
my $displayName = $c->request->params->{displayname}; my $displayName = trim $c->request->params->{displayname};
die "Invalid display name: $displayName" unless $displayName =~ /^\w.*\w$/; die "Invalid display name: $displayName" if $displayName eq "";
$project->name($projectName); $project->name($projectName);
$project->displayname($displayName); $project->displayname($displayName);
$project->description($c->request->params->{description}); $project->description(trim $c->request->params->{description});
$project->enabled($c->request->params->{enabled} eq "1" ? 1 : 0); $project->enabled(trim($c->request->params->{enabled}) eq "1" ? 1 : 0);
$project->update; $project->update;
@ -77,14 +84,14 @@ sub updateProject {
my $baseName = $1; my $baseName = $1;
next if $baseName eq "template"; next if $baseName eq "template";
my $jobsetName = $c->request->params->{"jobset-$baseName-name"}; my $jobsetName = trim $c->request->params->{"jobset-$baseName-name"};
die "Invalid jobset name: $jobsetName" unless $jobsetName =~ /^[[:alpha:]]\w*$/; die "Invalid jobset name: $jobsetName" unless $jobsetName =~ /^[[:alpha:]]\w*$/;
# The Nix expression path must be relative and can't contain ".." elements. # The Nix expression path must be relative and can't contain ".." elements.
my $nixExprPath = $c->request->params->{"jobset-$baseName-nixexprpath"}; my $nixExprPath = trim $c->request->params->{"jobset-$baseName-nixexprpath"};
die "Invalid Nix expression path: $nixExprPath" if $nixExprPath !~ /^$relPathRE$/; die "Invalid Nix expression path: $nixExprPath" if $nixExprPath !~ /^$relPathRE$/;
my $nixExprInput = $c->request->params->{"jobset-$baseName-nixexprinput"}; my $nixExprInput = trim $c->request->params->{"jobset-$baseName-nixexprinput"};
die "Invalid Nix expression input name: $nixExprInput" unless $nixExprInput =~ /^\w+$/; die "Invalid Nix expression input name: $nixExprInput" unless $nixExprInput =~ /^\w+$/;
$jobsetNames{$jobsetName} = 1; $jobsetNames{$jobsetName} = 1;
@ -94,7 +101,7 @@ sub updateProject {
if ($baseName =~ /^\d+$/) { # numeric base name is auto-generated, i.e. a new entry if ($baseName =~ /^\d+$/) { # numeric base name is auto-generated, i.e. a new entry
$jobset = $project->jobsets->create( $jobset = $project->jobsets->create(
{ name => $jobsetName { name => $jobsetName
, description => $c->request->params->{"jobset-$baseName-description"} , description => trim $c->request->params->{"jobset-$baseName-description"}
, nixexprpath => $nixExprPath , nixexprpath => $nixExprPath
, nixexprinput => $nixExprInput , nixexprinput => $nixExprInput
}); });
@ -102,7 +109,7 @@ sub updateProject {
$jobset = ($project->jobsets->search({name => $baseName}))[0]; $jobset = ($project->jobsets->search({name => $baseName}))[0];
die unless defined $jobset; die unless defined $jobset;
$jobset->name($jobsetName); $jobset->name($jobsetName);
$jobset->description($c->request->params->{"jobset-$baseName-description"}); $jobset->description(trim $c->request->params->{"jobset-$baseName-description"});
$jobset->nixexprpath($nixExprPath); $jobset->nixexprpath($nixExprPath);
$jobset->nixexprinput($nixExprInput); $jobset->nixexprinput($nixExprInput);
$jobset->update; $jobset->update;
@ -117,10 +124,10 @@ sub updateProject {
next if $baseName2 eq "template"; next if $baseName2 eq "template";
print STDERR "GOT INPUT: $baseName2\n"; print STDERR "GOT INPUT: $baseName2\n";
my $inputName = $c->request->params->{"jobset-$baseName-input-$baseName2-name"}; my $inputName = trim $c->request->params->{"jobset-$baseName-input-$baseName2-name"};
die "Invalid input name: $inputName" unless $inputName =~ /^[[:alpha:]]\w*$/; die "Invalid input name: $inputName" unless $inputName =~ /^[[:alpha:]]\w*$/;
my $inputType = $c->request->params->{"jobset-$baseName-input-$baseName2-type"}; my $inputType = trim $c->request->params->{"jobset-$baseName-input-$baseName2-type"};
die "Invalid input type: $inputType" unless die "Invalid input type: $inputType" unless
$inputType eq "svn" || $inputType eq "cvs" || $inputType eq "tarball" || $inputType eq "svn" || $inputType eq "cvs" || $inputType eq "tarball" ||
$inputType eq "string" || $inputType eq "path"; $inputType eq "string" || $inputType eq "path";
@ -150,7 +157,7 @@ sub updateProject {
my $altnr = 0; my $altnr = 0;
foreach my $value (@{$values}) { foreach my $value (@{$values}) {
print STDERR "VALUE: $value\n"; print STDERR "VALUE: $value\n";
$input->jobsetinputalts->create({altnr => $altnr++, value => $value}); $input->jobsetinputalts->create({altnr => $altnr++, value => trim $value});
} }
} }
@ -174,7 +181,7 @@ sub project :Local {
$c->stash->{template} = 'project.tt'; $c->stash->{template} = 'project.tt';
(my $project) = $c->model('DB::Projects')->search({ name => $projectName }); (my $project) = $c->model('DB::Projects')->search({ name => $projectName });
return error($c, "Project <tt>$projectName</tt> doesn't exist.") if !defined $project; return error($c, "Project $projectName doesn't exist.") if !defined $project;
my $isPosted = $c->request->method eq "POST"; my $isPosted = $c->request->method eq "POST";
@ -186,7 +193,7 @@ sub project :Local {
$c->model('DB')->schema->txn_do(sub { $c->model('DB')->schema->txn_do(sub {
updateProject($c, $project); updateProject($c, $project);
}); });
return $c->res->redirect($c->uri_for("/project", $c->request->params->{name})); return $c->res->redirect($c->uri_for("/project", trim $c->request->params->{name}));
} elsif ($subcommand eq "delete" && $isPosted) { } elsif ($subcommand eq "delete" && $isPosted) {
$c->model('DB')->schema->txn_do(sub { $c->model('DB')->schema->txn_do(sub {
$project->delete; $project->delete;
@ -255,7 +262,7 @@ sub job :Local {
$c->stash->{template} = 'job.tt'; $c->stash->{template} = 'job.tt';
(my $project) = $c->model('DB::Projects')->search({ name => $projectName }); (my $project) = $c->model('DB::Projects')->search({ name => $projectName });
return error($c, "Project <tt>$projectName</tt> doesn't exist.") if !defined $project; return error($c, "Project $projectName doesn't exist.") if !defined $project;
$c->stash->{curProject} = $project; $c->stash->{curProject} = $project;
$c->stash->{jobName} = $jobName; $c->stash->{jobName} = $jobName;
@ -299,7 +306,7 @@ sub log :Local {
return error($c, "Build with ID $id doesn't exist.") if !defined $build; return error($c, "Build with ID $id doesn't exist.") if !defined $build;
my $log = $build->buildlogs->find({logphase => $logPhase}); my $log = $build->buildlogs->find({logphase => $logPhase});
return error($c, "Build $id doesn't have a log phase named <tt>$logPhase</tt>.") if !defined $log; return error($c, "Build $id doesn't have a log phase named $logPhase.") if !defined $log;
$c->stash->{template} = 'log.tt'; $c->stash->{template} = 'log.tt';
$c->stash->{id} = $id; $c->stash->{id} = $id;

View file

@ -1,4 +1,5 @@
[% USE date -%] [% USE date -%]
[% USE HTML -%]
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
[% BLOCK makeLink %] [% BLOCK makeLink %]
@ -17,12 +18,9 @@
<script type="text/javascript" src="/static/js/jquery-pack.js"></script> <script type="text/javascript" src="/static/js/jquery-pack.js"></script>
<script type="text/javascript" src="/static/js/tablesorter/jquery.tablesorter.js"></script> <script type="text/javascript" src="/static/js/tablesorter/jquery.tablesorter.js"></script>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready( $(document).ready(function() {
function() $("table.tablesorter").tablesorter();
{ });
$("table.tablesorter").tablesorter();
}
);
</script> </script>
</head> </head>
@ -47,7 +45,7 @@
<ul class="submenu"> <ul class="submenu">
[% FOREACH project IN projects %] [% FOREACH project IN projects %]
<li [% IF curUri == c.uri_for('/project' project.name) %]class="active"[% END %]> <li [% IF curUri == c.uri_for('/project' project.name) %]class="active"[% END %]>
<div class="title"><a href="[% c.uri_for('/project' project.name) %]">[% project.displayname %]</a></div> <div class="title"><a href="[% c.uri_for('/project' project.name) %]">[% HTML.escape(project.displayname) %]</a></div>
[% IF curProject.name == project.name %] [% IF curProject.name == project.name %]
<ul class="subsubmenu"> <ul class="subsubmenu">
[% INCLUDE makeLink uri = c.uri_for('/project' project.name 'edit') title = "Edit" %] [% INCLUDE makeLink uri = c.uri_for('/project' project.name 'edit') title = "Edit" %]

View file

@ -261,12 +261,15 @@ sub checkJobSet {
sub checkJobs { sub checkJobs {
foreach my $project ($db->resultset('Projects')->all) { foreach my $project ($db->resultset('Projects')->search({enabled => 1})) {
print "PROJECT ", $project->name, "\n"; print "PROJECT ", $project->name, "\n";
foreach my $jobset ($project->jobsets->all) { foreach my $jobset ($project->jobsets->all) {
print " JOBSET ", $jobset->name, "\n"; print " JOBSET ", $jobset->name, "\n";
checkJobSet($project, $jobset); eval {
} checkJobSet($project, $jobset);
};
warn $@ if $@;
}
} }
} }