gitprep / lib / Gitprep.pm /
Newer Older
353 lines | 9.677kb
add FAQ large repository can...
Yuki Kimoto authored on 2013-10-07
1
# 環境変数
2

            
copy gitweblite soruce code
root authored on 2012-11-23
3
use 5.008007;
renamed gitpub to gitprep
Yuki Kimoto authored on 2012-11-26
4
package Gitprep;
copy gitweblite soruce code
root authored on 2012-11-23
5
use Mojo::Base 'Mojolicious';
cleanup
Yuki Kimoto authored on 2013-05-14
6

            
7
use Carp 'croak';
added start page
Yuki Kimoto authored on 2013-02-09
8
use DBIx::Custom;
little more secure login
Yuki Kimoto authored on 2013-03-16
9
use Gitprep::API;
cleanup
Yuki Kimoto authored on 2013-05-14
10
use Gitprep::Git;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
11
use Gitprep::Manager;
added RepManager rename feat...
Yuki Kimoto authored on 2013-03-27
12
use Scalar::Util 'weaken';
cleanup
Yuki Kimoto authored on 2013-05-14
13
use Validator::Custom;
copy gitweblite soruce code
root authored on 2012-11-23
14

            
Digest::SHA loading to Mojo:...
Yuki Kimoto authored on 2013-08-13
15
# Digest::SHA loading to Mojo::Util if not loaded
16
{
17
  package Mojo::Util;
18
  eval {require Digest::SHA; import Digest::SHA qw(sha1 sha1_hex)};
19
}
20

            
version up and add descripti...
Yuki Kimoto authored on 2013-11-22
21
our $VERSION = '1.04';
cleanup
Yuki Kimoto authored on 2013-05-14
22

            
added start page
Yuki Kimoto authored on 2013-02-09
23
has 'dbi';
revert encoding support
Yuki Kimoto authored on 2013-11-22
24
has 'git';
added RepManager rename feat...
Yuki Kimoto authored on 2013-03-27
25
has 'manager';
rename validator to vc to up...
Yuki Kimoto authored on 2013-12-02
26
has 'vc';
revert encoding support
Yuki Kimoto authored on 2013-11-22
27

            
28
use constant BUFFER_SIZE => 8192;
add /info/refs request
Yuki Kimoto authored on 2013-10-01
29

            
copy gitweblite soruce code
root authored on 2012-11-23
30
sub startup {
31
  my $self = shift;
32
  
cleanup
Yuki Kimoto authored on 2013-05-14
33
  # Config file
update Mojolicious and added...
Yuki Kimoto authored on 2013-03-20
34
  $self->plugin('INIConfig', {ext => 'conf'});
35
  
cleanup
Yuki Kimoto authored on 2013-05-14
36
  # Config file for developper
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
37
  unless ($ENV{GITPREP_NO_MYCONFIG}) {
38
    my $my_conf_file = $self->home->rel_file('gitprep.my.conf');
39
    $self->plugin('INIConfig', {file => $my_conf_file}) if -f $my_conf_file;
40
  }
update Mojolicious and added...
Yuki Kimoto authored on 2013-03-20
41
  
cleanup
Yuki Kimoto authored on 2013-05-14
42
  # Listen
copy gitweblite soruce code
root authored on 2012-11-23
43
  my $conf = $self->config;
cleanup
Yuki Kimoto authored on 2013-05-14
44
  my $listen = $conf->{hypnotoad}{listen} ||= ['http://*:10020'];
45
  $listen = [split /,/, $listen] unless ref $listen eq 'ARRAY';
fixed listen bug
Yuki Kimoto authored on 2013-03-29
46
  $conf->{hypnotoad}{listen} = $listen;
copy gitweblite soruce code
root authored on 2012-11-23
47
  
revert encoding support
Yuki Kimoto authored on 2013-11-22
48
  # Git
renamed gitpub to gitprep
Yuki Kimoto authored on 2012-11-26
49
  my $git = Gitprep::Git->new;
cleanup
Yuki Kimoto authored on 2013-05-14
50
  my $git_bin
51
    = $conf->{basic}{git_bin} ? $conf->{basic}{git_bin} : $git->search_bin;
fix mini bug
Yuki Kimoto authored on 2013-03-31
52
  if (!$git_bin || ! -e $git_bin) {
53
    $git_bin ||= '';
cleanup
Yuki Kimoto authored on 2013-05-14
54
    my $error = "Can't detect or found git command ($git_bin)."
55
      . " set git_bin in gitprep.conf";
fixed git_bin not found bug
Yuki Kimoto authored on 2013-03-31
56
    $self->log->error($error);
57
    croak $error;
58
  }
improve code structures
Yuki Kimoto authored on 2013-11-19
59
  $git->bin($git_bin);
revert encoding support
Yuki Kimoto authored on 2013-11-22
60
  
61
  # Repository Manager
62
  my $manager = Gitprep::Manager->new(app => $self);
63
  weaken $manager->{app};
64
  $self->manager($manager);
65
  
fixed git_bin not found bug
Yuki Kimoto authored on 2013-03-31
66
  # Repository home
cleanup
Yuki Kimoto authored on 2013-05-14
67
  my $rep_home = $ENV{GITPREP_REP_HOME} || $self->home->rel_file('data/rep');
revert encoding support
Yuki Kimoto authored on 2013-11-22
68
  $git->rep_home($rep_home);
added create repository feat...
Yuki Kimoto authored on 2013-03-18
69
  unless (-d $rep_home) {
70
    mkdir $rep_home
71
      or croak "Can't create directory $rep_home: $!";
72
  }
improve code structures
Yuki Kimoto authored on 2013-11-19
73
  $self->git($git);
cleanup
Yuki Kimoto authored on 2013-05-14
74
  
revert encoding support
Yuki Kimoto authored on 2013-11-22
75
  # Added public path
76
  # push @{$self->static->paths}, $rep_home;
cleanup
Yuki Kimoto authored on 2013-05-14
77
  
improved create repository f...
Yuki Kimoto authored on 2013-03-21
78
  # DBI
added test
Yuki Kimoto authored on 2013-04-30
79
  my $db_file = $ENV{GITPREP_DB_FILE}
80
    || $self->home->rel_file('data/gitprep.db');
improved create repository f...
Yuki Kimoto authored on 2013-03-21
81
  my $dbi = DBIx::Custom->connect(
82
    dsn => "dbi:SQLite:database=$db_file",
83
    connector => 1,
added original_pid column
Yuki Kimoto authored on 2013-04-18
84
    option => {sqlite_unicode => 1, sqlite_use_immediate_transaction => 1}
improved create repository f...
Yuki Kimoto authored on 2013-03-21
85
  );
86
  $self->dbi($dbi);
87
  
cleanup
Yuki Kimoto authored on 2013-05-14
88
  # Database file permision
fixed database file permissi...
Yuki Kimoto authored on 2013-04-19
89
  if (my $user = $self->config->{hypnotoad}{user}) {
90
    my $uid = (getpwnam $user)[2];
91
    chown $uid, -1, $db_file;
92
  }
93
  if (my $group = $self->config->{hypnotoad}{group}) {
94
    my $gid = (getgrnam $group)[2];
95
    chown -1, $gid, $db_file;
96
  }
97
  
added tab_index columns
Yuki Kimoto authored on 2013-04-11
98
  # Setup database
99
  $self->manager->setup_database;
improved create repository f...
Yuki Kimoto authored on 2013-03-21
100
  
101
  # Model
102
  my $models = [
103
    {table => 'user', primary_key => 'id'},
added original_pid column
Yuki Kimoto authored on 2013-04-18
104
    {table => 'project', primary_key => ['user_id', 'name']},
add collaborator register lo...
Yuki Kimoto authored on 2013-11-17
105
    {table => 'number', primary_key => 'key'},
106
    {table => 'collaboration', primary_key => ['user_id', 'project_name', 'collaborator_id']}
improved create repository f...
Yuki Kimoto authored on 2013-03-21
107
  ];
108
  $dbi->create_model($_) for @$models;
109

            
110
  # Validator
rename validator to vc to up...
Yuki Kimoto authored on 2013-12-02
111
  my $vc = Validator::Custom->new;
112
  $self->vc($vc);
113
  $vc->register_constraint(
added project delete feature
Yuki Kimoto authored on 2013-03-24
114
    user_name => sub {
115
      my $value = shift;
116
      
117
      return ($value || '') =~ /^[a-zA-Z0-9_\-]+$/
118
    },
119
    project_name => sub {
120
      my $value = shift;
121
      
122
      return ($value || '') =~ /^[a-zA-Z0-9_\-]+$/
123
    }
124
  );
improved create repository f...
Yuki Kimoto authored on 2013-03-21
125
  
fixed receive pack bug and a...
Yuki Kimoto authored on 2013-10-03
126
  # Basic auth plugin
127
  $self->plugin('BasicAuth');
added admin user tests
Yuki Kimoto authored on 2013-05-17
128

            
cleanup
Yuki Kimoto authored on 2013-05-14
129
  # Routes
Auto Route system catch up w...
Yuki Kimoto authored on 2013-05-18
130
  sub template {
131
    my $template = shift;
132
    
cleanup
Yuki Kimoto authored on 2013-05-19
133
    return sub { shift->render($template, , 'mojo.maybe' => 1) };
Auto Route system catch up w...
Yuki Kimoto authored on 2013-05-18
134
  }
135
  
added login page
Yuki Kimoto authored on 2013-02-09
136
  {
cleanup
Yuki Kimoto authored on 2013-05-14
137
    my $r = $self->routes;
138

            
139
    # DBViewer(only development)
140
    if ($self->mode eq 'development') {
141
      eval {
142
        $self->plugin(
143
          'DBViewer',
144
          dsn => "dbi:SQLite:database=$db_file"
145
        );
146
      };
added reset password feature
Yuki Kimoto authored on 2013-04-10
147
    }
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
148
    
cleanup
Yuki Kimoto authored on 2013-05-14
149
    # Auto route
cleanup many pages
Yuki Kimoto authored on 2013-03-31
150
    {
cleanup
Yuki Kimoto authored on 2013-05-14
151
      my $r = $r->under(sub {
152
        my $self = shift;
153
        
154
        my $api = $self->gitprep_api;
155
        
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
156
        # Authentication
cleanup
Yuki Kimoto authored on 2013-05-14
157
        {
158
          my $path = $self->req->url->path->parts->[0] || '';
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
159
          
160
          # Admin
cleanup
Yuki Kimoto authored on 2013-05-14
161
          if ($path eq '_admin' && !$api->logined_admin) {
162
            $self->redirect_to('/');
163
            return;
164
          }
165
        }
166
        
167
        return 1; 
168
      });
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
169
      
170
      # Auto routes
cleanup
Yuki Kimoto authored on 2013-05-14
171
      $self->plugin('AutoRoute', route => $r);
improved repository page des...
Yuki Kimoto authored on 2012-11-23
172

            
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
173
      # Custom routes
cleanup
Yuki Kimoto authored on 2013-05-14
174
      {
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
175
        my $id_re = qr/[a-zA-Z0-9_-]+/;
cleanup
Yuki Kimoto authored on 2013-05-14
176
        
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
177
        # User
178
        my $r = $r->route('/:user', user => $id_re);
179
        {
180
          # Home
181
          $r->get('/' => template '/user');
182
          
183
          # Settings
184
          $r->get('/_settings' => template '/user-settings');
185
        }
add /info/refs request
Yuki Kimoto authored on 2013-10-01
186

            
187
        # Smart HTTP
188
        {
189
          my $r = $r->route('/(:project).git', project => $id_re);
190
          
fixed receive pack bug and a...
Yuki Kimoto authored on 2013-10-03
191
          {
192
            my $r = $r->under(sub {
193
              my $self = shift;
194
              
cleanup
Yuki Kimoto authored on 2013-11-16
195
              my $api = $self->gitprep_api;
complete private repository ...
Yuki Kimoto authored on 2013-11-16
196
              my $user = $self->param('user');
197
              my $project = $self->param('project');
198
              my $private = $self->app->manager->is_private_project($user, $project);
cleanup
Yuki Kimoto authored on 2013-11-16
199
              
fixed receive pack bug and a...
Yuki Kimoto authored on 2013-10-03
200
              # Basic auth when push request
201
              my $service = $self->param('service') || '';
complete private repository ...
Yuki Kimoto authored on 2013-11-16
202
              if ($service eq 'git-receive-pack' || $private) {
fixed receive pack bug and a...
Yuki Kimoto authored on 2013-10-03
203
                
204
                $self->basic_auth("Git Area", sub {
complete private repository ...
Yuki Kimoto authored on 2013-11-16
205
                  my ($auth_user, $auth_password) = @_;
fix warnings
Yuki Kimoto authored on 2013-11-18
206
                  $auth_user = '' unless defined $auth_user;
207
                  $auth_password = '' unless defined $auth_password;
fixed receive pack bug and a...
Yuki Kimoto authored on 2013-10-03
208
                  
complete collaborator featur...
Yuki Kimoto authored on 2013-11-17
209
                  my $is_valid =
210
                    ($user eq $auth_user || $api->is_collaborator($user, $project, $auth_user))
211
                    && $api->check_user_and_password($auth_user, $auth_password);
fixed receive pack bug and a...
Yuki Kimoto authored on 2013-10-03
212
                  
213
                  return $is_valid;
214
                });
215
              }
216
              else {
217
                return 1;
218
              }
219
            });
220
            
221
            # /info/refs
222
            $r->get('/info/refs' => template 'smart-http/info-refs');
223
            
224
            # /git-upload-pack or /git-receive-pack
225
            $r->any('/git-(:service)'
226
              => [service => qr/(?:upload-pack|receive-pack)/]
227
              => template 'smart-http/service'
228
            );
229
            
230
            # Static file
231
            $r->get('/(*Path)' => template 'smart-http/static');
232
          }
add /info/refs request
Yuki Kimoto authored on 2013-10-01
233
        }
234
                
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
235
        # Project
236
        {
237
          my $r = $r->route('/:project', project => $id_re);
238
          
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
239
          {
240
            my $r = $r->under(sub {
241
              my $self = shift;
242
              
cleanup
Yuki Kimoto authored on 2013-11-16
243
              # API
244
              my $api = $self->gitprep_api;
improve code structures
Yuki Kimoto authored on 2013-11-19
245
              
246
              # Private
revert encoding support
Yuki Kimoto authored on 2013-11-22
247
              my $user = $self->param('user');
248
              my $project = $self->param('project');
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
249
              my $private = $self->app->manager->is_private_project($user, $project);
250
              if ($private) {
complete collaborator featur...
Yuki Kimoto authored on 2013-11-17
251
                if ($api->can_access_private_project($user, $project)) {
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
252
                  return 1;
253
                }
254
                else {
255
                  $self->render('private');
256
                  return 0;
257
                }
258
              }
259
              else {
260
                return 1;
261
              }
262
            });
263
            
264
            # Home
265
            $r->get('/' => template '/project');
266
            
267
            # Commit
268
            $r->get('/commit/*diff' => template '/commit');
269
            
270
            # Commits
271
            $r->get('/commits/*rev_file' => template '/commits');
272
            
273
            # Branches
274
            $r->any('/branches/*base_branch' => {base_branch => undef} => template '/branches');
added feature that you see p...
Yuki Kimoto authored on 2013-04-11
275

            
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
276
            # Tags
277
            $r->get('/tags' => template '/tags');
improved network page
Yuki Kimoto authored on 2013-04-16
278

            
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
279
            # Tree
280
            $r->get('/tree/*rev_dir' => template '/tree');
281
            
282
            # Blob
283
            $r->get('/blob/*rev_file' => template '/blob');
284
            
285
            # Sub module
286
            $r->get('/submodule/*rev_file' => template '/submodule');
add blame method
Yuki Kimoto authored on 2013-08-10
287

            
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
288
            # Raw
289
            $r->get('/raw/*rev_file' => template '/raw');
add blame method
Yuki Kimoto authored on 2013-08-10
290

            
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
291
            # Blame
292
            $r->get('/blame/*rev_file' => template '/blame');
293
            
294
            # Archive
295
            $r->get('/archive/(*rev).tar.gz' => template '/archive')->to(archive_type => 'tar');
296
            $r->get('/archive/(*rev).zip' => template '/archive')->to(archive_type => 'zip' );
297
            
298
            # Compare
299
            $r->get('/compare/(*rev1)...(*rev2)' => template '/compare');
300
            
301
            # Settings
302
            $r->any('/settings' => template '/settings');
303
            
add collaboration page
Yuki Kimoto authored on 2013-11-17
304
            # Collaboration
305
            $r->any('/settings/collaboration' => template '/settings/collaboration');
306
            
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
307
            # Fork
308
            $r->any('/fork' => template '/fork');
cleanup
Yuki Kimoto authored on 2013-05-14
309

            
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
310
            # Network
311
            $r->get('/network' => template '/network');
cleanup
Yuki Kimoto authored on 2013-05-14
312

            
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
313
            # Network Graph
314
            $r->get('/network/graph/(*rev1)...(*rev2_abs)' => template '/network/graph');
add pull page design
Yuki Kimoto authored on 2013-08-13
315

            
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
316
            # Import branch
317
            $r->any('/import-branch/:remote_user/:remote_project' => template '/import-branch');
318
            
319
            # Get branches and tags
320
            $r->get('/api/revs' => template '/api/revs');
321
          }
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
322
        }
cleanup
Yuki Kimoto authored on 2013-05-14
323
      }
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
324
    }
325
  }
added admin user tests
Yuki Kimoto authored on 2013-05-17
326

            
327
  # Helper
328
  {
329
    # API
330
    $self->helper(gitprep_api => sub { Gitprep::API->new(shift) });
331
  }
added reverse proxy path_dep...
Yuki Kimoto authored on 2013-04-22
332
  
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
333
  # Reverse proxy support
added reverse proxy path_dep...
Yuki Kimoto authored on 2013-04-22
334
  my $reverse_proxy_on = $self->config->{reverse_proxy}{on};
335
  my $path_depth = $self->config->{reverse_proxy}{path_depth};
336
  if ($reverse_proxy_on) {
337
    $ENV{MOJO_REVERSE_PROXY} = 1;
338
    if ($path_depth) {
339
      $self->hook('before_dispatch' => sub {
340
        my $self = shift;
341
        for (1 .. $path_depth) {
342
          my $prefix = shift @{$self->req->url->path->parts};
343
          push @{$self->req->url->base->path->parts}, $prefix;
344
        }
345
      });
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
346
    }
added reverse proxy path_dep...
Yuki Kimoto authored on 2013-04-22
347
  }
cleanup
Yuki Kimoto authored on 2013-10-11
348
  
349
  # Smart HTTP Buffer size
350
  $ENV{GITPREP_SMART_HTTP_BUFFER_SIZE} ||= 8192;
copy gitweblite soruce code
root authored on 2012-11-23
351
}
352

            
353
1;