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