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