Commit | Line | Data |
28d48c6e |
1 | package Gitalist::Controller::Repository; |
28d48c6e |
2 | use Moose; |
b132dce6 |
3 | use XML::Atom::Feed; |
4 | use XML::Atom::Entry; |
5 | use XML::RSS; |
6 | use Sys::Hostname qw/hostname/; |
28d48c6e |
7 | use namespace::autoclean; |
8 | |
b6ec181b |
9 | BEGIN { extends 'Gitalist::Controller' } |
ecb0ebe7 |
10 | with 'Gitalist::URIStructure::Repository'; |
28d48c6e |
11 | |
066e9aa4 |
12 | sub base : Chained('/base') PathPart('') CaptureArgs(0) {} |
f6a72048 |
13 | |
b132dce6 |
14 | =head2 atom |
15 | |
16 | Provides an atom feed for a given repository. |
17 | |
18 | =cut |
19 | |
20 | sub atom : Chained('find') Args(0) { |
21 | my($self, $c) = @_; |
22 | |
23 | my $feed = XML::Atom::Feed->new; |
24 | |
25 | my $host = lc hostname(); |
26 | $feed->title($host . ' - ' . Gitalist->config->{name}); |
27 | $feed->updated(~~DateTime->now); |
28 | |
29 | my $repository = $c->stash->{Repository}; |
30 | my %logargs = ( |
31 | sha1 => $repository->head_hash, |
32 | count => Gitalist->config->{paging}{log} || 25, |
33 | ); |
34 | |
35 | my $mk_title = $c->stash->{short_cmt}; |
36 | for my $commit ($repository->list_revs(%logargs)) { |
37 | my $entry = XML::Atom::Entry->new; |
38 | $entry->title( $mk_title->($commit->comment) ); |
39 | $entry->id($c->uri_for_action('/commit/commit', [$repository->name, $commit->sha1])); |
40 | # XXX FIXME Needs work ... |
41 | $entry->content($commit->comment); |
42 | $feed->add_entry($entry); |
43 | } |
44 | |
45 | $c->response->body($feed->as_xml); |
46 | $c->response->content_type('application/atom+xml'); |
47 | } |
48 | |
49 | =head2 rss |
50 | |
51 | Provides an RSS feed for a given repository. |
52 | |
53 | =cut |
54 | |
55 | sub rss : Chained('find') Args(0) { |
56 | my ($self, $c) = @_; |
57 | |
58 | my $repository = $c->stash->{Repository}; |
59 | |
60 | my $rss = XML::RSS->new(version => '2.0'); |
61 | $rss->channel( |
62 | title => lc(Sys::Hostname::hostname()) . ' - ' . Gitalist->config->{name}, |
63 | link => $c->uri_for('summary', {p=>$repository->name}), |
64 | language => 'en', |
65 | description => $repository->description, |
66 | pubDate => DateTime->now, |
67 | lastBuildDate => DateTime->now, |
68 | ); |
69 | |
70 | my %logargs = ( |
71 | sha1 => $repository->head_hash, |
72 | count => Gitalist->config->{paging}{log} || 25, |
73 | # ($c->req->param('f') ? (file => $c->req->param('f')) : ()) |
74 | ); |
75 | my $mk_title = $c->stash->{short_cmt}; |
76 | for my $commit ($repository->list_revs(%logargs)) { |
77 | # XXX FIXME Needs work .... |
78 | $rss->add_item( |
79 | title => $mk_title->($commit->comment), |
80 | permaLink => $c->uri_for_action('/commit/commit', [$repository->name, $commit->sha1]), |
81 | description => $commit->comment, |
82 | ); |
83 | } |
84 | |
85 | $c->response->body($rss->as_string); |
86 | $c->response->content_type('application/rss+xml'); |
87 | } |
88 | |
28d48c6e |
89 | __PACKAGE__->meta->make_immutable; |