gitprep / lib / Gitprep.pm /
Newer Older
259 lines | 6.411kb
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

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

            
104
  # Validator
105
  my $validator = Validator::Custom->new;
106
  $self->validator($validator);
added project delete feature
Yuki Kimoto authored on 2013-03-24
107
  $validator->register_constraint(
108
    user_name => sub {
109
      my $value = shift;
110
      
111
      return ($value || '') =~ /^[a-zA-Z0-9_\-]+$/
112
    },
113
    project_name => sub {
114
      my $value = shift;
115
      
116
      return ($value || '') =~ /^[a-zA-Z0-9_\-]+$/
117
    }
118
  );
improved create repository f...
Yuki Kimoto authored on 2013-03-21
119
  
added admin user tests
Yuki Kimoto authored on 2013-05-17
120

            
cleanup
Yuki Kimoto authored on 2013-05-14
121
  # Routes
Auto Route system catch up w...
Yuki Kimoto authored on 2013-05-18
122
  sub template {
123
    my $template = shift;
124
    
cleanup
Yuki Kimoto authored on 2013-05-19
125
    return sub { shift->render($template, , 'mojo.maybe' => 1) };
Auto Route system catch up w...
Yuki Kimoto authored on 2013-05-18
126
  }
127
  
added login page
Yuki Kimoto authored on 2013-02-09
128
  {
cleanup
Yuki Kimoto authored on 2013-05-14
129
    my $r = $self->routes;
130

            
131
    # DBViewer(only development)
132
    if ($self->mode eq 'development') {
133
      eval {
134
        $self->plugin(
135
          'DBViewer',
136
          dsn => "dbi:SQLite:database=$db_file"
137
        );
138
      };
added reset password feature
Yuki Kimoto authored on 2013-04-10
139
    }
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
140
    
cleanup
Yuki Kimoto authored on 2013-05-14
141
    # Auto route
cleanup many pages
Yuki Kimoto authored on 2013-03-31
142
    {
cleanup
Yuki Kimoto authored on 2013-05-14
143
      my $r = $r->under(sub {
144
        my $self = shift;
145
        
146
        my $api = $self->gitprep_api;
147
        
148
        # Admin page authentication
149
        {
150
          my $path = $self->req->url->path->parts->[0] || '';
Fixed repositories page
Yuki Kimoto authored on 2012-11-23
151

            
cleanup
Yuki Kimoto authored on 2013-05-14
152
          if ($path eq '_admin' && !$api->logined_admin) {
153
            $self->redirect_to('/');
154
            return;
155
          }
156
        }
157
        
158
        return 1; 
159
      });
160
      $self->plugin('AutoRoute', route => $r);
161
    }
improved repository page des...
Yuki Kimoto authored on 2012-11-23
162

            
cleanup
Yuki Kimoto authored on 2013-05-14
163
    # Custom routes
164
    {
add rename project and suppr...
Yuki Kimoto authored on 2013-05-24
165
      my $id_re = qr/[a-zA-Z0-9_-]+/;
166
      
cleanup
Yuki Kimoto authored on 2013-05-14
167
      # User
add rename project and suppr...
Yuki Kimoto authored on 2013-05-24
168
      my $r = $r->route('/:user', user => $id_re);
cleanup
Yuki Kimoto authored on 2013-05-14
169
      {
170
        # Home
cleanup
Yuki Kimoto authored on 2013-05-19
171
        $r->get('/' => template '/user');
cleanup
Yuki Kimoto authored on 2013-05-14
172
        
173
        # Settings
cleanup
Yuki Kimoto authored on 2013-05-19
174
        $r->get('/_settings' => template '/user-settings');
cleanup
Yuki Kimoto authored on 2013-05-14
175
      }
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
176
      
cleanup
Yuki Kimoto authored on 2013-05-14
177
      # Project
178
      {
add rename project and suppr...
Yuki Kimoto authored on 2013-05-24
179
        my $r = $r->route('/:project', project => $id_re);
cleanup
Yuki Kimoto authored on 2013-05-14
180
        
181
        # Home
cleanup
Yuki Kimoto authored on 2013-05-19
182
        $r->get('/' => template '/project');
cleanup
Yuki Kimoto authored on 2013-05-14
183
        
184
        # Commit
cleanup
Yuki Kimoto authored on 2013-05-19
185
        $r->get('/commit/*diff' => template '/commit');
cleanup
Yuki Kimoto authored on 2013-05-14
186
        
187
        # Commits
cleanup
Yuki Kimoto authored on 2013-05-19
188
        $r->get('/commits/*rev_file' => template '/commits');
cleanup
Yuki Kimoto authored on 2013-05-14
189
        
190
        # Branches
cleanup
Yuki Kimoto authored on 2013-05-19
191
        $r->any('/branches/*base_branch' => {base_branch => undef} => template '/branches');
added feature that you see p...
Yuki Kimoto authored on 2013-04-11
192

            
cleanup
Yuki Kimoto authored on 2013-05-14
193
        # Tags
cleanup
Yuki Kimoto authored on 2013-05-19
194
        $r->get('/tags' => template '/tags');
improved network page
Yuki Kimoto authored on 2013-04-16
195

            
cleanup
Yuki Kimoto authored on 2013-05-14
196
        # Tree
cleanup
Yuki Kimoto authored on 2013-05-19
197
        $r->get('/tree/*rev_dir' => template '/tree');
cleanup
Yuki Kimoto authored on 2013-05-14
198
        
199
        # Blob
cleanup
Yuki Kimoto authored on 2013-05-19
200
        $r->get('/blob/*rev_file' => template '/blob');
add blame method
Yuki Kimoto authored on 2013-08-10
201

            
cleanup
Yuki Kimoto authored on 2013-05-14
202
        # Raw
cleanup
Yuki Kimoto authored on 2013-05-19
203
        $r->get('/raw/*rev_file' => template '/raw');
add blame method
Yuki Kimoto authored on 2013-08-10
204

            
205
        # Blame
206
        $r->get('/blame/*rev_file' => template '/blame');
cleanup
Yuki Kimoto authored on 2013-05-14
207
        
208
        # Archive
cleanup
Yuki Kimoto authored on 2013-05-19
209
        $r->get('/archive/(*rev).tar.gz' => template '/archive')->to(archive_type => 'tar');
210
        $r->get('/archive/(*rev).zip' => template '/archive')->to(archive_type => 'zip' );
cleanup
Yuki Kimoto authored on 2013-05-14
211
        
212
        # Compare
cleanup
Yuki Kimoto authored on 2013-05-19
213
        $r->get('/compare/(*rev1)...(*rev2)' => template '/compare');
cleanup
Yuki Kimoto authored on 2013-05-14
214
        
215
        # Settings
cleanup
Yuki Kimoto authored on 2013-05-19
216
        $r->any('/settings' => template '/settings');
cleanup
Yuki Kimoto authored on 2013-05-14
217
        
218
        # Fork
cleanup
Yuki Kimoto authored on 2013-05-19
219
        $r->any('/fork' => template '/fork');
cleanup
Yuki Kimoto authored on 2013-05-14
220

            
221
        # Network
cleanup
Yuki Kimoto authored on 2013-05-19
222
        $r->get('/network' => template '/network');
cleanup
Yuki Kimoto authored on 2013-05-14
223

            
224
        # Network Graph
cleanup
Yuki Kimoto authored on 2013-05-19
225
        $r->get('/network/graph/(*rev1)...(*rev2_abs)' => template '/network/graph');
add pull page design
Yuki Kimoto authored on 2013-08-13
226

            
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
227
        # Import branch
add import branch tests
Yuki Kimoto authored on 2013-08-19
228
        $r->any('/import-branch/:remote_user/:remote_project' => template '/import-branch');
cleanup
Yuki Kimoto authored on 2013-05-14
229
        
230
        # Get branches and tags
cleanup
Yuki Kimoto authored on 2013-05-19
231
        $r->get('/api/revs' => template '/api/revs');
cleanup
Yuki Kimoto authored on 2013-05-14
232
      }
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
233
    }
234
  }
added admin user tests
Yuki Kimoto authored on 2013-05-17
235

            
236
  # Helper
237
  {
238
    # API
239
    $self->helper(gitprep_api => sub { Gitprep::API->new(shift) });
240
  }
added reverse proxy path_dep...
Yuki Kimoto authored on 2013-04-22
241
  
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
242
  # Reverse proxy support
added reverse proxy path_dep...
Yuki Kimoto authored on 2013-04-22
243
  my $reverse_proxy_on = $self->config->{reverse_proxy}{on};
244
  my $path_depth = $self->config->{reverse_proxy}{path_depth};
245
  if ($reverse_proxy_on) {
246
    $ENV{MOJO_REVERSE_PROXY} = 1;
247
    if ($path_depth) {
248
      $self->hook('before_dispatch' => sub {
249
        my $self = shift;
250
        for (1 .. $path_depth) {
251
          my $prefix = shift @{$self->req->url->path->parts};
252
          push @{$self->req->url->base->path->parts}, $prefix;
253
        }
254
      });
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
255
    }
added reverse proxy path_dep...
Yuki Kimoto authored on 2013-04-22
256
  }
copy gitweblite soruce code
root authored on 2012-11-23
257
}
258

            
259
1;