Merge remote branch 't0m/json' into json
[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
cbcd8397 42=head2 tree
8fd20a28 43
cbcd8397 44Provide a simple redirect to C</ref/tree>.
8fd20a28 45
46=cut
47
cbcd8397 48sub tree : Chained('find') Args(0) {
49 my($self, $c) = @_;
50 $c->res->redirect($c->uri_for_action('/ref/tree', [$c->stash->{Repository}->name, 'HEAD']));
51 $c->res->status(301);
8fd20a28 52}
53
b132dce6 54=head2 atom
55
56Provides an atom feed for a given repository.
57
58=cut
59
f3be32b4 60sub atom : Chained('find') Does('FilenameArgs') Args() {
b9f46eb8 61 my ($self, $c) = @_;
b132dce6 62
b9f46eb8 63 my $host = lc hostname();
64 $c->stash(
65 title => $host . ' - ' . Gitalist->config->{name},
66 updated => DateTime->now
67 );
b132dce6 68
b9f46eb8 69 my $repository = $c->stash->{Repository};
70 my %logargs = (
f3be32b4 71 sha1 => $repository->head_hash,
72 count => Gitalist->config->{paging}{log} || 25,
73 ($c->stash->{filename} ? (file => $c->stash->{filename}) : ()),
b9f46eb8 74 );
b132dce6 75
b9f46eb8 76 my @revs;
77 my $mk_title = $c->stash->{short_cmt};
78 for my $commit ($repository->list_revs(%logargs)) {
79 my $entry = {};
80 $entry->{title} = $mk_title->($commit->comment);
81 $entry->{id} = $c->uri_for_action('/ref/commit', [$repository->name, $commit->sha1]);
82 # XXX FIXME Needs work ...
83 $entry->{content} = $commit->comment;
84 push(@revs, $entry);
85 }
86 $c->stash(
87 Commits => \@revs,
88 no_wrapper => 1,
89 );
90 $c->response->content_type('application/atom+xml');
b132dce6 91}
92
93=head2 rss
94
95Provides an RSS feed for a given repository.
96
97=cut
98
f3be32b4 99sub rss : Chained('find') Does('FilenameArgs') Args() {
b132dce6 100 my ($self, $c) = @_;
101
102 my $repository = $c->stash->{Repository};
103
b9f46eb8 104 $c->stash(
b132dce6 105 title => lc(Sys::Hostname::hostname()) . ' - ' . Gitalist->config->{name},
b132dce6 106 language => 'en',
b132dce6 107 pubDate => DateTime->now,
108 lastBuildDate => DateTime->now,
b9f46eb8 109 no_wrapper => 1,
b132dce6 110 );
111
112 my %logargs = (
113 sha1 => $repository->head_hash,
114 count => Gitalist->config->{paging}{log} || 25,
f3be32b4 115 ($c->stash->{filename} ? (file => $c->stash->{filename}) : ()),
b132dce6 116 );
b9f46eb8 117 my @revs;
b132dce6 118 my $mk_title = $c->stash->{short_cmt};
119 for my $commit ($repository->list_revs(%logargs)) {
120 # XXX FIXME Needs work ....
b9f46eb8 121 push(@revs, {
b132dce6 122 title => $mk_title->($commit->comment),
65afba8d 123 permaLink => $c->uri_for_action('/ref/commit', [$repository->name, $commit->sha1]),
b132dce6 124 description => $commit->comment,
b9f46eb8 125 });
b132dce6 126 }
b9f46eb8 127 $c->stash(Commits => \@revs);
b132dce6 128 $c->response->content_type('application/rss+xml');
129}
130
28d48c6e 131__PACKAGE__->meta->make_immutable;