« blib/lib/Ukigumo/Server/Command/Branch.pm
↑ Summary
blib/lib/Ukigumo/Server/Web/ViewFunctions.pm »
| 1 | package Ukigumo::Server::Web::Dispatcher; | ||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use 5.010001; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 1 | ▶ | use Amon2::Web::Dispatcher::Lite; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 1 | ▶ | use URI::Escape qw(uri_unescape uri_escape); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 1 | ▶ | use Ukigumo::Server::Command::Report; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 1 | ▶ | use Ukigumo::Server::Command::Branch; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 1 | ▶ | use Data::Validator; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 1 | ▶ | use File::Spec; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 1 | ▶ | use Ukigumo::Server::Util; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 1 | ▶ | use JSON qw(encode_json); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 1 | ▶ | use Text::Xslate qw(mark_raw); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | |||||||||||||
| 15 | any '/' => sub { | ||||||||||||
| 16 | 0 | ▶ | my ($c) = @_; | ||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||
| 17 | |||||||||||||
| 18 | 0 | my $project = $c->req->param('project'); | |||||||||||
| 19 | 0 | ▶ | if ($project) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 20 | 0 | return $c->redirect('/project/' . uri_escape($project)); | |||||||||||
| 21 | } | ||||||||||||
| 22 | 0 | my $project_src = Ukigumo::Server::Command::Branch->list(); | |||||||||||
| 23 | 0 | my %projects = (); | |||||||||||
| 24 | 0 | for my $project (@$project_src) { | |||||||||||
| 25 | 0 | push @{$projects{$project->{project}}}, $project; | |||||||||||
| 26 | } | ||||||||||||
| 27 | |||||||||||||
| 28 | 0 | $c->render( 'index.tx', | |||||||||||
| 29 | { | ||||||||||||
| 30 | now => time(), | ||||||||||||
| 31 | projects => \%projects, | ||||||||||||
| 32 | } | ||||||||||||
| 33 | ); | ||||||||||||
| 34 | 1 | }; | |||||||||||
| 35 | |||||||||||||
| 36 | # CruiseControl format XML http://cruisecontrol.sourceforge.net/ | ||||||||||||
| 37 | get '/cc.xml' => sub { | ||||||||||||
| 38 | 0 | ▶ | my ($c) = @_; | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 39 | |||||||||||||
| 40 | 0 | my $project_src = Ukigumo::Server::Command::Branch->list(); | |||||||||||
| 41 | 0 | my %projects = (); | |||||||||||
| 42 | 0 | for my $project (@$project_src) { | |||||||||||
| 43 | 0 | push @{$projects{$project->{project}}}, $project; | |||||||||||
| 44 | } | ||||||||||||
| 45 | |||||||||||||
| 46 | 0 | my $res = $c->render( 'cc.xml.tx', | |||||||||||
| 47 | { | ||||||||||||
| 48 | now => time(), | ||||||||||||
| 49 | projects => \%projects, | ||||||||||||
| 50 | } | ||||||||||||
| 51 | ); | ||||||||||||
| 52 | 0 | $res->content_type( 'application/xml' ); | |||||||||||
| 53 | 0 | $res; | |||||||||||
| 54 | 1 | }; | |||||||||||
| 55 | |||||||||||||
| 56 | get '/rss.xml' => sub { | ||||||||||||
| 57 | 0 | ▶ | my ($c, $args) = @_; | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 58 | |||||||||||||
| 59 | 0 | my $limit = 50; | |||||||||||
| 60 | |||||||||||||
| 61 | 0 | my ($reports, $pager) = Ukigumo::Server::Command::Report->recent_list( | |||||||||||
| 62 | limit => $limit, | ||||||||||||
| 63 | ); | ||||||||||||
| 64 | 0 | for my $report (@{$reports}) { | |||||||||||
| 65 | 0 | $report->{body} = Ukigumo::Server::Command::Report->find( report_id => $report->{report_id} )->{body}; | |||||||||||
| 66 | } | ||||||||||||
| 67 | 0 | my $res = $c->render( | |||||||||||
| 68 | 'rss.xml.tx' => { | ||||||||||||
| 69 | reports => $reports, | ||||||||||||
| 70 | now => time(), | ||||||||||||
| 71 | base_uri => $c->req->base, | ||||||||||||
| 72 | } | ||||||||||||
| 73 | ); | ||||||||||||
| 74 | 0 | $res->content_type( 'application/xml' ); | |||||||||||
| 75 | 0 | $res; | |||||||||||
| 76 | 1 | }; | |||||||||||
| 77 | |||||||||||||
| 78 | get '/recent' => sub { | ||||||||||||
| 79 | 0 | ▶ | my ($c, $args) = @_; | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 80 | |||||||||||||
| 81 | 0 | ▶ | my $page = $c->req->param('page') || 1; | ||||||||||
|
Condition0%0/2
$c->req->param('page') || 1
MC/DC0%0/1
$c->req->param('page') || 1
$c->req->param('page')
Truth table0%0/2
A
A= $c->req->param('page')
| |||||||||||||
| 82 | 0 | my $limit = 50; | |||||||||||
| 83 | |||||||||||||
| 84 | 0 | my ($reports, $pager) = Ukigumo::Server::Command::Report->recent_list( | |||||||||||
| 85 | page => $page, | ||||||||||||
| 86 | limit => $limit, | ||||||||||||
| 87 | ); | ||||||||||||
| 88 | 0 | return $c->render( | |||||||||||
| 89 | 'recent.tx' => { | ||||||||||||
| 90 | reports => $reports, | ||||||||||||
| 91 | pager => $pager, | ||||||||||||
| 92 | now => time(), | ||||||||||||
| 93 | } | ||||||||||||
| 94 | ); | ||||||||||||
| 95 | 1 | }; | |||||||||||
| 96 | |||||||||||||
| 97 | get '/failure' => sub { | ||||||||||||
| 98 | 0 | ▶ | my ($c, $args) = @_; | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 99 | |||||||||||||
| 100 | 0 | my $project_src = Ukigumo::Server::Command::Branch->list( | |||||||||||
| 101 | status => [2, 3], | ||||||||||||
| 102 | ); | ||||||||||||
| 103 | 0 | my %projects = (); | |||||||||||
| 104 | 0 | for my $project (@$project_src) { | |||||||||||
| 105 | 0 | push @{$projects{$project->{project}}}, $project; | |||||||||||
| 106 | } | ||||||||||||
| 107 | |||||||||||||
| 108 | 0 | return $c->render( | |||||||||||
| 109 | 'index.tx' => { | ||||||||||||
| 110 | projects => \%projects, | ||||||||||||
| 111 | now => time(), | ||||||||||||
| 112 | } | ||||||||||||
| 113 | ); | ||||||||||||
| 114 | 1 | }; | |||||||||||
| 115 | |||||||||||||
| 116 | get '/all_failure' => sub { | ||||||||||||
| 117 | 0 | ▶ | my ($c, $args) = @_; | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 118 | |||||||||||||
| 119 | 0 | ▶ | my $page = $c->req->param('page') || 1; | ||||||||||
|
Condition0%0/2
$c->req->param('page') || 1
MC/DC0%0/1
$c->req->param('page') || 1
$c->req->param('page')
Truth table0%0/2
A
A= $c->req->param('page')
| |||||||||||||
| 120 | 0 | my $limit = 50; | |||||||||||
| 121 | |||||||||||||
| 122 | 0 | my ($reports, $pager) = Ukigumo::Server::Command::Report->failure_list( | |||||||||||
| 123 | page => $page, | ||||||||||||
| 124 | limit => $limit, | ||||||||||||
| 125 | ); | ||||||||||||
| 126 | |||||||||||||
| 127 | 0 | return $c->render( | |||||||||||
| 128 | 'recent.tx' => { | ||||||||||||
| 129 | reports => $reports, | ||||||||||||
| 130 | pager => $pager, | ||||||||||||
| 131 | now => time(), | ||||||||||||
| 132 | } | ||||||||||||
| 133 | ); | ||||||||||||
| 134 | 1 | }; | |||||||||||
| 135 | |||||||||||||
| 136 | get '/project/{project}' => sub { | ||||||||||||
| 137 | 0 | ▶ | my ($c, $args) = @_; | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 138 | |||||||||||||
| 139 | 0 | ▶ | my $project = $args->{project} || die; | ||||||||||
|
Condition0%0/2
$args->{'project'} || die()
MC/DC0%0/1
$args->{'project'} || die()
$args->{'project'}
Truth table0%0/2
A
A= $args->{'project'}
| |||||||||||||
| 140 | 0 | my $project_src = Ukigumo::Server::Command::Branch->list( | |||||||||||
| 141 | project => $project, | ||||||||||||
| 142 | ); | ||||||||||||
| 143 | |||||||||||||
| 144 | 0 | $c->render( | |||||||||||
| 145 | 'project/index.tx', | ||||||||||||
| 146 | { | ||||||||||||
| 147 | now => time(), | ||||||||||||
| 148 | project_name => $project, | ||||||||||||
| 149 | projects => $project_src, | ||||||||||||
| 150 | } | ||||||||||||
| 151 | ); | ||||||||||||
| 152 | 1 | }; | |||||||||||
| 153 | |||||||||||||
| 154 | get '/project/{project}/{branch:[A-Za-z0-9/_\-\.]+}' => sub { | ||||||||||||
| 155 | 0 | ▶ | my ($c, $args) = @_; | ||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||
| 156 | 0 | my $project = $args->{project}; | |||||||||||
| 157 | 0 | my $branch = $args->{branch}; | |||||||||||
| 158 | 0 | ▶ | my $page = $c->req->param('page') || 1; | ||||||||||
|
Condition0%0/2
$c->req->param('page') || 1
MC/DC0%0/1
$c->req->param('page') || 1
$c->req->param('page')
Truth table0%0/2
A
A= $c->req->param('page')
| |||||||||||||
| 159 | 0 | my $limit = 50; | |||||||||||
| 160 | |||||||||||||
| 161 | my $branch_id = Ukigumo::Server::Command::Branch->find( | ||||||||||||
| 162 | project => $args->{project}, | ||||||||||||
| 163 | branch => $args->{branch}, | ||||||||||||
| 164 | 0 | ); | |||||||||||
| 165 | 0 | ▶ | return $c->res_404() unless $branch_id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 166 | |||||||||||||
| 167 | 0 | my ($reports, $pager) = Ukigumo::Server::Command::Report->list( | |||||||||||
| 168 | branch_id => $branch_id, | ||||||||||||
| 169 | page => $page, | ||||||||||||
| 170 | limit => $limit, | ||||||||||||
| 171 | ); | ||||||||||||
| 172 | 0 | my $reports_json = encode_json($reports); | |||||||||||
| 173 | |||||||||||||
| 174 | 0 | return $c->render( | |||||||||||
| 175 | 'report_list.tx' => { | ||||||||||||
| 176 | project => $project, | ||||||||||||
| 177 | branch => $branch, | ||||||||||||
| 178 | branch_id => $branch_id, | ||||||||||||
| 179 | reports => $reports, | ||||||||||||
| 180 | reports_json => mark_raw("$reports_json"), | ||||||||||||
| 181 | pager => $pager, | ||||||||||||
| 182 | now => time(), | ||||||||||||
| 183 | } | ||||||||||||
| 184 | ); | ||||||||||||
| 185 | 1 | }; | |||||||||||
| 186 | |||||||||||||
| 187 | get '/branch/delete' => sub { | ||||||||||||
| 188 | 0 | ▶ | my ($c, $args) = @_; | ||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||
| 189 | |||||||||||||
| 190 | 0 | ▶ | my $branch_id = $c->req->param('branch_id') || die; | ||||||||||
|
Condition0%0/2
$c->req->param('branch_id') || die()
MC/DC0%0/1
$c->req->param('branch_id') || die()
$c->req->param('branch_id')
Truth table0%0/2
A
A= $c->req->param('branch_id')
| |||||||||||||
| 191 | 0 | ▶ | my $branch = Ukigumo::Server::Command::Branch->lookup( | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 192 | branch_id => $branch_id, | ||||||||||||
| 193 | ) or die "Unknown branch: $branch_id"; | ||||||||||||
| 194 | 0 | return $c->render( | |||||||||||
| 195 | 'branch_delete.tx' => { | ||||||||||||
| 196 | branch => $branch, | ||||||||||||
| 197 | } | ||||||||||||
| 198 | ); | ||||||||||||
| 199 | 1 | }; | |||||||||||
| 200 | post '/branch/delete' => sub { | ||||||||||||
| 201 | 0 | ▶ | my ($c, $args) = @_; | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 202 | |||||||||||||
| 203 | 0 | ▶ | my $branch_id = $c->req->param('branch_id') || die; | ||||||||||
|
Condition0%0/2
$c->req->param('branch_id') || die()
MC/DC0%0/1
$c->req->param('branch_id') || die()
$c->req->param('branch_id')
Truth table0%0/2
A
A= $c->req->param('branch_id')
| |||||||||||||
| 204 | 0 | Ukigumo::Server::Command::Branch->delete( | |||||||||||
| 205 | branch_id => $branch_id, | ||||||||||||
| 206 | ); | ||||||||||||
| 207 | 0 | return $c->redirect('/'); | |||||||||||
| 208 | 1 | }; | |||||||||||
| 209 | |||||||||||||
| 210 | get '/report/{report_id:\d+}' => sub { | ||||||||||||
| 211 | 0 | ▶ | my ($c, $args) = @_; | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 212 | 0 | my $report_id = $args->{report_id}; | |||||||||||
| 213 | 0 | my $report = Ukigumo::Server::Command::Report->find( report_id => $report_id ); | |||||||||||
| 214 | 0 | ▶ | if ($report) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 215 | return $c->render( | ||||||||||||
| 216 | 'show_report.tx', | ||||||||||||
| 217 | { | ||||||||||||
| 218 | report => $report, | ||||||||||||
| 219 | body => Ukigumo::Server::Util::make_line_link( $report->{body} ) | ||||||||||||
| 220 | 0 | } | |||||||||||
| 221 | ); | ||||||||||||
| 222 | } else { | ||||||||||||
| 223 | 0 | return $c->res_404(); | |||||||||||
| 224 | } | ||||||||||||
| 225 | 1 | }; | |||||||||||
| 226 | |||||||||||||
| 227 | get '/docs/api' => sub { | ||||||||||||
| 228 | 0 | ▶ | my ($c) = @_; | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 229 | 0 | return $c->render('docs/api.tx'); | |||||||||||
| 230 | 1 | }; | |||||||||||
| 231 | |||||||||||||
| 232 | get '/docs/{path:[a-z0-9_-]+}' => sub { | ||||||||||||
| 233 | 0 | ▶ | my ($c, $args) = @_; | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 234 | 0 | ▶ | my $path = $args->{path} // die; | ||||||||||
|
Condition0%0/2
$args->{"path"} // die()
MC/DC0%0/1
$args->{"path"} // die()
$args->{"path"}
Truth table0%0/2
A
A= $args->{"path"}
| |||||||||||||
| 235 | 0 | require Ukigumo::Server::Command::Docs; | |||||||||||
| 236 | 0 | my $html = Ukigumo::Server::Command::Docs->render($path); | |||||||||||
| 237 | |||||||||||||
| 238 | 0 | $c->render('docs.tx', { | |||||||||||
| 239 | doc => $html | ||||||||||||
| 240 | }); | ||||||||||||
| 241 | 1 | }; | |||||||||||
| 242 | |||||||||||||
| 243 | 1 | 1; | |||||||||||