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