1 |
package Frey::VCI; |
2 |
|
3 |
use Moose; |
4 |
|
5 |
use lib '/rest/cvs/vci/lib'; # FIXME |
6 |
use VCI; |
7 |
|
8 |
extends 'Frey'; |
9 |
with 'Frey::Web'; |
10 |
|
11 |
use Data::Dump qw/dump/; |
12 |
|
13 |
has 'repo' => ( |
14 |
is => 'rw', |
15 |
isa => 'Str', |
16 |
required => 1, |
17 |
default => 'file:///home/dpavlin/private/svn/Frey', |
18 |
); |
19 |
|
20 |
has 'type' => ( |
21 |
is => 'rw', |
22 |
isa => 'Str', |
23 |
required => 1, |
24 |
default => 'Svn', |
25 |
); |
26 |
|
27 |
has 'project' => ( |
28 |
is => 'rw', |
29 |
isa => 'Str', |
30 |
required => 1, |
31 |
default => 'trunk', |
32 |
); |
33 |
|
34 |
has 'revision' => ( |
35 |
is => 'rw', |
36 |
isa => 'Int|Str', |
37 |
documentation => 'last revision in repository if not specified', |
38 |
); |
39 |
|
40 |
sub as_markup { |
41 |
my ( $self ) = @_; |
42 |
|
43 |
my $html; |
44 |
|
45 |
my $repo = VCI->connect( |
46 |
repo => $self->repo, |
47 |
type => $self->type, |
48 |
debug => $self->debug, |
49 |
) || die "can't open ",$self->type," ",$self->repo; |
50 |
|
51 |
my @projects_available = map { $_->name } @{ $repo->projects }; |
52 |
die $self->project," not one of valid projects ", dump( @projects_available ) unless grep { $self->project } @projects_available; |
53 |
|
54 |
my $project = $repo->get_project( name => $self->project ); |
55 |
my $rev = $self->revision || $project->head_revision; |
56 |
|
57 |
my $commit = $project->get_commit( revision => $rev ) || die "can't get revision $rev: $@"; |
58 |
|
59 |
sub div { |
60 |
my ( $class, $text ) = @_; |
61 |
return "<div class=\"$class\">$text</div>"; |
62 |
} |
63 |
|
64 |
my $diff = $commit->as_diff; |
65 |
|
66 |
my $body = |
67 |
'<h1>Commit</h1>' . |
68 |
div( 'revision', $commit->revision ) . |
69 |
div( 'commiter', $commit->committer ) . |
70 |
div( 'date', $commit->time->iso8601 ) . |
71 |
div( 'message', $commit->message ) . |
72 |
'<pre>' . $self->html_escape( $diff->raw ) . '</pre>'; |
73 |
|
74 |
$self->add_status({ dump => $diff }); |
75 |
|
76 |
$self->title( $self->repo . '/' . $project->name ); |
77 |
return $body; |
78 |
}; |
79 |
|
80 |
warn "## VCI loaded"; |
81 |
|
82 |
1; |