gitprep / lib / Gitprep.pm /
Newer Older
264 lines | 6.631kb
copy gitweblite soruce code
root authored on 2012-11-23
1
use 5.008007;
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;
added user management featur...
Yuki Kimoto authored on 2013-02-13
7
use Encode qw/encode decode/;
little more secure login
Yuki Kimoto authored on 2013-03-16
8
use Gitprep::API;
cleanup
Yuki Kimoto authored on 2013-05-14
9
use Gitprep::Git;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
10
use Gitprep::Manager;
added RepManager rename feat...
Yuki Kimoto authored on 2013-03-27
11
use Scalar::Util 'weaken';
cleanup
Yuki Kimoto authored on 2013-05-14
12
use Validator::Custom;
copy gitweblite soruce code
root authored on 2012-11-23
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

            
version 1.2 release
Yuki Kimoto authored on 2013-08-21
20
our $VERSION = '1.02';
cleanup
Yuki Kimoto authored on 2013-05-14
21

            
added start page
Yuki Kimoto authored on 2013-02-09
22
has 'dbi';
cleanup
Yuki Kimoto authored on 2013-05-14
23
has 'git';
added RepManager rename feat...
Yuki Kimoto authored on 2013-03-27
24
has 'manager';
cleanup
Yuki Kimoto authored on 2013-05-14
25
has 'validator';
copy gitweblite soruce code
root authored on 2012-11-23
26

            
27
sub startup {
28
  my $self = shift;
29
  
cleanup
Yuki Kimoto authored on 2013-05-14
30
  # Config file
update Mojolicious and added...
Yuki Kimoto authored on 2013-03-20
31
  $self->plugin('INIConfig', {ext => 'conf'});
32
  
cleanup
Yuki Kimoto authored on 2013-05-14
33
  # Config file for developper
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
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...
Yuki Kimoto authored on 2013-03-20
38
  
cleanup
Yuki Kimoto authored on 2013-05-14
39
  # Listen
copy gitweblite soruce code
root authored on 2012-11-23
40
  my $conf = $self->config;
cleanup
Yuki Kimoto authored on 2013-05-14
41
  my $listen = $conf->{hypnotoad}{listen} ||= ['http://*:10020'];
42
  $listen = [split /,/, $listen] unless ref $listen eq 'ARRAY';
fixed listen bug
Yuki Kimoto authored on 2013-03-29
43
  $conf->{hypnotoad}{listen} = $listen;
copy gitweblite soruce code
root authored on 2012-11-23
44
  
cleanup
Yuki Kimoto authored on 2013-05-14
45
  # Git
renamed gitpub to gitprep
Yuki Kimoto authored on 2012-11-26
46
  my $git = Gitprep::Git->new;
cleanup
Yuki Kimoto authored on 2013-05-14
47
  my $git_bin
48
    = $conf->{basic}{git_bin} ? $conf->{basic}{git_bin} : $git->search_bin;
fix mini bug
Yuki Kimoto authored on 2013-03-31
49
  if (!$git_bin || ! -e $git_bin) {
50
    $git_bin ||= '';
cleanup
Yuki Kimoto authored on 2013-05-14
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
Yuki Kimoto authored on 2013-03-31
53
    $self->log->error($error);
54
    croak $error;
55
  }
copy gitweblite soruce code
root authored on 2012-11-23
56
  $git->bin($git_bin);
fix bug that http clone won'...
Yuki Kimoto authored on 2013-04-15
57
  
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
58
  # Repository Manager
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
59
  my $manager = Gitprep::Manager->new(app => $self);
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
60
  weaken $manager->{app};
61
  $self->manager($manager);
fixed git_bin not found bug
Yuki Kimoto authored on 2013-03-31
62
  
63
  # Repository home
cleanup
Yuki Kimoto authored on 2013-05-14
64
  my $rep_home = $ENV{GITPREP_REP_HOME} || $self->home->rel_file('data/rep');
added create repository feat...
Yuki Kimoto authored on 2013-03-18
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
root authored on 2012-11-23
70
  $self->git($git);
cleanup
Yuki Kimoto authored on 2013-05-14
71
  
added test
Yuki Kimoto authored on 2013-04-30
72
  # Added public path
73
  push @{$self->static->paths}, $rep_home;
cleanup
Yuki Kimoto authored on 2013-05-14
74
  
improved create repository f...
Yuki Kimoto authored on 2013-03-21
75
  # DBI
added test
Yuki Kimoto authored on 2013-04-30
76
  my $db_file = $ENV{GITPREP_DB_FILE}
77
    || $self->home->rel_file('data/gitprep.db');
improved create repository f...
Yuki Kimoto authored on 2013-03-21
78
  my $dbi = DBIx::Custom->connect(
79
    dsn => "dbi:SQLite:database=$db_file",
80
    connector => 1,
added original_pid column
Yuki Kimoto authored on 2013-04-18
81
    option => {sqlite_unicode => 1, sqlite_use_immediate_transaction => 1}
improved create repository f...
Yuki Kimoto authored on 2013-03-21
82
  );
83
  $self->dbi($dbi);
84
  
cleanup
Yuki Kimoto authored on 2013-05-14
85
  # Database file permision
fixed database file permissi...
Yuki Kimoto authored on 2013-04-19
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
Yuki Kimoto authored on 2013-04-11
95
  # Setup database
96
  $self->manager->setup_database;
improved create repository f...
Yuki Kimoto authored on 2013-03-21
97
  
98
  # Model
99
  my $models = [
100
    {table => 'user', primary_key => 'id'},
added original_pid column
Yuki Kimoto authored on 2013-04-18
101
    {table => 'project', primary_key => ['user_id', 'name']},
102
    {table => 'number', primary_key => 'key'}
improved create repository f...
Yuki Kimoto authored on 2013-03-21
103
  ];
104
  $dbi->create_model($_) for @$models;
105

            
106
  # Validator
107
  my $validator = Validator::Custom->new;
108
  $self->validator($validator);
added project delete feature
Yuki Kimoto authored on 2013-03-24
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...
Yuki Kimoto authored on 2013-03-21
121
  
added admin user tests
Yuki Kimoto authored on 2013-05-17
122

            
cleanup
Yuki Kimoto authored on 2013-05-14
123
  # Routes
Auto Route system catch up w...
Yuki Kimoto authored on 2013-05-18
124
  sub template {
125
    my $template = shift;
126
    
cleanup
Yuki Kimoto authored on 2013-05-19
127
    return sub { shift->render($template, , 'mojo.maybe' => 1) };
Auto Route system catch up w...
Yuki Kimoto authored on 2013-05-18
128
  }
129
  
added login page
Yuki Kimoto authored on 2013-02-09
130
  {
cleanup
Yuki Kimoto authored on 2013-05-14
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
Yuki Kimoto authored on 2013-04-10
141
    }
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
142
    
cleanup
Yuki Kimoto authored on 2013-05-14
143
    # Auto route
cleanup many pages
Yuki Kimoto authored on 2013-03-31
144
    {
cleanup
Yuki Kimoto authored on 2013-05-14
145
      my $r = $r->under(sub {
146
        my $self = shift;
147
        
148
        my $api = $self->gitprep_api;
149
        
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
150
        # Authentication
cleanup
Yuki Kimoto authored on 2013-05-14
151
        {
152
          my $path = $self->req->url->path->parts->[0] || '';
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
153
          
154
          # Admin
cleanup
Yuki Kimoto authored on 2013-05-14
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
Yuki Kimoto authored on 2013-08-21
163
      
164
      # Auto routes
cleanup
Yuki Kimoto authored on 2013-05-14
165
      $self->plugin('AutoRoute', route => $r);
improved repository page des...
Yuki Kimoto authored on 2012-11-23
166

            
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
167
      # Custom routes
cleanup
Yuki Kimoto authored on 2013-05-14
168
      {
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
169
        my $id_re = qr/[a-zA-Z0-9_-]+/;
cleanup
Yuki Kimoto authored on 2013-05-14
170
        
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
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
Yuki Kimoto authored on 2013-05-14
180
        
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
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...
Yuki Kimoto authored on 2013-04-11
196

            
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
197
          # Tags
198
          $r->get('/tags' => template '/tags');
improved network page
Yuki Kimoto authored on 2013-04-16
199

            
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
200
          # Tree
201
          $r->get('/tree/*rev_dir' => template '/tree');
202
          
203
          # Blob
204
          $r->get('/blob/*rev_file' => template '/blob');
add blame method
Yuki Kimoto authored on 2013-08-10
205

            
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
206
          # Raw
207
          $r->get('/raw/*rev_file' => template '/raw');
add blame method
Yuki Kimoto authored on 2013-08-10
208

            
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
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
Yuki Kimoto authored on 2013-05-14
224

            
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
225
          # Network
226
          $r->get('/network' => template '/network');
cleanup
Yuki Kimoto authored on 2013-05-14
227

            
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
228
          # Network Graph
229
          $r->get('/network/graph/(*rev1)...(*rev2_abs)' => template '/network/graph');
add pull page design
Yuki Kimoto authored on 2013-08-13
230

            
add need_login_always_option
Yuki Kimoto authored on 2013-08-21
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
Yuki Kimoto authored on 2013-05-14
237
      }
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
238
    }
239
  }
added admin user tests
Yuki Kimoto authored on 2013-05-17
240

            
241
  # Helper
242
  {
243
    # API
244
    $self->helper(gitprep_api => sub { Gitprep::API->new(shift) });
245
  }
added reverse proxy path_dep...
Yuki Kimoto authored on 2013-04-22
246
  
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
247
  # Reverse proxy support
added reverse proxy path_dep...
Yuki Kimoto authored on 2013-04-22
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
Yuki Kimoto authored on 2013-04-09
260
    }
added reverse proxy path_dep...
Yuki Kimoto authored on 2013-04-22
261
  }
copy gitweblite soruce code
root authored on 2012-11-23
262
}
263

            
264
1;