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