gitprep / lib / Gitprep.pm /
Newer Older
562 lines | 16.78kb
GitPrep 2 need Perl 5.10
Yuki Kimoto authored on 2016-03-28
1
use 5.010001;
renamed gitpub to gitprep
Yuki Kimoto authored on 2012-11-26
2
package Gitprep;
copy gitweblite soruce code
root authored on 2012-11-23
3
use Mojo::Base 'Mojolicious';
cleanup
Yuki Kimoto authored on 2013-05-14
4

            
5
use Carp 'croak';
added start page
Yuki Kimoto authored on 2013-02-09
6
use DBIx::Custom;
little more secure login
Yuki Kimoto authored on 2013-03-16
7
use Gitprep::API;
cleanup
Yuki Kimoto authored on 2013-05-14
8
use Gitprep::Git;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
9
use Gitprep::Manager;
added RepManager rename feat...
Yuki Kimoto authored on 2013-03-27
10
use Scalar::Util 'weaken';
cleanup
Yuki Kimoto authored on 2013-05-14
11
use Validator::Custom;
add Time::Moment to cpanfil
Yuki Kimoto authored on 2016-04-20
12
use Time::Moment;
fix bug that in CGI reposito...
Yuki Kimoto authored on 2015-11-05
13

            
Digest::SHA loading to Mojo:...
Yuki Kimoto authored on 2013-08-13
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

            
add changes and version up t...
Yuki Kimoto authored on 2016-06-04
20
our $VERSION = 'v2.2';
cleanup
Yuki Kimoto authored on 2013-05-14
21

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

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

            
add repository and work repo...
Yuki Kimoto authored on 2016-04-14
29
sub data_dir {
30
  my $self = shift;
31
  
32
  my $data_dir = $self->config('data_dir');
33
  
34
  return $data_dir;
35
}
36

            
cleanup
Yuki Kimoto authored on 2016-04-16
37
sub rep_home {
38
  my $self = shift;
39
  
40
  my $rep_home = $self->data_dir . "/rep";
41
  
42
  return $rep_home;
43
}
44

            
cleanup branch
Yuki Kimoto authored on 2016-04-16
45
sub rep_info {
change is_collaborator argum...
Yuki Kimoto authored on 2016-04-23
46
  my ($self, $user_id, $project_id) = @_;
cleanup branch
Yuki Kimoto authored on 2016-04-16
47
  
48
  my $info = {};
change is_collaborator argum...
Yuki Kimoto authored on 2016-04-23
49
  $info->{user} = $user_id;
50
  $info->{project} = $project_id;
51
  $info->{git_dir} = $self->rep_home . "/$user_id/$project_id.git";
cleanup branch
Yuki Kimoto authored on 2016-04-16
52
  
53
  return $info;
54
}
55

            
cleanup
Yuki Kimoto authored on 2016-04-16
56
sub work_rep_home {
57
  my $self = shift;
58
  
59
  my $work_rep_home = $self->data_dir . "/work";
60
  
61
  return $work_rep_home;
62
}
63

            
cleanup create working direc...
Yuki Kimoto authored on 2016-04-16
64
sub work_rep_info {
change is_collaborator argum...
Yuki Kimoto authored on 2016-04-23
65
  my ($self, $user_id, $project_id) = @_;
cleanup create working direc...
Yuki Kimoto authored on 2016-04-16
66
  
67
  my $info = {};
change is_collaborator argum...
Yuki Kimoto authored on 2016-04-23
68
  $info->{user} = $user_id;
69
  $info->{project} = $project_id;
70
  $info->{git_dir} = $self->work_rep_home . "/$user_id/$project_id/.git";
71
  $info->{work_tree} = $self->work_rep_home . "/$user_id/$project_id";
cleanup create working direc...
Yuki Kimoto authored on 2016-04-16
72
  
73
  return $info;
74
}
75

            
copy gitweblite soruce code
root authored on 2012-11-23
76
sub startup {
77
  my $self = shift;
78
  
cleanup
Yuki Kimoto authored on 2013-05-14
79
  # Config file
update Mojolicious and added...
Yuki Kimoto authored on 2013-03-20
80
  $self->plugin('INIConfig', {ext => 'conf'});
81
  
cleanup
Yuki Kimoto authored on 2013-05-14
82
  # Config file for developper
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
83
  unless ($ENV{GITPREP_NO_MYCONFIG}) {
84
    my $my_conf_file = $self->home->rel_file('gitprep.my.conf');
85
    $self->plugin('INIConfig', {file => $my_conf_file}) if -f $my_conf_file;
86
  }
update Mojolicious and added...
Yuki Kimoto authored on 2013-03-20
87
  
cleanup
Yuki Kimoto authored on 2013-05-14
88
  # Listen
copy gitweblite soruce code
root authored on 2012-11-23
89
  my $conf = $self->config;
cleanup
Yuki Kimoto authored on 2013-05-14
90
  my $listen = $conf->{hypnotoad}{listen} ||= ['http://*:10020'];
91
  $listen = [split /,/, $listen] unless ref $listen eq 'ARRAY';
fixed listen bug
Yuki Kimoto authored on 2013-03-29
92
  $conf->{hypnotoad}{listen} = $listen;
copy gitweblite soruce code
root authored on 2012-11-23
93
  
add repository and work repo...
Yuki Kimoto authored on 2016-04-14
94
  # Data directory
fix tests
Yuki Kimoto authored on 2016-04-14
95
  my $data_dir = $ENV{GITPREP_DATA_DIR} ? $ENV{GITPREP_DATA_DIR} : $self->home->rel_file('data');
96
  $self->config(data_dir => $data_dir);
add repository and work repo...
Yuki Kimoto authored on 2016-04-14
97
  
revert encoding support
Yuki Kimoto authored on 2013-11-22
98
  # Git
renamed gitpub to gitprep
Yuki Kimoto authored on 2012-11-26
99
  my $git = Gitprep::Git->new;
cleanup encoding
Yuki Kimoto authored on 2016-04-05
100
  $git->app($self);
101
  weaken $git->{app};
cleanup
Yuki Kimoto authored on 2013-05-14
102
  my $git_bin
103
    = $conf->{basic}{git_bin} ? $conf->{basic}{git_bin} : $git->search_bin;
fix mini bug
Yuki Kimoto authored on 2013-03-31
104
  if (!$git_bin || ! -e $git_bin) {
105
    $git_bin ||= '';
cleanup
Yuki Kimoto authored on 2013-05-14
106
    my $error = "Can't detect or found git command ($git_bin)."
107
      . " set git_bin in gitprep.conf";
fixed git_bin not found bug
Yuki Kimoto authored on 2013-03-31
108
    $self->log->error($error);
109
    croak $error;
110
  }
improve code structures
Yuki Kimoto authored on 2013-11-19
111
  $git->bin($git_bin);
revert encoding support
Yuki Kimoto authored on 2013-11-22
112
  
113
  # Repository Manager
cleanup encoding
Yuki Kimoto authored on 2016-04-05
114
  my $manager = Gitprep::Manager->new;
115
  $manager->app($self);
revert encoding support
Yuki Kimoto authored on 2013-11-22
116
  weaken $manager->{app};
117
  $self->manager($manager);
118
  
add key delete feature and u...
gitprep authored on 2014-05-19
119
  # authorized_keys file
fix authorized_keys_file bug
Yuki Kimoto authored on 2015-11-04
120
  my $authorized_keys_file = $conf->{basic}{authorized_keys_file};
add key delete feature and u...
gitprep authored on 2014-05-19
121
  unless (defined $authorized_keys_file) {
122
    if (defined $ENV{HOME}) {
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
123
      $authorized_keys_file = "$ENV{HOME}/.ssh/authorized_keys";
add key delete feature and u...
gitprep authored on 2014-05-19
124
    }
125
  }
126
  if (defined $authorized_keys_file) {
127
    $self->manager->authorized_keys_file($authorized_keys_file);
128
  }
129
  else {
130
    $self->app->log->warn(qq/Config "authorized_keys_file" can't be detected/);
131
  }
132
  
fixed git_bin not found bug
Yuki Kimoto authored on 2013-03-31
133
  # Repository home
cleanup tests
Yuki Kimoto authored on 2016-04-16
134
  my $rep_home = "$data_dir/rep";
added create repository feat...
Yuki Kimoto authored on 2013-03-18
135
  unless (-d $rep_home) {
136
    mkdir $rep_home
137
      or croak "Can't create directory $rep_home: $!";
138
  }
cleanup
Yuki Kimoto authored on 2013-05-14
139
  
add time zone system
Yuki Kimoto authored on 2014-03-08
140
  # Time Zone
141
  if (my $time_zone = $conf->{basic}{time_zone}) {
142
    
143
    if ($time_zone =~ /^([\+-])?([0-9]?[0-9]):([0-9][0-9])$/) {
144
      my $sign = $1 || '';
145
      my $hour = $2;
146
      my $min = $3;
147
      
148
      my $time_zone_second = $sign . ($hour * 60 * 60) + ($min * 60);
149
      $git->time_zone_second($time_zone_second);
150
    }
151
    else {
152
      $self->log->warn("Bad time zone $time_zone. Time zone become GMT");
153
    }
154
  }
155
  $self->git($git);
cleanup
Yuki Kimoto authored on 2013-05-14
156
  
improved create repository f...
Yuki Kimoto authored on 2013-03-21
157
  # DBI
cleanup tests
Yuki Kimoto authored on 2016-04-16
158
  my $db_file = "$data_dir/gitprep.db";
improved create repository f...
Yuki Kimoto authored on 2013-03-21
159
  my $dbi = DBIx::Custom->connect(
160
    dsn => "dbi:SQLite:database=$db_file",
161
    connector => 1,
added original_pid column
Yuki Kimoto authored on 2013-04-18
162
    option => {sqlite_unicode => 1, sqlite_use_immediate_transaction => 1}
improved create repository f...
Yuki Kimoto authored on 2013-03-21
163
  );
164
  $self->dbi($dbi);
165
  
cleanup
Yuki Kimoto authored on 2013-05-14
166
  # Database file permision
change is_collaborator argum...
Yuki Kimoto authored on 2016-04-23
167
  if (my $user_id = $self->config->{hypnotoad}{user}) {
168
    my $uid = (getpwnam $user_id)[2];
fixed database file permissi...
Yuki Kimoto authored on 2013-04-19
169
    chown $uid, -1, $db_file;
170
  }
171
  if (my $group = $self->config->{hypnotoad}{group}) {
172
    my $gid = (getgrnam $group)[2];
173
    chown -1, $gid, $db_file;
174
  }
175
  
improved create repository f...
Yuki Kimoto authored on 2013-03-21
176
  # Model
177
  my $models = [
fix project page
Yuki Kimoto authored on 2016-04-21
178
    {
179
      table => 'user',
180
      primary_key => 'row_id'
181
    },
182
    {
183
      table => 'ssh_public_key',
184
      primary_key => 'row_id',
185
      join => [
issue belong to project
Yuki Kimoto authored on 2016-06-11
186
        'left join user on ssh_public_key.user = user.row_id'
fix project page
Yuki Kimoto authored on 2016-04-21
187
      ]
188
    },
189
    {
190
      table => 'project',
191
      primary_key => 'row_id',
192
      join => [
issue belong to project
Yuki Kimoto authored on 2016-06-11
193
        'left join user on project.user = user.row_id'
fix project page
Yuki Kimoto authored on 2016-04-21
194
      ]
195
    },
196
    {
197
      table => 'collaboration',
198
      primary_key => 'row_id',
199
      join => [
issue belong to project
Yuki Kimoto authored on 2016-06-11
200
        'left join user on collaboration.user = user.row_id',
201
        'left join project on collaboration.project = project.row_id',
fix project page
Yuki Kimoto authored on 2016-04-21
202
      ]
203
    },
fix pulls page
Yuki Kimoto authored on 2016-06-09
204
    {
205
      table => 'issue',
206
      join => [
issue belong to project
Yuki Kimoto authored on 2016-06-11
207
        'left join project on issue.project = project.row_id',
208
        'left join pull_request on issue.pull_request = pull_request.row_id',
remove table __ prefix
Yuki Kimoto authored on 2016-06-11
209
        'left join user as open_user on issue.open_user = open_user.row_id',
210
        'left join project as pull_request__base_project on pull_request.base_project = pull_request__base_project.row_id',
211
        'left join user as pull_request__base_project__user'
212
          . ' on pull_request__base_project.user = pull_request__base_project__user.row_id',
213
        'left join project as pull_request__target_project on pull_request.target_project = pull_request__target_project.row_id',
214
        'left join user as pull_request__target_project__user'
215
          . ' on pull_request__target_project.user = pull_request__target_project__user.row_id'
fix pulls page
Yuki Kimoto authored on 2016-06-09
216

            
217
      ]
218
    },
219
    {
220
      table => 'issue_message',
221
      primary_key => 'row_id',
222
      join => [
issue belong to project
Yuki Kimoto authored on 2016-06-11
223
        'left join user on issue_message.user = user.row_id',
224
        'left join issue on issue_message.issue = issue.row_id'
fix pulls page
Yuki Kimoto authored on 2016-06-09
225
      ]
226
    },
add pulls description
Yuki Kimoto authored on 2016-04-20
227
    {
228
      table => 'pull_request',
fix project page
Yuki Kimoto authored on 2016-04-21
229
      primary_key => 'row_id',
230
      join => [
remove table __ prefix
Yuki Kimoto authored on 2016-06-11
231
        'left join user as open_user on pull_request.open_user = open_user.row_id',
232
        'left join project as base_project on pull_request.base_project = base_project.row_id',
233
        'left join user as base_project__user'
234
          . ' on base_project.user = base_project__user.row_id',
235
        'left join project as target_project on pull_request.target_project = target_project.row_id',
fix pull_request table bug
Yuki Kimoto authored on 2016-04-27
236
        'left join user as pull_request__target_project__user'
remove table __ prefix
Yuki Kimoto authored on 2016-06-11
237
          . ' on target_project.user = target_project__user.row_id'
fix project page
Yuki Kimoto authored on 2016-04-21
238
      ]
add pull request message log...
Yuki Kimoto authored on 2016-04-23
239
    },
improved create repository f...
Yuki Kimoto authored on 2013-03-21
240
  ];
241
  $dbi->create_model($_) for @$models;
add pulls description
Yuki Kimoto authored on 2016-04-20
242
  $dbi->setup_model;
improved create repository f...
Yuki Kimoto authored on 2013-03-21
243

            
244
  # Validator
rename validator to vc to up...
Yuki Kimoto authored on 2013-12-02
245
  my $vc = Validator::Custom->new;
246
  $self->vc($vc);
247
  $vc->register_constraint(
added project delete feature
Yuki Kimoto authored on 2013-03-24
248
    user_name => sub {
249
      my $value = shift;
250
      
allow . as project name
Yuki Kimoto authored on 2014-04-21
251
      return ($value || '') =~ /^[a-zA-Z0-9_\-]+$/;
added project delete feature
Yuki Kimoto authored on 2013-03-24
252
    },
253
    project_name => sub {
254
      my $value = shift;
allow . as project name
Yuki Kimoto authored on 2014-04-21
255
      return 0 unless defined $value;
256
      return 0 if $value eq '.' || $value eq '..';
257

            
258
      return ($value || '') =~ /[a-zA-Z0-9_\-\.]+$/;
added project delete feature
Yuki Kimoto authored on 2013-03-24
259
    }
260
  );
improved create repository f...
Yuki Kimoto authored on 2013-03-21
261
  
cleanup setting validation
Yuki Kimoto authored on 2016-02-09
262
  $vc->add_check(project_name => sub {
263
    my ($vc, $value) = @_;
264
    
265
    return 0 unless defined $value;
266
    return 0 if $value eq '.' || $value eq '..';
267
    
268
    return ($value || '') =~ /[a-zA-Z0-9_\-\.]+$/;
269
  });
cleanup create user validati...
Yuki Kimoto authored on 2016-02-09
270
  $vc->add_check(user_name => sub {
271
    my ($vc, $value) = @_;
272
    
273
    return ($value || '') =~ /^[a-zA-Z0-9_\-]+$/;
274
  });
cleanup setting validation
Yuki Kimoto authored on 2016-02-09
275
  
fixed receive pack bug and a...
Yuki Kimoto authored on 2013-10-03
276
  # Basic auth plugin
277
  $self->plugin('BasicAuth');
added admin user tests
Yuki Kimoto authored on 2013-05-17
278

            
added login page
Yuki Kimoto authored on 2013-02-09
279
  {
cleanup
Yuki Kimoto authored on 2013-05-14
280
    my $r = $self->routes;
281

            
282
    # DBViewer(only development)
add Mojolicious::Plugin::DBV...
Yuki Kimoto authored on 2016-03-26
283
    # /dbviewer
cleanup
Yuki Kimoto authored on 2013-05-14
284
    if ($self->mode eq 'development') {
285
      eval {
286
        $self->plugin(
287
          'DBViewer',
288
          dsn => "dbi:SQLite:database=$db_file"
289
        );
290
      };
added reset password feature
Yuki Kimoto authored on 2013-04-10
291
    }
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
292
    
cleanup
Yuki Kimoto authored on 2013-05-14
293
    # Auto route
cleanup many pages
Yuki Kimoto authored on 2013-03-31
294
    {
cleanup
Yuki Kimoto authored on 2013-05-14
295
      my $r = $r->under(sub {
296
        my $self = shift;
297
        
298
        my $api = $self->gitprep_api;
299
        
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
300
        # Authentication
cleanup
Yuki Kimoto authored on 2013-05-14
301
        {
302
          my $path = $self->req->url->path->parts->[0] || '';
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
303
          
304
          # Admin
cleanup
Yuki Kimoto authored on 2013-05-14
305
          if ($path eq '_admin' && !$api->logined_admin) {
306
            $self->redirect_to('/');
307
            return;
308
          }
309
        }
310
        
311
        return 1; 
312
      });
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
313
      
314
      # Auto routes
cleanup
Yuki Kimoto authored on 2013-05-14
315
      $self->plugin('AutoRoute', route => $r);
fix bug that forst . is not ...
Yuki Kimoto authored on 2014-04-21
316
      
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
317
      # Custom routes
cleanup
Yuki Kimoto authored on 2013-05-14
318
      {
add ssh key add feature
gitprep authored on 2014-05-17
319
        # Show ssh keys
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
320
        $r->get('/(:user).keys' => sub { shift->render_maybe('/user-keys') });
add ssh key add feature
gitprep authored on 2014-05-17
321
        
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
322
        # User
allow . as project name
Yuki Kimoto authored on 2014-04-21
323
        my $r = $r->route('/:user');
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
324
        {
325
          # Home
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
326
          $r->get('/' => [format => 0] => sub { shift->render_maybe('/user') });
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
327
          
328
          # Settings
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
329
          $r->get('/_settings' => sub { shift->render_maybe('/user-settings') });
add ssh keys page design
gitprep authored on 2014-05-17
330
          
331
          # SSH keys
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
332
          $r->any('/_settings/ssh' => sub { shift->render_maybe('/user-settings/ssh') });
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
333
        }
add /info/refs request
Yuki Kimoto authored on 2013-10-01
334

            
335
        # Smart HTTP
336
        {
allow . as project name
Yuki Kimoto authored on 2014-04-21
337
          my $r = $r->route('/(#project).git');
add /info/refs request
Yuki Kimoto authored on 2013-10-01
338
          
fixed receive pack bug and a...
Yuki Kimoto authored on 2013-10-03
339
          {
340
            my $r = $r->under(sub {
341
              my $self = shift;
342
              
cleanup
Yuki Kimoto authored on 2013-11-16
343
              my $api = $self->gitprep_api;
change is_collaborator argum...
Yuki Kimoto authored on 2016-04-23
344
              my $user_id = $self->param('user');
345
              my $project_id = $self->param('project');
346
              my $private = $self->app->manager->is_private_project($user_id, $project_id);
cleanup
Yuki Kimoto authored on 2013-11-16
347
              
fixed receive pack bug and a...
Yuki Kimoto authored on 2013-10-03
348
              # Basic auth when push request
349
              my $service = $self->param('service') || '';
complete private repository ...
Yuki Kimoto authored on 2013-11-16
350
              if ($service eq 'git-receive-pack' || $private) {
fixed receive pack bug and a...
Yuki Kimoto authored on 2013-10-03
351
                
352
                $self->basic_auth("Git Area", sub {
change is_collaborator argum...
Yuki Kimoto authored on 2016-04-23
353
                  my ($auth_user_id, $auth_password) = @_;
add warnings when authentica...
Yuki Kimoto authored on 2014-02-18
354
                  
change is_collaborator argum...
Yuki Kimoto authored on 2016-04-23
355
                  if (!defined $auth_user_id || !length $auth_user_id) {
add warnings when authentica...
Yuki Kimoto authored on 2014-02-18
356
                    $self->app->log->warn("Authentication: User name is empty");
357
                  }
358
                  
change is_collaborator argum...
Yuki Kimoto authored on 2016-04-23
359
                  $auth_user_id = '' unless defined $auth_user_id;
fix warnings
Yuki Kimoto authored on 2013-11-18
360
                  $auth_password = '' unless defined $auth_password;
fixed receive pack bug and a...
Yuki Kimoto authored on 2013-10-03
361
                  
complete collaborator featur...
Yuki Kimoto authored on 2013-11-17
362
                  my $is_valid =
change is_collaborator argum...
Yuki Kimoto authored on 2016-04-23
363
                    ($user_id eq $auth_user_id || $api->is_collaborator($auth_user_id, $user_id, $project_id))
364
                    && $api->check_user_and_password($auth_user_id, $auth_password);
fixed receive pack bug and a...
Yuki Kimoto authored on 2013-10-03
365
                  
366
                  return $is_valid;
367
                });
368
              }
369
              else {
370
                return 1;
371
              }
372
            });
373
            
redirect .git access to /use...
Yuki Kimoto authored on 2014-02-26
374
            # /
375
            $r->get('/')->to(cb => sub {
376
              my $self = shift;
377
              
change is_collaborator argum...
Yuki Kimoto authored on 2016-04-23
378
              my $user_id = $self->param('user');
379
              my $project_id = $self->param('project');
redirect .git access to /use...
Yuki Kimoto authored on 2014-02-26
380
              
change is_collaborator argum...
Yuki Kimoto authored on 2016-04-23
381
              $self->redirect_to("/$user_id/$project_id");
redirect .git access to /use...
Yuki Kimoto authored on 2014-02-26
382
            });
383
            
fixed receive pack bug and a...
Yuki Kimoto authored on 2013-10-03
384
            # /info/refs
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
385
            $r->get('/info/refs' => sub { shift->render_maybe('smart-http/info-refs') });
fixed receive pack bug and a...
Yuki Kimoto authored on 2013-10-03
386
            
387
            # /git-upload-pack or /git-receive-pack
388
            $r->any('/git-(:service)'
389
              => [service => qr/(?:upload-pack|receive-pack)/]
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
390
              => sub { shift->render_maybe('smart-http/service') }
fixed receive pack bug and a...
Yuki Kimoto authored on 2013-10-03
391
            );
392
            
393
            # Static file
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
394
            $r->get('/(*Path)' => sub { shift->render_maybe('smart-http/static') });
fixed receive pack bug and a...
Yuki Kimoto authored on 2013-10-03
395
          }
add /info/refs request
Yuki Kimoto authored on 2013-10-01
396
        }
397
                
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
398
        # Project
399
        {
allow . as project name
Yuki Kimoto authored on 2014-04-21
400
          my $r = $r->route('/#project');
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
401
          
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
402
          {
403
            my $r = $r->under(sub {
404
              my $self = shift;
405
              
cleanup
Yuki Kimoto authored on 2013-11-16
406
              # API
407
              my $api = $self->gitprep_api;
improve code structures
Yuki Kimoto authored on 2013-11-19
408
              
409
              # Private
change is_collaborator argum...
Yuki Kimoto authored on 2016-04-23
410
              my $user_id = $self->param('user');
411
              my $project_id = $self->param('project');
412
              my $private = $self->app->manager->is_private_project($user_id, $project_id);
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
413
              if ($private) {
change is_collaborator argum...
Yuki Kimoto authored on 2016-04-23
414
                if ($api->can_access_private_project($user_id, $project_id)) {
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
415
                  return 1;
416
                }
417
                else {
418
                  $self->render('private');
419
                  return 0;
420
                }
421
              }
422
              else {
423
                return 1;
424
              }
425
            });
426
            
427
            # Home
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
428
            $r->get('/' => sub { shift->render_maybe('/tree') });
add issue page
Yuki Kimoto authored on 2016-06-06
429
            
430
            # Issue
431
            $r->get('/issues' => sub { shift->render_maybe('/issues') })->to(tab => 'issues');
432
            
improve pull page design
Yuki Kimoto authored on 2016-04-21
433
            # Pull requests
add pulls page
Yuki Kimoto authored on 2016-04-12
434
            $r->get('/pulls' => sub { shift->render_maybe('/pulls') })->to(tab => 'pulls');
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
435
            
improve pull page design
Yuki Kimoto authored on 2016-04-21
436
            # Pull request
add patch feature
Yuki Kimoto authored on 2016-06-04
437
            $r->get('/pull/(:row_id).patch' => sub { shift->render_maybe('/pull') })->to(tab => 'pulls', patch => 1);
improve pull page design
Yuki Kimoto authored on 2016-04-21
438
            $r->any('/pull/:row_id' => sub { shift->render_maybe('/pull') })->to(tab => 'pulls');
439
            
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
440
            # Commit
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
441
            $r->get('/commit/*diff' => sub { shift->render_maybe('/commit') });
add atom feed part
Yuki Kimoto authored on 2014-10-02
442

            
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
443
            # Commits
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
444
            $r->get('/commits/*rev_file' => sub { shift->render_maybe('/commits') });
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
445
            
446
            # Branches
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
447
            $r->any('/branches/:display' => {display => undef} => sub { shift->render_maybe('/branches') });
added feature that you see p...
Yuki Kimoto authored on 2013-04-11
448

            
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
449
            # Tags
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
450
            $r->get('/tags' => sub { shift->render_maybe('/tags') });
improved network page
Yuki Kimoto authored on 2013-04-16
451

            
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
452
            # Tree
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
453
            $r->get('/tree/*rev_dir' => sub { shift->render_maybe('/tree') });
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
454
            
455
            # Blob
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
456
            $r->get('/blob/*rev_file' => sub { shift->render_maybe('/blob') });
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
457
            
458
            # Sub module
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
459
            $r->get('/submodule/*rev_file' => sub { shift->render_maybe('/submodule') });
add blame method
Yuki Kimoto authored on 2013-08-10
460

            
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
461
            # Raw
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
462
            $r->get('/raw/*rev_file' => sub { shift->render_maybe('/raw') });
add blame method
Yuki Kimoto authored on 2013-08-10
463

            
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
464
            # Blame
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
465
            $r->get('/blame/*rev_file' => sub { shift->render_maybe('/blame') });
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
466
            
467
            # Archive
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
468
            # Archive
469
            $r->get('/archive/(*rev).tar.gz' => sub { shift->render_maybe('/archive') })->to(archive_type => 'tar');
470
            $r->get('/archive/(*rev).zip' => sub { shift->render_maybe('/archive') })->to(archive_type => 'zip' );
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
471
            
472
            # Compare
add create pull request logi...
Yuki Kimoto authored on 2016-04-19
473
            $r->any('/compare' => sub { shift->render_maybe('/compare') });
474
            $r->any(
cleanup branch
Yuki Kimoto authored on 2016-04-12
475
              '/compare/(:rev1)...(:rev2)'
476
              => [rev1 => qr/[^\.]+/, rev2 => qr/[^\.]+/]
477
              => sub { shift->render_maybe('/compare') }
478
            );
add create pull request logi...
Yuki Kimoto authored on 2016-04-19
479
            $r->any('/compare/(:rev2)' => sub { shift->render_maybe('/compare') });
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
480
            
481
            # Settings
improve tab design
Yuki Kimoto authored on 2016-01-26
482
            {
483
              my $r = $r->route('/settings')->to(tab => 'settings');
484
              
485
              # Settings
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
486
              $r->any('/' => sub { shift->render_maybe('/settings') });
improve tab design
Yuki Kimoto authored on 2016-01-26
487
              
488
              # Collaboration
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
489
              $r->any('/collaboration' => sub { shift->render_maybe('/settings/collaboration') });
improve tab design
Yuki Kimoto authored on 2016-01-26
490
            }
add collaboration page
Yuki Kimoto authored on 2013-11-17
491
            
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
492
            # Fork
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
493
            $r->any('/fork' => sub { shift->render_maybe('/fork') });
improve tab design
Yuki Kimoto authored on 2016-01-26
494
            
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
495
            # Network
improve tab design
Yuki Kimoto authored on 2016-01-26
496
            {
497
              my $r = $r->route('/network')->to(tab => 'graph');
498
              
499
              # Network
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
500
              $r->get('/' => sub { shift->render_maybe('/network') });
cleanup
Yuki Kimoto authored on 2013-05-14
501

            
improve tab design
Yuki Kimoto authored on 2016-01-26
502
              # Network Graph
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
503
              $r->get('/graph/(*rev1)...(*rev2_abs)' => sub { shift->render_maybe('/network/graph') });
improve tab design
Yuki Kimoto authored on 2016-01-26
504
            }
add pull page design
Yuki Kimoto authored on 2013-08-13
505

            
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
506
            # Import branch
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
507
            $r->any('/import-branch/:remote_user/:remote_project' => sub { shift->render_maybe('/import-branch') });
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
508
            
509
            # Get branches and tags
remove Mojolicious::Plugin::...
Yuki Kimoto authored on 2016-03-28
510
            $r->get('/api/revs' => sub { shift->render_maybe('/api/revs') });
add private reporitory featu...
Yuki Kimoto authored on 2013-11-16
511
          }
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
512
        }
cleanup
Yuki Kimoto authored on 2013-05-14
513
      }
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
514
    }
515
  }
added admin user tests
Yuki Kimoto authored on 2013-05-17
516

            
517
  # Helper
518
  {
519
    # API
520
    $self->helper(gitprep_api => sub { Gitprep::API->new(shift) });
521
  }
added reverse proxy path_dep...
Yuki Kimoto authored on 2013-04-22
522
  
X-Forwarded-HTTPS header is ...
Yuki Kimoto authored on 2016-03-28
523
  # set scheme to https when X-Forwarded-HTTPS header is specified
524
  # This is for the backword compatible only. Now X-Forwarded-Proto is used for this purpose
525
  $self->hook(before_dispatch => sub {
526
    my $c = shift;
527
    if ($c->req->headers->header('X-Forwarded-HTTPS')) {
528
      $c->req->url->base->scheme('https');
529
      $c->app->log->warn("X-Forwarded-HTTPS header is DEPRECATED! use X-Forwarded-Proto instead.");
530
    }
531
  });
fix smart http decompress bu...
Yuki Kimoto authored on 2016-04-22
532

            
change is_collaborator argum...
Yuki Kimoto authored on 2016-04-23
533
  # Set auto_decompress for Smart HTTP
534
  # HTTP request body of /smart-http/service is compressed.
535
  # If auto_decompress is not set, Smart HTTP fail.
fix smart http decompress bu...
Yuki Kimoto authored on 2016-04-22
536
  $self->hook('after_build_tx' => sub {
537
    my ($tx, $app) = @_;
538
    
539
    $tx->req->content->auto_decompress(1);
540
  });
541

            
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
542
  # Reverse proxy support
added reverse proxy path_dep...
Yuki Kimoto authored on 2013-04-22
543
  my $reverse_proxy_on = $self->config->{reverse_proxy}{on};
544
  my $path_depth = $self->config->{reverse_proxy}{path_depth};
545
  if ($reverse_proxy_on) {
546
    $ENV{MOJO_REVERSE_PROXY} = 1;
547
    if ($path_depth) {
548
      $self->hook('before_dispatch' => sub {
549
        my $self = shift;
550
        for (1 .. $path_depth) {
551
          my $prefix = shift @{$self->req->url->path->parts};
552
          push @{$self->req->url->base->path->parts}, $prefix;
553
        }
554
      });
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
555
    }
added reverse proxy path_dep...
Yuki Kimoto authored on 2013-04-22
556
  }
cleanup
Yuki Kimoto authored on 2013-10-11
557
  
558
  # Smart HTTP Buffer size
fix bug that lerge repositor...
Yuki Kimoto authored on 2014-02-17
559
  $ENV{GITPREP_SMART_HTTP_BUFFER_SIZE} ||= 16384;
copy gitweblite soruce code
root authored on 2012-11-23
560
}
561

            
562
1;