about summary refs log tree commit diff
path: root/lib/jitterbug/WebService.pm
blob: 4f89be885fddff2802bfdb490129477495ed62fd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package jitterbug::WebService;

BEGIN {
    use Dancer ':syntax';
    load_plugin 'jitterbug::Plugin::Redis';
}

use File::Spec;

set serializer => 'JSON';

get '/build/:project/:commit/:version' => sub {
    my $project = params->{project};
    my $commit  = params->{commit};
    my $version = params->{version};

    my $conf = setting 'jitterbug';

    my $file = File::Spec->catfile( $conf->{reports}->{dir},
        $project, $commit, $version . '.txt' );

    if ( -f $file ) {
        open my $fh, '<', $file;
        my @content = <$fh>;
        close $fh;
        {
            commit  => $commit,
            version => $version,
            content => join( '', @content ),
        };
    }
};

1;