blob: 76168439536bdc5b05af4015cdc513e514b0c2db (
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
package jitterbug::Project;
use Dancer ':syntax';
use Dancer::Plugin::DBIC;
use jitterbug::Plugin::Template;
use Digest::MD5 qw/md5_hex/;
use DateTime;
use XML::Feed;
get '/:project' => sub {
my $project =
schema->resultset('Project')->find( { name => params->{project} } );
send_error( "Project " . params->{project} . " not found", 404 )
unless $project;
my $builds = _sorted_builds($project);
my $commits;
my $total_by_days;
foreach (@$builds) {
$_->{avatar} = md5_hex( lc( $_->{author}->{email} ) );
my $t = $_->{timestamp};
(my $d) = $t =~ /^(\d{4}-\d{2}-\d{2})/;
push @{$commits->{$d}}, $_;
$total_by_days->{$d}++;
}
my @days = sort {$b cmp $a} keys %$commits;
template 'project/index',
{project => $project, days => \@days, commits => $commits, total_by_days => $total_by_days};
};
get '/:project/feed' => sub {
my $project =
schema->resultset('Project')->find( { name => params->{project} } );
send_error( "Project " . params->{project} . " not found", 404 )
unless $project;
my $builds = _sorted_builds($project);
my $feed = XML::Feed->new('Atom');
$feed->title('builds for '.$project->name);
my $builds_per_feed = setting('builds_per_feed') || 5;
for(0..$builds_per_feed) {
my $build = $builds->[$_];
foreach my $version (keys %{$build->{build}->{version}}) {
my $entry = XML::Feed::Entry->new();
$entry->link( request->base
. 'api/build/'
. $project->name . '/'
. $build->{id} . '/'
.$version );
$entry->author($build->{author}->{name});
$entry->title( "build for " . $build->{id} . ' on ' . $version );
$entry->summary( "Result: " . $build->{build}->{version}->{$version} );
$feed->add_entry($entry);
}
}
content_type('application/atom+xml');
$feed->as_xml;
};
sub _sorted_builds {
my $project = shift;
return [] if !defined $project;
my $commits =
schema->resultset('Commit')
->search( { projectid => $project->projectid } );
my @builds;
while ( my $c = $commits->next ) {
my $content = from_json($c->content);
$content->{id} = $c->sha256 if (!$content->{id});
push @builds, $content;
}
@builds = sort { $b->{timestamp} cmp $a->{timestamp} } @builds;
\@builds;
}
1;
|