Skip to content

Commit

Permalink
support atom feed of commits page
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki-kimoto committed Oct 3, 2014
1 parent c7f1890 commit ea5abb0
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.9
- add ssh_rep_url_base to cnahge or hide ssh URL user directory
- add atom feed of commits page
for example, http://somehost.com/kimoto/gitprep_t/commits/master.atom
1.8
- support publick key authentication
1.7
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ OK. GitPrep suport time zone. You can set time_zone option in conig file.

### How to hide user home directory in ssh repository URL?

**1. Use symbolic link and ssh_rep_url_base option
**1. Use symbolic link and ssh_rep_url_base option**

At first, set [basic]ssh_rep_url_base option to /git

Expand All @@ -441,7 +441,7 @@ And you create symbolic link to /home/gitprep/gitprep/data/rep
ln -s /home/gitprep/gitprep/data/rep /git
chown gitprep:gitprep /git

**2. Use only public key authentication and set [basic]ssh_rep_url_base to empty
**2. Use only public key authentication and set [basic]ssh_rep_url_base to empty**

If you use only public key authentication, you can access ssh repository
using the following url.
Expand All @@ -455,6 +455,12 @@ If you set [basic]ssh_rep_url_base to empty string, this URL is shown on Browser
; ssh://[email protected]/git/kimoto/gitprep.git
ssh_rep_url_base=

### How to get atom feed of commits page

You can get atom feed of commits page by the following URL

http://somehost.com/kimoto/gitprep/commits/master.atom

## Web Site

[GitPrep Web Site](http://perlcodesample.sakura.ne.jp/gitprep-site/)
Expand Down
2 changes: 1 addition & 1 deletion lib/Gitprep.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use Mojolicious::Plugin::AutoRoute::Util 'template';
eval {require Digest::SHA; import Digest::SHA qw(sha1 sha1_hex)};
}

our $VERSION = 'v1.7';
our $VERSION = 'v1.9_dev';

has 'dbi';
has 'git';
Expand Down
14 changes: 4 additions & 10 deletions lib/Gitprep/Git.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1270,8 +1270,7 @@ sub parse_commit_text {

# GMT
{
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday)
= gmtime($commit{committer_epoch});
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($commit{committer_epoch});
$commit{age_string_date} = sprintf '%4d-%02d-%02d', 1900 + $year, $mon + 1, $mday;
$commit{age_string_datetime} = sprintf '%4d-%02d-%02d %02d:%02d:%02d',
1900 + $year, $mon + 1, $mday, $hour, $min, $sec;
Expand All @@ -1280,19 +1279,14 @@ sub parse_commit_text {
# Local Time
{
my $time_zone_second = $self->time_zone_second || 0;
my $time_zone_hour = int($time_zone_second / 60);
my $time_zone_min = $time_zone_second % 60;
my $time_zone = $time_zone_second >= 0 ? '+' : '-';
$time_zone .= sprintf("%02d:%02d", $time_zone_hour, $time_zone_min);

my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday)
= gmtime($commit{committer_epoch} + $time_zone_second);
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($commit{committer_epoch} + $time_zone_second);
$commit{age_string_date_local}
= sprintf '%4d-%02d-%02d', 1900 + $year, $mon + 1, $mday;
$commit{age_string_datetime_local} = sprintf "%4d-%02d-%02d %02d:%02d:%02d GMT$time_zone",
$commit{age_string_datetime_local} = sprintf '%4d-%02d-%02d %02d:%02d:%02d',
1900 + $year, $mon + 1, $mday, $hour, $min, $sec;
}

return \%commit;
}

Expand Down
55 changes: 48 additions & 7 deletions templates/commits.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
my $project = param('project');
my $rev_file = param('rev_file');

my $return_atom = $rev_file =~ s/\.atom$// ? 1 : 0;
my $render_atom_feed = $rev_file =~ s/\.atom$// ? 1 : 0;

my ($rev, $file) = $git->parse_rev_path($user, $project, $rev_file);
my $page = param('page') || 0;
Expand Down Expand Up @@ -46,27 +46,68 @@
stash(user => $user, project => $project, rev => $rev);

# Render atom xml feed
if ($return_atom) {
if ($render_atom_feed) {
my $url = url_with->to_abs;

my $updated = $commits->[0];

warn dumper $commits->[0];
# Add updated date time
for my $commit (@$commits) {
my $committer_epoch = $commit->{committer_epoch};
my $committer_tz = $commit->{committer_tz};

my $time_zone_second;
my $time_zone;
if ($committer_tz =~ /^(\+|\-)([0-9]{2})([0-9]{2})$/) {
my $time_zone_sign = $1;
my $time_zone_hour = $2;
my $time_zone_min = $3;
$time_zone_second = $time_zone_sign . ($time_zone_hour * (60 * 60) + $time_zone_min * 60);
$time_zone = sprintf("$time_zone_sign%02d:%02d", $time_zone_hour, $time_zone_min);
}

# updated datetime
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($committer_epoch + $time_zone_second);
my $updated = sprintf('%4d-%02d-%02dT%02d:%02d:%02d', 1900 + $year, $mon + 1, $mday, $hour, $min, $sec);
$updated .= $time_zone;

$commit->{updated} = $updated;
}

my $xml = <<"EOS";
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xml:lang="en-US">
<id>tag:gitprep,2008:/$user/$project/commits/$rev_file</id>
<link type="text/html" rel="alternate" href="$url"/>
<link type="application/atom+xml" rel="self" href="$url"/>
<title>Recent Commits to $project:$rev</title>
<updated>2013-03-29T22:16:25+09:00</updated>
<updated>$commits->[0]->{updated}</updated>

EOS

for my $commit (reverse @$commits) {
my $author_uri = url_for->base->to_abs . "/$user";
$xml .= <<"EOS";
<entry>
<id>tag:gitprep,2008:Grit::Commit/$commit->{id}</id>
<link type="text/html" rel="alternate" href="https://github.com/kraih/mojo/commit/9efcd268fd08c8e0f2418278aec31c44906e1be3"/>
<title>
$commit->{title}
</title>
<updated>$commit->{updated}</updated>
<author>
<name>$commit->{author_name}</name>
<uri>$author_uri</uri>
</author>
<content type="html">
&lt;pre style='white-space:pre-wrap;width:81ex'>$commit->{title}&lt;/pre>
</content>
</entry>
EOS
}

$xml .= <<"EOS";
</feed>
EOS


$self->res->headers->content_type('application/atom+xml');
$self->render(text => $xml);
return;
Expand Down
8 changes: 8 additions & 0 deletions xt/basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ note 'Commits page';
$t->get_ok("/$user/$project/commits/refs/heads/master");
$t->content_like(qr#refs/heads/master#);
}

# Commits page - atom feed
{
# Page access(branch name long)
$t->get_ok("/$user/$project/commits/master.atom");
$t->content_like(qr/\Q<?xml version="1.0" encoding="UTF-8"?>/);
$t->content_like(qr/<entry>/);
}
}

note 'History page';
Expand Down

0 comments on commit ea5abb0

Please sign in to comment.