Commit | Line | Data |
28d48c6e |
1 | package Gitalist::Controller::Repository; |
28d48c6e |
2 | use Moose; |
b132dce6 |
3 | use Sys::Hostname qw/hostname/; |
28d48c6e |
4 | use namespace::autoclean; |
5 | |
b6ec181b |
6 | BEGIN { extends 'Gitalist::Controller' } |
ecb0ebe7 |
7 | with 'Gitalist::URIStructure::Repository'; |
28d48c6e |
8 | |
066e9aa4 |
9 | sub base : Chained('/base') PathPart('') CaptureArgs(0) {} |
f6a72048 |
10 | |
8fd20a28 |
11 | =head2 search |
12 | |
13 | The action for the search form. |
14 | |
15 | =cut |
16 | |
39724fd5 |
17 | sub search : Chained('find') Args(0) { |
8fd20a28 |
18 | my($self, $c) = @_; |
19 | my $repository = $c->stash->{Repository}; |
20 | # Lifted from /shortlog. |
21 | my %logargs = ( |
a349e797 |
22 | sha1 => $repository->head_hash, |
8fd20a28 |
23 | # count => Gitalist->config->{paging}{log}, |
24 | # ($c->req->param('f') ? (file => $c->req->param('f')) : ()), |
25 | search => { |
26 | type => $c->req->param('type'), |
27 | text => $c->req->param('text'), |
28 | regexp => $c->req->param('regexp') || 0, |
29 | }, |
30 | ); |
31 | |
32 | $c->stash( |
33 | # commit => $commit, |
34 | results => [$repository->list_revs(%logargs)], |
35 | # This could be added - page => $page, |
36 | ); |
37 | } |
38 | |
cbcd8397 |
39 | =head2 tree |
8fd20a28 |
40 | |
cbcd8397 |
41 | Provide a simple redirect to C</ref/tree>. |
8fd20a28 |
42 | |
43 | =cut |
44 | |
cbcd8397 |
45 | sub tree : Chained('find') Args(0) { |
46 | my($self, $c) = @_; |
47 | $c->res->redirect($c->uri_for_action('/ref/tree', [$c->stash->{Repository}->name, 'HEAD'])); |
48 | $c->res->status(301); |
8fd20a28 |
49 | } |
50 | |
b132dce6 |
51 | =head2 atom |
52 | |
53 | Provides an atom feed for a given repository. |
54 | |
55 | =cut |
56 | |
f3be32b4 |
57 | sub atom : Chained('find') Does('FilenameArgs') Args() { |
b9f46eb8 |
58 | my ($self, $c) = @_; |
b132dce6 |
59 | |
b9f46eb8 |
60 | my $host = lc hostname(); |
61 | $c->stash( |
62 | title => $host . ' - ' . Gitalist->config->{name}, |
63 | updated => DateTime->now |
64 | ); |
b132dce6 |
65 | |
b9f46eb8 |
66 | my $repository = $c->stash->{Repository}; |
67 | my %logargs = ( |
f3be32b4 |
68 | sha1 => $repository->head_hash, |
69 | count => Gitalist->config->{paging}{log} || 25, |
70 | ($c->stash->{filename} ? (file => $c->stash->{filename}) : ()), |
b9f46eb8 |
71 | ); |
b132dce6 |
72 | |
b9f46eb8 |
73 | my @revs; |
74 | my $mk_title = $c->stash->{short_cmt}; |
75 | for my $commit ($repository->list_revs(%logargs)) { |
76 | my $entry = {}; |
77 | $entry->{title} = $mk_title->($commit->comment); |
78 | $entry->{id} = $c->uri_for_action('/ref/commit', [$repository->name, $commit->sha1]); |
79 | # XXX FIXME Needs work ... |
80 | $entry->{content} = $commit->comment; |
81 | push(@revs, $entry); |
82 | } |
83 | $c->stash( |
84 | Commits => \@revs, |
85 | no_wrapper => 1, |
86 | ); |
87 | $c->response->content_type('application/atom+xml'); |
b132dce6 |
88 | } |
89 | |
90 | =head2 rss |
91 | |
92 | Provides an RSS feed for a given repository. |
93 | |
94 | =cut |
95 | |
f3be32b4 |
96 | sub rss : Chained('find') Does('FilenameArgs') Args() { |
b132dce6 |
97 | my ($self, $c) = @_; |
98 | |
99 | my $repository = $c->stash->{Repository}; |
100 | |
b9f46eb8 |
101 | $c->stash( |
b132dce6 |
102 | title => lc(Sys::Hostname::hostname()) . ' - ' . Gitalist->config->{name}, |
b132dce6 |
103 | language => 'en', |
b132dce6 |
104 | pubDate => DateTime->now, |
105 | lastBuildDate => DateTime->now, |
b9f46eb8 |
106 | no_wrapper => 1, |
b132dce6 |
107 | ); |
108 | |
109 | my %logargs = ( |
110 | sha1 => $repository->head_hash, |
111 | count => Gitalist->config->{paging}{log} || 25, |
f3be32b4 |
112 | ($c->stash->{filename} ? (file => $c->stash->{filename}) : ()), |
b132dce6 |
113 | ); |
b9f46eb8 |
114 | my @revs; |
b132dce6 |
115 | my $mk_title = $c->stash->{short_cmt}; |
116 | for my $commit ($repository->list_revs(%logargs)) { |
117 | # XXX FIXME Needs work .... |
b9f46eb8 |
118 | push(@revs, { |
b132dce6 |
119 | title => $mk_title->($commit->comment), |
65afba8d |
120 | permaLink => $c->uri_for_action('/ref/commit', [$repository->name, $commit->sha1]), |
b132dce6 |
121 | description => $commit->comment, |
b9f46eb8 |
122 | }); |
b132dce6 |
123 | } |
b9f46eb8 |
124 | $c->stash(Commits => \@revs); |
b132dce6 |
125 | $c->response->content_type('application/rss+xml'); |
126 | } |
127 | |
28d48c6e |
128 | __PACKAGE__->meta->make_immutable; |