copy gitweblite soruce code
|
1 |
use 5.008007; |
renamed gitpub to gitprep
|
2 |
package Gitprep; |
copy gitweblite soruce code
|
3 |
use Mojo::Base 'Mojolicious'; |
cleanup
|
4 | |
5 |
use Carp 'croak'; |
|
added start page
|
6 |
use DBIx::Custom; |
added user management featur...
|
7 |
use Encode qw/encode decode/; |
little more secure login
|
8 |
use Gitprep::API; |
cleanup
|
9 |
use Gitprep::Git; |
fixed tags page paging bug a...
|
10 |
use Gitprep::Manager; |
added RepManager rename feat...
|
11 |
use Scalar::Util 'weaken'; |
cleanup
|
12 |
use Validator::Custom; |
copy gitweblite soruce code
|
13 | |
Digest::SHA loading to Mojo:...
|
14 |
# Digest::SHA loading to Mojo::Util if not loaded |
15 |
{ |
|
16 |
package Mojo::Util; |
|
17 |
eval {require Digest::SHA; import Digest::SHA qw(sha1 sha1_hex)}; |
|
18 |
} |
|
19 | ||
version 1.2 release
|
20 |
our $VERSION = '1.02'; |
cleanup
|
21 | |
added start page
|
22 |
has 'dbi'; |
cleanup
|
23 |
has 'git'; |
added RepManager rename feat...
|
24 |
has 'manager'; |
cleanup
|
25 |
has 'validator'; |
copy gitweblite soruce code
|
26 | |
27 |
sub startup { |
|
28 |
my $self = shift; |
|
29 |
|
|
cleanup
|
30 |
# Config file |
update Mojolicious and added...
|
31 |
$self->plugin('INIConfig', {ext => 'conf'}); |
32 |
|
|
cleanup
|
33 |
# Config file for developper |
add need_login_always_option
|
34 |
unless ($ENV{GITPREP_NO_MYCONFIG}) { |
35 |
my $my_conf_file = $self->home->rel_file('gitprep.my.conf'); |
|
36 |
$self->plugin('INIConfig', {file => $my_conf_file}) if -f $my_conf_file; |
|
37 |
} |
|
update Mojolicious and added...
|
38 |
|
cleanup
|
39 |
# Listen |
copy gitweblite soruce code
|
40 |
my $conf = $self->config; |
cleanup
|
41 |
my $listen = $conf->{hypnotoad}{listen} ||= ['http://*:10020']; |
42 |
$listen = [split /,/, $listen] unless ref $listen eq 'ARRAY'; |
|
fixed listen bug
|
43 |
$conf->{hypnotoad}{listen} = $listen; |
copy gitweblite soruce code
|
44 |
|
cleanup
|
45 |
# Git |
renamed gitpub to gitprep
|
46 |
my $git = Gitprep::Git->new; |
cleanup
|
47 |
my $git_bin |
48 |
= $conf->{basic}{git_bin} ? $conf->{basic}{git_bin} : $git->search_bin; |
|
fix mini bug
|
49 |
if (!$git_bin || ! -e $git_bin) { |
50 |
$git_bin ||= ''; |
|
cleanup
|
51 |
my $error = "Can't detect or found git command ($git_bin)." |
52 |
. " set git_bin in gitprep.conf"; |
|
fixed git_bin not found bug
|
53 |
$self->log->error($error); |
54 |
croak $error; |
|
55 |
} |
|
copy gitweblite soruce code
|
56 |
$git->bin($git_bin); |
fix bug that http clone won'...
|
57 |
|
added AutoRoute plugin
|
58 |
# Repository Manager |
fixed tags page paging bug a...
|
59 |
my $manager = Gitprep::Manager->new(app => $self); |
added AutoRoute plugin
|
60 |
weaken $manager->{app}; |
61 |
$self->manager($manager); |
|
fixed git_bin not found bug
|
62 |
|
63 |
# Repository home |
|
cleanup
|
64 |
my $rep_home = $ENV{GITPREP_REP_HOME} || $self->home->rel_file('data/rep'); |
added create repository feat...
|
65 |
$git->rep_home($rep_home); |
66 |
unless (-d $rep_home) { |
|
67 |
mkdir $rep_home |
|
68 |
or croak "Can't create directory $rep_home: $!"; |
|
69 |
} |
|
copy gitweblite soruce code
|
70 |
$self->git($git); |
cleanup
|
71 |
|
added test
|
72 |
# Added public path |
73 |
push @{$self->static->paths}, $rep_home; |
|
cleanup
|
74 |
|
improved create repository f...
|
75 |
# DBI |
added test
|
76 |
my $db_file = $ENV{GITPREP_DB_FILE} |
77 |
|| $self->home->rel_file('data/gitprep.db'); |
|
improved create repository f...
|
78 |
my $dbi = DBIx::Custom->connect( |
79 |
dsn => "dbi:SQLite:database=$db_file", |
|
80 |
connector => 1, |
|
added original_pid column
|
81 |
option => {sqlite_unicode => 1, sqlite_use_immediate_transaction => 1} |
improved create repository f...
|
82 |
); |
83 |
$self->dbi($dbi); |
|
84 |
|
|
cleanup
|
85 |
# Database file permision |
fixed database file permissi...
|
86 |
if (my $user = $self->config->{hypnotoad}{user}) { |
87 |
my $uid = (getpwnam $user)[2]; |
|
88 |
chown $uid, -1, $db_file; |
|
89 |
} |
|
90 |
if (my $group = $self->config->{hypnotoad}{group}) { |
|
91 |
my $gid = (getgrnam $group)[2]; |
|
92 |
chown -1, $gid, $db_file; |
|
93 |
} |
|
94 |
|
|
added tab_index columns
|
95 |
# Setup database |
96 |
$self->manager->setup_database; |
|
improved create repository f...
|
97 |
|
98 |
# Model |
|
99 |
my $models = [ |
|
100 |
{table => 'user', primary_key => 'id'}, |
|
added original_pid column
|
101 |
{table => 'project', primary_key => ['user_id', 'name']}, |
102 |
{table => 'number', primary_key => 'key'} |
|
improved create repository f...
|
103 |
]; |
104 |
$dbi->create_model($_) for @$models; |
|
105 | ||
106 |
# Validator |
|
107 |
my $validator = Validator::Custom->new; |
|
108 |
$self->validator($validator); |
|
added project delete feature
|
109 |
$validator->register_constraint( |
110 |
user_name => sub { |
|
111 |
my $value = shift; |
|
112 |
|
|
113 |
return ($value || '') =~ /^[a-zA-Z0-9_\-]+$/ |
|
114 |
}, |
|
115 |
project_name => sub { |
|
116 |
my $value = shift; |
|
117 |
|
|
118 |
return ($value || '') =~ /^[a-zA-Z0-9_\-]+$/ |
|
119 |
} |
|
120 |
); |
|
improved create repository f...
|
121 |
|
added admin user tests
|
122 | |
cleanup
|
123 |
# Routes |
Auto Route system catch up w...
|
124 |
sub template { |
125 |
my $template = shift; |
|
126 |
|
|
cleanup
|
127 |
return sub { shift->render($template, , 'mojo.maybe' => 1) }; |
Auto Route system catch up w...
|
128 |
} |
129 |
|
|
added login page
|
130 |
{ |
cleanup
|
131 |
my $r = $self->routes; |
132 | ||
133 |
# DBViewer(only development) |
|
134 |
if ($self->mode eq 'development') { |
|
135 |
eval { |
|
136 |
$self->plugin( |
|
137 |
'DBViewer', |
|
138 |
dsn => "dbi:SQLite:database=$db_file" |
|
139 |
); |
|
140 |
}; |
|
added reset password feature
|
141 |
} |
added AutoRoute plugin
|
142 |
|
cleanup
|
143 |
# Auto route |
cleanup many pages
|
144 |
{ |
cleanup
|
145 |
my $r = $r->under(sub { |
146 |
my $self = shift; |
|
147 |
|
|
148 |
my $api = $self->gitprep_api; |
|
149 |
|
|
add need_login_always_option
|
150 |
# Authentication |
cleanup
|
151 |
{ |
152 |
my $path = $self->req->url->path->parts->[0] || ''; |
|
add need_login_always_option
|
153 |
|
154 |
# Admin |
|
cleanup
|
155 |
if ($path eq '_admin' && !$api->logined_admin) { |
156 |
$self->redirect_to('/'); |
|
157 |
return; |
|
158 |
} |
|
159 |
} |
|
160 |
|
|
161 |
return 1; |
|
162 |
}); |
|
add need_login_always_option
|
163 |
|
164 |
# Auto routes |
|
cleanup
|
165 |
$self->plugin('AutoRoute', route => $r); |
improved repository page des...
|
166 | |
add need_login_always_option
|
167 |
# Custom routes |
cleanup
|
168 |
{ |
add need_login_always_option
|
169 |
my $id_re = qr/[a-zA-Z0-9_-]+/; |
cleanup
|
170 |
|
add need_login_always_option
|
171 |
# User |
172 |
my $r = $r->route('/:user', user => $id_re); |
|
173 |
{ |
|
174 |
# Home |
|
175 |
$r->get('/' => template '/user'); |
|
176 |
|
|
177 |
# Settings |
|
178 |
$r->get('/_settings' => template '/user-settings'); |
|
179 |
} |
|
cleanup
|
180 |
|
add need_login_always_option
|
181 |
# Project |
182 |
{ |
|
183 |
my $r = $r->route('/:project', project => $id_re); |
|
184 |
|
|
185 |
# Home |
|
186 |
$r->get('/' => template '/project'); |
|
187 |
|
|
188 |
# Commit |
|
189 |
$r->get('/commit/*diff' => template '/commit'); |
|
190 |
|
|
191 |
# Commits |
|
192 |
$r->get('/commits/*rev_file' => template '/commits'); |
|
193 |
|
|
194 |
# Branches |
|
195 |
$r->any('/branches/*base_branch' => {base_branch => undef} => template '/branches'); |
|
added feature that you see p...
|
196 | |
add need_login_always_option
|
197 |
# Tags |
198 |
$r->get('/tags' => template '/tags'); |
|
improved network page
|
199 | |
add need_login_always_option
|
200 |
# Tree |
201 |
$r->get('/tree/*rev_dir' => template '/tree'); |
|
202 |
|
|
203 |
# Blob |
|
204 |
$r->get('/blob/*rev_file' => template '/blob'); |
|
add blame method
|
205 | |
add need_login_always_option
|
206 |
# Raw |
207 |
$r->get('/raw/*rev_file' => template '/raw'); |
|
add blame method
|
208 | |
add need_login_always_option
|
209 |
# Blame |
210 |
$r->get('/blame/*rev_file' => template '/blame'); |
|
211 |
|
|
212 |
# Archive |
|
213 |
$r->get('/archive/(*rev).tar.gz' => template '/archive')->to(archive_type => 'tar'); |
|
214 |
$r->get('/archive/(*rev).zip' => template '/archive')->to(archive_type => 'zip' ); |
|
215 |
|
|
216 |
# Compare |
|
217 |
$r->get('/compare/(*rev1)...(*rev2)' => template '/compare'); |
|
218 |
|
|
219 |
# Settings |
|
220 |
$r->any('/settings' => template '/settings'); |
|
221 |
|
|
222 |
# Fork |
|
223 |
$r->any('/fork' => template '/fork'); |
|
cleanup
|
224 | |
add need_login_always_option
|
225 |
# Network |
226 |
$r->get('/network' => template '/network'); |
|
cleanup
|
227 | |
add need_login_always_option
|
228 |
# Network Graph |
229 |
$r->get('/network/graph/(*rev1)...(*rev2_abs)' => template '/network/graph'); |
|
add pull page design
|
230 | |
add need_login_always_option
|
231 |
# Import branch |
232 |
$r->any('/import-branch/:remote_user/:remote_project' => template '/import-branch'); |
|
233 |
|
|
234 |
# Get branches and tags |
|
235 |
$r->get('/api/revs' => template '/api/revs'); |
|
236 |
} |
|
cleanup
|
237 |
} |
added AutoRoute plugin
|
238 |
} |
239 |
} |
|
added admin user tests
|
240 | |
241 |
# Helper |
|
242 |
{ |
|
243 |
# API |
|
244 |
$self->helper(gitprep_api => sub { Gitprep::API->new(shift) }); |
|
245 |
} |
|
added reverse proxy path_dep...
|
246 |
|
added AutoRoute plugin
|
247 |
# Reverse proxy support |
added reverse proxy path_dep...
|
248 |
my $reverse_proxy_on = $self->config->{reverse_proxy}{on}; |
249 |
my $path_depth = $self->config->{reverse_proxy}{path_depth}; |
|
250 |
if ($reverse_proxy_on) { |
|
251 |
$ENV{MOJO_REVERSE_PROXY} = 1; |
|
252 |
if ($path_depth) { |
|
253 |
$self->hook('before_dispatch' => sub { |
|
254 |
my $self = shift; |
|
255 |
for (1 .. $path_depth) { |
|
256 |
my $prefix = shift @{$self->req->url->path->parts}; |
|
257 |
push @{$self->req->url->base->path->parts}, $prefix; |
|
258 |
} |
|
259 |
}); |
|
added AutoRoute plugin
|
260 |
} |
added reverse proxy path_dep...
|
261 |
} |
copy gitweblite soruce code
|
262 |
} |
263 | ||
264 |
1; |