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

            
improved design
Yuki Kimoto authored on 2012-11-30
4
our $VERSION = '0.01';
copy gitweblite soruce code
root authored on 2012-11-23
5

            
6
use Mojo::Base 'Mojolicious';
renamed gitpub to gitprep
Yuki Kimoto authored on 2012-11-26
7
use Gitprep::Git;
added start page
Yuki Kimoto authored on 2013-02-09
8
use DBIx::Custom;
9
use Validator::Custom;
added user management featur...
Yuki Kimoto authored on 2013-02-13
10
use Encode qw/encode decode/;
11
use Mojo::JSON;
little more secure login
Yuki Kimoto authored on 2013-03-16
12
use Gitprep::API;
added create repository feat...
Yuki Kimoto authored on 2013-03-18
13
use Carp 'croak';
added RepManager rename feat...
Yuki Kimoto authored on 2013-03-27
14
use Gitprep::RepManager;
15
use Scalar::Util 'weaken';
fixed git_bin not found bug
Yuki Kimoto authored on 2013-03-31
16
use Carp 'croak';
copy gitweblite soruce code
root authored on 2012-11-23
17

            
18
has 'git';
added start page
Yuki Kimoto authored on 2013-02-09
19
has 'dbi';
20
has 'validator';
added RepManager rename feat...
Yuki Kimoto authored on 2013-03-27
21
has 'manager';
copy gitweblite soruce code
root authored on 2012-11-23
22

            
23
sub startup {
24
  my $self = shift;
25
  
26
  # Config
update Mojolicious and added...
Yuki Kimoto authored on 2013-03-20
27
  $self->plugin('INIConfig', {ext => 'conf'});
28
  
29
  # My Config(Development)
30
  my $my_conf_file = $self->home->rel_file('gitprep.my.conf');
31
  $self->plugin('INIConfig', {file => $my_conf_file}) if -f $my_conf_file;
32
  
fixed git_bin not found bug
Yuki Kimoto authored on 2013-03-31
33
  # Config
copy gitweblite soruce code
root authored on 2012-11-23
34
  my $conf = $self->config;
added create repository feat...
Yuki Kimoto authored on 2013-03-18
35
  $conf->{hypnotoad} ||= {listen => ["http://*:10020"]};
fixed listen bug
Yuki Kimoto authored on 2013-03-29
36
  my $listen = $conf->{hypnotoad}{listen} || '';
37
  if ($listen ne '' && ref $listen ne 'ARRAY') {
38
    $listen = [ split /,/, $listen ];
39
  }
40
  $conf->{hypnotoad}{listen} = $listen;
copy gitweblite soruce code
root authored on 2012-11-23
41
  
fixed git_bin not found bug
Yuki Kimoto authored on 2013-03-31
42
  # Git command
renamed gitpub to gitprep
Yuki Kimoto authored on 2012-11-26
43
  my $git = Gitprep::Git->new;
fixed git_bin not found bug
Yuki Kimoto authored on 2013-03-31
44
  my $git_bin = $conf->{basic}{git_bin} ? $conf->{basic}{git_bin} : $git->search_bin;
fix mini bug
Yuki Kimoto authored on 2013-03-31
45
  if (!$git_bin || ! -e $git_bin) {
46
    $git_bin ||= '';
47
    my $error = "Can't detect or found git command ($git_bin). set git_bin in gitprep.conf";
fixed git_bin not found bug
Yuki Kimoto authored on 2013-03-31
48
    $self->log->error($error);
49
    croak $error;
50
  }
copy gitweblite soruce code
root authored on 2012-11-23
51
  $git->bin($git_bin);
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
52

            
53
  # Repository Manager
54
  my $manager = Gitprep::RepManager->new(app => $self);
55
  weaken $manager->{app};
56
  $self->manager($manager);
fixed git_bin not found bug
Yuki Kimoto authored on 2013-03-31
57
  
58
  # Repository home
move database and repository...
Yuki Kimoto authored on 2013-04-15
59
  my $rep_home = $self->home->rel_file('data/rep');
added create repository feat...
Yuki Kimoto authored on 2013-03-18
60
  $git->rep_home($rep_home);
61
  unless (-d $rep_home) {
62
    mkdir $rep_home
63
      or croak "Can't create directory $rep_home: $!";
64
  }
copy gitweblite soruce code
root authored on 2012-11-23
65
  $self->git($git);
66

            
improved create repository f...
Yuki Kimoto authored on 2013-03-21
67
  # DBI
move database and repository...
Yuki Kimoto authored on 2013-04-15
68
  my $db_file = $self->home->rel_file('data/gitprep.db');
improved create repository f...
Yuki Kimoto authored on 2013-03-21
69
  my $dbi = DBIx::Custom->connect(
70
    dsn => "dbi:SQLite:database=$db_file",
71
    connector => 1,
72
    option => {sqlite_unicode => 1}
73
  );
74
  $self->dbi($dbi);
75
  
added tab_index columns
Yuki Kimoto authored on 2013-04-11
76
  # Setup database
77
  $self->manager->setup_database;
improved create repository f...
Yuki Kimoto authored on 2013-03-21
78
  
79
  # Model
80
  my $models = [
81
    {table => 'user', primary_key => 'id'},
82
    {table => 'project', primary_key => ['user_id', 'name']}
83
  ];
84
  $dbi->create_model($_) for @$models;
85

            
86
  # Fiter
87
  $dbi->register_filter(json => sub {
88
    my $value = shift;
89
    
90
    if (ref $value) {
91
      return decode('UTF-8', Mojo::JSON->new->encode($value));
92
    }
93
    else {
94
      return Mojo::JSON->new->decode(encode('UTF-8', $value));
95
    }
96
  });
97
  
98
  # Validator
99
  my $validator = Validator::Custom->new;
100
  $self->validator($validator);
added project delete feature
Yuki Kimoto authored on 2013-03-24
101
  $validator->register_constraint(
102
    user_name => sub {
103
      my $value = shift;
104
      
105
      return ($value || '') =~ /^[a-zA-Z0-9_\-]+$/
106
    },
107
    project_name => sub {
108
      my $value = shift;
109
      
110
      return ($value || '') =~ /^[a-zA-Z0-9_\-]+$/
111
    }
112
  );
improved create repository f...
Yuki Kimoto authored on 2013-03-21
113
  
114
  # Helper
115
  $self->helper(gitprep_api => sub { Gitprep::API->new(shift) });
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
116

            
added feature that project c...
Yuki Kimoto authored on 2013-04-11
117
  # Routes
118
  my $r = $self->routes;
119

            
improved create repository f...
Yuki Kimoto authored on 2013-03-21
120
  # DBViewer(only development)
121
  if ($self->mode eq 'development') {
122
    eval {
123
      $self->plugin(
124
        'DBViewer',
added feature that project c...
Yuki Kimoto authored on 2013-04-11
125
        dsn => "dbi:SQLite:database=$db_file"
improved create repository f...
Yuki Kimoto authored on 2013-03-21
126
      );
127
    };
128
  }
added user delete feature
Yuki Kimoto authored on 2013-04-09
129
  
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
130
  # Auto route
added user delete feature
Yuki Kimoto authored on 2013-04-09
131
  {
132
    my $r = $r->under(sub {
133
      my $self = shift;
134
      
135
      my $api = $self->gitprep_api;
136
      
137
      # Admin page authentication
138
      {
139
        my $path = $self->req->url->path->parts->[0] || '';
140

            
141
        if ($path eq '_admin' && !$api->logined_admin) {
142
          $self->redirect_to('/');
143
          return;
144
        }
145
      }
146
      
147
      return 1; 
148
    });
149
    $self->plugin('AutoRoute', route => $r);
150
  }
added feature that project c...
Yuki Kimoto authored on 2013-04-11
151

            
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
152
  # User defined Routes
added login page
Yuki Kimoto authored on 2013-02-09
153
  {
added user management featur...
Yuki Kimoto authored on 2013-02-13
154
    # User
added reset password feature
Yuki Kimoto authored on 2013-04-10
155
    my $r = $r->route('/:user');
156
    {
157
      # Home
158
      $r->get('/')->name('user');
159
      
160
      # Settings
161
      $r->get('/_settings')->name('user-settings');
162
    }
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
163
    
164
    # Project
cleanup many pages
Yuki Kimoto authored on 2013-03-31
165
    {
added reset password feature
Yuki Kimoto authored on 2013-04-10
166
      my $r = $r->route('/:project');
167
      
168
      # Home
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
169
      $r->get('/')->name('project');
cleanup many pages
Yuki Kimoto authored on 2013-03-31
170
      
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
171
      # Commit
172
      $r->get('/commit/#diff')->name('commit');
173
      
174
      # Commits
175
      $r->get('/commits/#rev', {id => 'HEAD'})->name('commits');
176
      $r->get('/commits/#rev/(*blob)')->name('commits');
177
      
178
      # Branches
added admin password reset s...
Yuki Kimoto authored on 2013-04-09
179
      $r->get('/branches')->name('branches');
Fixed repositories page
Yuki Kimoto authored on 2012-11-23
180

            
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
181
      # Tags
added admin password reset s...
Yuki Kimoto authored on 2013-04-09
182
      $r->get('/tags')->name('tags');
improved repository page des...
Yuki Kimoto authored on 2012-11-23
183

            
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
184
      # Tree
185
      $r->get('/tree/(*object)')->name('tree');
186
      
187
      # Blob
188
      $r->get('/blob/(*object)')->name('blob');
189
      
190
      # Blob diff
191
      $r->get('/blobdiff/(#diff)/(*file)')->name('blobdiff');
192
      
193
      # Raw
194
      $r->get('/raw/(*object)')->name('raw');
195
      
196
      # Archive
197
      $r->get('/archive/(#rev).tar.gz')->name('archive')->to(archive_type => 'tar');
198
      $r->get('/archive/(#rev).zip')->name('archive')->to(archive_type => 'zip');
199
      
200
      # Compare
201
      $r->get('/compare/(#rev1)...(#rev2)')->name('compare');
202
      
203
      # Settings
added reset password feature
Yuki Kimoto authored on 2013-04-10
204
      $r->any('/settings')->name('project-settings');
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
205
      
206
      # Fork
added admin password reset s...
Yuki Kimoto authored on 2013-04-09
207
      $r->any('/fork')->name('fork');
added feature that you see p...
Yuki Kimoto authored on 2013-04-11
208

            
209
      # Fork
210
      $r->get('/network')->name('network');
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
211
    }
212
  }
added downloads page
Yuki Kimoto authored on 2012-12-11
213

            
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
214
  # Reverse proxy support
215
  $ENV{MOJO_REVERSE_PROXY} = 1;
216
  $self->hook('before_dispatch' => sub {
217
    my $self = shift;
added fork feature
Yuki Kimoto authored on 2013-03-29
218
    
added AutoRoute plugin
Yuki Kimoto authored on 2013-04-09
219
    if ($self->req->headers->header('X-Forwarded-Host')) {
220
      my $prefix = shift @{$self->req->url->path->parts};
221
      push @{$self->req->url->base->path->parts}, $prefix
222
        if defined $prefix;
223
    }
224
  });
copy gitweblite soruce code
root authored on 2012-11-23
225
}
226

            
227
1;