Provided support for blobdiff_plain legacy URIs.
[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 = (
a349e797 25 sha1 => $repository->head_hash,
8fd20a28 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) {
b9f46eb8 66 my ($self, $c) = @_;
b132dce6 67
b9f46eb8 68 my $host = lc hostname();
69 $c->stash(
70 title => $host . ' - ' . Gitalist->config->{name},
71 updated => DateTime->now
72 );
b132dce6 73
b9f46eb8 74 my $repository = $c->stash->{Repository};
75 my %logargs = (
76 sha1 => $repository->head_hash,
77 count => Gitalist->config->{paging}{log} || 25,
78 );
b132dce6 79
b9f46eb8 80 my @revs;
81 my $mk_title = $c->stash->{short_cmt};
82 for my $commit ($repository->list_revs(%logargs)) {
83 my $entry = {};
84 $entry->{title} = $mk_title->($commit->comment);
85 $entry->{id} = $c->uri_for_action('/ref/commit', [$repository->name, $commit->sha1]);
86 # XXX FIXME Needs work ...
87 $entry->{content} = $commit->comment;
88 push(@revs, $entry);
89 }
90 $c->stash(
91 Commits => \@revs,
92 no_wrapper => 1,
93 );
94 $c->response->content_type('application/atom+xml');
b132dce6 95}
96
97=head2 rss
98
99Provides an RSS feed for a given repository.
100
101=cut
102
103sub rss : Chained('find') Args(0) {
104 my ($self, $c) = @_;
105
106 my $repository = $c->stash->{Repository};
107
b9f46eb8 108 $c->stash(
b132dce6 109 title => lc(Sys::Hostname::hostname()) . ' - ' . Gitalist->config->{name},
b132dce6 110 language => 'en',
b132dce6 111 pubDate => DateTime->now,
112 lastBuildDate => DateTime->now,
b9f46eb8 113 no_wrapper => 1,
b132dce6 114 );
115
116 my %logargs = (
117 sha1 => $repository->head_hash,
118 count => Gitalist->config->{paging}{log} || 25,
119# ($c->req->param('f') ? (file => $c->req->param('f')) : ())
120 );
b9f46eb8 121 my @revs;
b132dce6 122 my $mk_title = $c->stash->{short_cmt};
123 for my $commit ($repository->list_revs(%logargs)) {
124 # XXX FIXME Needs work ....
b9f46eb8 125 push(@revs, {
b132dce6 126 title => $mk_title->($commit->comment),
65afba8d 127 permaLink => $c->uri_for_action('/ref/commit', [$repository->name, $commit->sha1]),
b132dce6 128 description => $commit->comment,
b9f46eb8 129 });
b132dce6 130 }
b9f46eb8 131 $c->stash(Commits => \@revs);
b132dce6 132 $c->response->content_type('application/rss+xml');
133}
134
28d48c6e 135__PACKAGE__->meta->make_immutable;