lib/Gitalist/Controller/Repository.pm untested

filter: Statementstmt 0.0% 0 / 48 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 76 CC 3 SCAR 12.4
CC
3
Cov
0%
atom
6.0
rss
6.0
BEGIN
2.0
CRAP 3.5
1 package Gitalist::Controller::Repository;
2 use Moose;
3 use Sys::Hostname qw/hostname/;
4 use namespace::autoclean;
5  
6 BEGIN { extends 'Gitalist::Controller' }
7 with 'Gitalist::URIStructure::Repository';
8  
9 sub base : Chained('/base') PathPart('') CaptureArgs(0) {}
10  
11 =encoding UTF-8
12  
13 =head1 NAME
14  
15 Gitalist::Controller::Repository - Controller::Repository module for Gitalist
16  
17 =head2 search
18  
19 The action for the search form.
20  
21 =cut
22  
23 sub search : Chained('find') Args(0) {
24 my($self, $c) = @_;
25 my $repository = $c->stash->{Repository};
26 # Lifted from /shortlog.
27 my %logargs = (
28 sha1 => $repository->head_hash,
29 # count => Gitalist->config->{paging}{log},
30 # ($c->req->param('f') ? (file => $c->req->param('f')) : ()),
31 search => {
32 type => $c->req->param('type'),
33 text => $c->req->param('text'),
34 regexp => $c->req->param('regexp') || 0,
35 },
36 );
37  
38 $c->stash(
39 # commit => $commit,
40 results => [$repository->list_revs(%logargs)],
41 # This could be added - page => $page,
42 );
43 }
44  
45 =head2 tree
46  
47 Provide a simple redirect to C</ref/tree>.
48  
49 =cut
50  
51 sub tree : Chained('find') Args(0) {
52 my($self, $c) = @_;
53 $c->res->redirect($c->uri_for_action('/ref/tree', [$c->stash->{Repository}->name, 'HEAD']));
54 $c->res->status(301);
55 }
56  
57 =head2 atom
58  
59 Provides an atom feed for a given repository.
60  
61 =cut
62  
63 sub atom : Chained('find') Does('FilenameArgs') Args() {
64 my ($self, $c) = @_;
65  
66 my $host = lc hostname();
67 $c->stash(
68 title => $host . ' - ' . Gitalist->config->{name},
69 updated => DateTime->now
70 );
71  
72 my $repository = $c->stash->{Repository};
73 my %logargs = (
74 sha1 => $repository->head_hash,
75 count => Gitalist->config->{paging}{log} || 25,
76 ($c->stash->{filename} ? (file => $c->stash->{filename}) : ()),
77 );
78  
79 my @revs;
80 my $mk_title = $c->stash->{short_cmt};
81 for my $commit ($repository->list_revs(%logargs)) {
82 my $entry = {};
83 $entry->{title} = $mk_title->($commit->comment);
84 $entry->{id} = $c->uri_for_action('/ref/commit', [$repository->name, $commit->sha1]);
85 # XXX FIXME Needs work ...
86 $entry->{content} = $commit->comment;
87 push(@revs, $entry);
88 }
89 $c->stash(
90 Commits => \@revs,
91 no_wrapper => 1,
92 );
93 $c->response->content_type('application/atom+xml');
94 }
95  
96 =head2 rss
97  
98 Provides an RSS feed for a given repository.
99  
100 =cut
101  
102 sub rss : Chained('find') Does('FilenameArgs') Args() {
103 my ($self, $c) = @_;
104  
105 my $repository = $c->stash->{Repository};
106  
107 $c->stash(
108 title => lc(Sys::Hostname::hostname()) . ' - ' . Gitalist->config->{name},
109 language => 'en',
110 pubDate => DateTime->now,
111 lastBuildDate => DateTime->now,
112 no_wrapper => 1,
113 );
114  
115 my %logargs = (
116 sha1 => $repository->head_hash,
117 count => Gitalist->config->{paging}{log} || 25,
118 ($c->stash->{filename} ? (file => $c->stash->{filename}) : ()),
119 );
120 my @revs;
121 my $mk_title = $c->stash->{short_cmt};
122 for my $commit ($repository->list_revs(%logargs)) {
123 # XXX FIXME Needs work ....
124 push(@revs, {
125 title => $mk_title->($commit->comment),
126 permaLink => $c->uri_for_action('/ref/commit', [$repository->name, $commit->sha1]),
127 description => $commit->comment,
128 });
129 }
130 $c->stash(Commits => \@revs);
131 $c->response->content_type('application/rss+xml');
132 }
133  
134 __PACKAGE__->meta->make_immutable;