X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FGitalist%2FController%2FRepository.pm;h=fd2756314ba8d8c7a4d1663de5601ae9669af7f7;hb=2a3e469739a4d635584877a0e8ea0265a921610b;hp=5015ae28b92d71bb6c924bf23e7a265ceb83b1e8;hpb=16bdb8dfa9dc68ef5ce8ca2e9e4af824eb170015;p=catagits%2FGitalist.git diff --git a/lib/Gitalist/Controller/Repository.pm b/lib/Gitalist/Controller/Repository.pm index 5015ae2..fd27563 100644 --- a/lib/Gitalist/Controller/Repository.pm +++ b/lib/Gitalist/Controller/Repository.pm @@ -1,39 +1,135 @@ package Gitalist::Controller::Repository; - use Moose; -use Moose::Autobox; -use Try::Tiny qw/try catch/; +use XML::Atom::Feed; +use XML::Atom::Entry; +use XML::RSS; +use Sys::Hostname qw/hostname/; use namespace::autoclean; -BEGIN { extends 'Catalyst::Controller' } +BEGIN { extends 'Gitalist::Controller' } +with 'Gitalist::URIStructure::Repository'; -sub base : Chained('/root') PathPart('') CaptureArgs(0) { - my ($self, $c) = @_; - $c->stash(_do_not_mangle_uri_for => 1); +sub base : Chained('/base') PathPart('') CaptureArgs(0) {} + +=head2 search + +The action for the search form. + +=cut + +sub search : Chained('find') Args(0) { + my($self, $c) = @_; + my $repository = $c->stash->{Repository}; + # Lifted from /shortlog. + my %logargs = ( + sha1 => $repository->head_hash, +# count => Gitalist->config->{paging}{log}, +# ($c->req->param('f') ? (file => $c->req->param('f')) : ()), + search => { + type => $c->req->param('type'), + text => $c->req->param('text'), + regexp => $c->req->param('regexp') || 0, + }, + ); + + $c->stash( +# commit => $commit, + results => [$repository->list_revs(%logargs)], + # This could be added - page => $page, + ); } -sub find : Chained('base') PathPart('') CaptureArgs(1) { - my ($self, $c, $repository) = @_; - try { - $c->stash(Repository => $c->model()->get_repository($repository)); - } - catch { - $c->detach('/error_404'); - }; +=head2 reflog + +Expose the local reflog. This may go away. + +=cut + +sub reflog : Chained('find') Args(0) { + my ( $self, $c ) = @_; + my @log = $c->stash->{Repository}->reflog( + '--since=yesterday' + ); + + $c->stash( + log => \@log, + ); } -sub summary : Chained('find') PathPart('') Args(0) {} +=head2 atom + +Provides an atom feed for a given repository. -sub shortlog : Chained('find') Args(0) { +=cut + +sub atom : Chained('find') Args(0) { my ($self, $c) = @_; - $c->stash(no_wrapper => 1); - $c->forward('/shortlog'); + + my $host = lc hostname(); + $c->stash( + title => $host . ' - ' . Gitalist->config->{name}, + updated => DateTime->now + ); + + my $repository = $c->stash->{Repository}; + my %logargs = ( + sha1 => $repository->head_hash, + count => Gitalist->config->{paging}{log} || 25, + ); + + my @revs; + my $mk_title = $c->stash->{short_cmt}; + for my $commit ($repository->list_revs(%logargs)) { + my $entry = {}; + $entry->{title} = $mk_title->($commit->comment); + $entry->{id} = $c->uri_for_action('/ref/commit', [$repository->name, $commit->sha1]); + # XXX FIXME Needs work ... + $entry->{content} = $commit->comment; + push(@revs, $entry); + } + $c->stash( + Commits => \@revs, + no_wrapper => 1, + ); + $c->response->content_type('application/atom+xml'); } -sub log : Chained('find') Args(0) { - my ($self, $c) = @_; - $c->stash(template => 'log.tt2'); - $c->forward('/log'); +=head2 rss + +Provides an RSS feed for a given repository. + +=cut + +sub rss : Chained('find') Args(0) { + my ($self, $c) = @_; + + my $repository = $c->stash->{Repository}; + + $c->stash( + title => lc(Sys::Hostname::hostname()) . ' - ' . Gitalist->config->{name}, + language => 'en', + pubDate => DateTime->now, + lastBuildDate => DateTime->now, + no_wrapper => 1, + ); + + my %logargs = ( + sha1 => $repository->head_hash, + count => Gitalist->config->{paging}{log} || 25, +# ($c->req->param('f') ? (file => $c->req->param('f')) : ()) + ); + my @revs; + my $mk_title = $c->stash->{short_cmt}; + for my $commit ($repository->list_revs(%logargs)) { + # XXX FIXME Needs work .... + push(@revs, { + title => $mk_title->($commit->comment), + permaLink => $c->uri_for_action('/ref/commit', [$repository->name, $commit->sha1]), + description => $commit->comment, + }); + } + $c->stash(Commits => \@revs); + $c->response->content_type('application/rss+xml'); } __PACKAGE__->meta->make_immutable;