gitprep / lib / Gitprep / Manager.pm /
Newer Older
967 lines | 25.291kb
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
1
package Gitprep::Manager;
2
use Mojo::Base -base;
3

            
4
use Carp 'croak';
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
5
use Encode 'encode';
fix description file not cop...
Yuki Kimoto authored on 2013-05-25
6
use File::Copy qw/move copy/;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
7
use File::Path qw/mkpath rmtree/;
8
use File::Temp ();
add key delete feature and u...
gitprep authored on 2014-05-19
9
use Fcntl ':flock';
10
use Carp 'croak';
11
use File::Copy qw/copy move/;
fix bug that in CGI reposito...
Yuki Kimoto authored on 2015-11-05
12
use File::Spec;
13
use Gitprep::Util;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
14

            
15
has 'app';
add key delete feature and u...
gitprep authored on 2014-05-19
16
has 'authorized_keys_file';
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
17

            
cleanup prepare merge
Yuki Kimoto authored on 2016-04-23
18
has '_tmp_branch' => '__gitprep_tmp_branch__';
19

            
20
sub prepare_merge {
fix tests
Yuki Kimoto authored on 2016-04-27
21
  my ($self, $work_rep_info, $base_rep_info, $base_branch, $target_rep_info, $target_branch) = @_;
add lock system
Yuki Kimoto authored on 2016-04-18
22
  
cleanup prepare merge
Yuki Kimoto authored on 2016-04-23
23
  # Fetch base repository
fix tests
Yuki Kimoto authored on 2016-04-27
24
  my $base_user_id = $base_rep_info->{user};
fix pull_request table bug
Yuki Kimoto authored on 2016-04-27
25
  my @git_fetch_base_cmd = $self->app->git->cmd($work_rep_info, 'fetch', 'origin');
cleanup prepare merge
Yuki Kimoto authored on 2016-04-23
26
  Gitprep::Util::run_command(@git_fetch_base_cmd)
27
    or Carp::croak "Can't execute git fetch: @git_fetch_base_cmd";
add lock system
Yuki Kimoto authored on 2016-04-18
28
  
cleanup prepare merge
Yuki Kimoto authored on 2016-04-23
29
  # Fetch target repository
fix tests
Yuki Kimoto authored on 2016-04-27
30
  my @git_fetch_target_cmd = $self->app->git->cmd($work_rep_info, 'fetch', $target_rep_info->{git_dir});
fix compare page from forke...
Yuki Kimoto authored on 2016-08-20
31
  
cleanup prepare merge
Yuki Kimoto authored on 2016-04-23
32
  Gitprep::Util::run_command(@git_fetch_target_cmd)
33
    or Carp::croak "Can't execute git fetch: @git_fetch_target_cmd";
cleanup merge and push logic
Yuki Kimoto authored on 2016-04-27
34

            
35
  # Ensure no diff
36
  my @git_reset_hard_cmd = $self->app->git->cmd(
37
    $work_rep_info,
38
    'reset',
39
    '--hard'
40
  );
41
  Gitprep::Util::run_command(@git_reset_hard_cmd)
42
    or Carp::croak "Can't execute git reset --hard: @git_reset_hard_cmd";
43

            
44
  # Checkout first branch
45
  my $tmp_branch = $self->_tmp_branch;
46
  my $branch_names = $self->app->git->branch_names($work_rep_info);
47
  my $first_branch;
48
  for my $branch_name (@$branch_names) {
49
    if ($branch_name ne $tmp_branch) {
50
      $first_branch = $branch_name;
51
      last;
52
    }
53
  }
54
  my @git_checkout_first_branch = $self->app->git->cmd(
55
    $work_rep_info,
56
    'checkout',
57
    $first_branch
58
  );
59
  Gitprep::Util::run_command(@git_checkout_first_branch)
60
    or Carp::croak "Can't execute git checkout: @git_checkout_first_branch";
61
  
62
  # Delete temparary branch if it eixsts
63
  if (grep { $_ eq $tmp_branch } @$branch_names) {
64
    my @git_branch_remove_cmd = $self->app->git->cmd(
65
      $work_rep_info,
66
      'branch',
67
      '-D',
68
      $tmp_branch
69
    );
70
    Gitprep::Util::run_command(@git_branch_remove_cmd)
71
      or Carp::croak "Can't execute git branch: @git_branch_remove_cmd";
72
  }
73

            
74
  # Create temparary branch
75
  my @git_branch_cmd = $self->app->git->cmd(
76
    $work_rep_info,
77
    'branch',
78
    $tmp_branch
79
  );
80
  Gitprep::Util::run_command(@git_branch_cmd)
81
    or Carp::croak "Can't execute git branch: @git_branch_cmd";
cleanup prepare merge
Yuki Kimoto authored on 2016-04-23
82
  
83
  # Checkout tmp branch and git reset --hard from my remote branch
84
  my @git_checkout_tmp_branch = $self->app->git->cmd(
85
    $work_rep_info,
86
    'checkout',
cleanup merge and push logic
Yuki Kimoto authored on 2016-04-27
87
    $tmp_branch
cleanup prepare merge
Yuki Kimoto authored on 2016-04-23
88
  );
89
  Gitprep::Util::run_command(@git_checkout_tmp_branch)
90
    or Carp::croak "Can't execute git checkout: @git_checkout_tmp_branch";
91
  
fix merge pull request bug
Yuki Kimoto authored on 2016-04-27
92
  # git reset --hard 
fix tests
Yuki Kimoto authored on 2016-04-27
93
  my $base_object_id = $self->app->git->ref_to_object_id($base_rep_info, $base_branch);
fix merge pull request bug
Yuki Kimoto authored on 2016-04-27
94
  my @git_reset_hard_base_cmd = $self->app->git->cmd(
cleanup prepare merge
Yuki Kimoto authored on 2016-04-23
95
    $work_rep_info,
96
    'reset',
97
    '--hard',
fix tests
Yuki Kimoto authored on 2016-04-27
98
    $base_object_id
cleanup prepare merge
Yuki Kimoto authored on 2016-04-23
99
  );
fix merge pull request bug
Yuki Kimoto authored on 2016-04-27
100
  Gitprep::Util::run_command(@git_reset_hard_base_cmd)
101
    or Carp::croak "Can't execute git reset --hard: @git_reset_hard_base_cmd";
add lock system
Yuki Kimoto authored on 2016-04-18
102
}
103

            
cleanup merge and push logic
Yuki Kimoto authored on 2016-04-27
104
sub merge {
add --no-ff option to merge ...
Yuki Kimoto authored on 2016-04-30
105
  my ($self, $work_rep_info, $target_rep_info, $target_branch, $pull_request_number) = @_;
cleanup merge and push logic
Yuki Kimoto authored on 2016-04-27
106
  
fix tests
Yuki Kimoto authored on 2016-04-27
107
  my $object_id = $self->app->git->ref_to_object_id($target_rep_info, $target_branch);
fix pull_request table bug
Yuki Kimoto authored on 2016-04-27
108
  
add --no-ff option to merge ...
Yuki Kimoto authored on 2016-04-30
109
  my $message;
fix tests
Yuki Kimoto authored on 2016-04-27
110
  my $target_user_id = $target_rep_info->{user};
add --no-ff option to merge ...
Yuki Kimoto authored on 2016-04-30
111
  if (defined $pull_request_number) {
112
    $message = "Merge pull request #$pull_request_number from $target_user_id/$target_branch";
113
  }
114
  else {
115
    $message = "Merge from $target_user_id/$target_branch";
116
  }
117
  
118
  # Merge
cleanup merge and push logic
Yuki Kimoto authored on 2016-04-27
119
  my @git_merge_cmd = $self->app->git->cmd(
120
    $work_rep_info,
121
    'merge',
add --no-ff option to merge ...
Yuki Kimoto authored on 2016-04-30
122
    '--no-ff',
123
    "--message=$message",
fix pull_request table bug
Yuki Kimoto authored on 2016-04-27
124
    $object_id
cleanup merge and push logic
Yuki Kimoto authored on 2016-04-27
125
  );
add --no-ff option to merge ...
Yuki Kimoto authored on 2016-04-30
126
  # 
cleanup merge and push logic
Yuki Kimoto authored on 2016-04-27
127
  
128
  my $success = Gitprep::Util::run_command(@git_merge_cmd);
129
  
130
  return $success;
131
}
132

            
add patch feature
Yuki Kimoto authored on 2016-06-04
133
sub get_patch {
134
  my ($self, $work_rep_info, $target_rep_info, $target_branch) = @_;
135
  
136
  my $object_id = $self->app->git->ref_to_object_id($target_rep_info, $target_branch);
137
  
138
  # Merge
139
  my @git_format_patch_cmd = $self->app->git->cmd(
140
    $work_rep_info,
141
    'format-patch',
142
    '--stdout',
143
    "HEAD..$object_id"
144
  );
145
  
146
  open my $fh, '-|', @git_format_patch_cmd
147
    or croak "Execute git format-patch cmd:@git_format_patch_cmd";
148
  
149
  my $patch = do { local $/; <$fh> };
150
  
151
  return $patch;
152
}
153

            
cleanup merge and push logic
Yuki Kimoto authored on 2016-04-27
154
sub push {
fix merge pull request bug
Yuki Kimoto authored on 2016-04-27
155
  my ($self, $work_rep_info, $base_branch) = @_;
cleanup merge and push logic
Yuki Kimoto authored on 2016-04-27
156
  
157
  # Push
fix merge pull request bug
Yuki Kimoto authored on 2016-04-27
158
  my $tmp_branch = $self->_tmp_branch;
159
  my @git_push_cmd = $self->app->git->cmd(
160
    $work_rep_info,
161
    'push',
162
    'origin',
163
    "$tmp_branch:$base_branch"
164
  );
cleanup merge and push logic
Yuki Kimoto authored on 2016-04-27
165
  Gitprep::Util::run_command(@git_push_cmd)
166
    or Carp::croak "Can't execute git push: @git_push_cmd";
167
}
168

            
cleanup prepare merge
Yuki Kimoto authored on 2016-04-23
169
sub lock_rep {
170
  my ($self, $rep_info) = @_;
171
  
172
  my $git_dir = $rep_info->{git_dir};
173
  my $lock_file = "$git_dir/config";
174
  
175
  open my $lock_fh, '<', $lock_file
176
    or croak "Can't open lock file $lock_file: $!";
177
    
178
  flock $lock_fh, LOCK_EX
179
    or croak "Can't lock $lock_file";
180
  
181
  return $lock_fh;
182
}
183

            
cleanup
Yuki Kimoto authored on 2016-04-16
184
sub create_work_rep {
improve create working repos...
Yuki Kimoto authored on 2016-04-15
185
  my ($self, $user, $project) = @_;
186
  
cleanup create working direc...
Yuki Kimoto authored on 2016-04-16
187
  # Remote repository
188
  my $rep_info = $self->app->rep_info($user, $project);
189
  my $rep_git_dir = $rep_info->{git_dir};
190
  
191
  # Working repository
192
  my $work_rep_info = $self->app->work_rep_info($user, $project);
193
  my $work_tree = $work_rep_info->{work_tree};
194
  
improve create working repos...
Yuki Kimoto authored on 2016-04-15
195
  # Create working repository if it don't exist
cleanup create working direc...
Yuki Kimoto authored on 2016-04-16
196
  unless (-e $work_tree) {
197

            
improve create working repos...
Yuki Kimoto authored on 2016-04-15
198
    # git clone
cleanup create working direc...
Yuki Kimoto authored on 2016-04-16
199
    my @git_clone_cmd = ($self->app->git->bin, 'clone', $rep_git_dir, $work_tree);
improve create working repos...
Yuki Kimoto authored on 2016-04-15
200
    Gitprep::Util::run_command(@git_clone_cmd)
201
      or croak "Can't git clone: @git_clone_cmd";
cleanup compare logic
Yuki Kimoto authored on 2016-04-18
202
    
improve create working repos...
Yuki Kimoto authored on 2016-04-15
203
    # Set user name
cleanup create working direc...
Yuki Kimoto authored on 2016-04-16
204
    my @git_config_user_name = $self->app->git->cmd(
205
      $work_rep_info,
improve create working repos...
Yuki Kimoto authored on 2016-04-15
206
      'config',
207
      'user.name',
208
      $user
209
    );
210
    Gitprep::Util::run_command(@git_config_user_name)
211
      or croak "Can't execute git config: @git_config_user_name";
212
    
fix mail bug
Yuki Kimoto authored on 2016-04-21
213
    # Set user email
214
    my $user_email = $self->app->dbi->model('user')->select('email', where => {id => $user})->value;
215
    my @git_config_user_email = $self->app->git->cmd(
cleanup create working direc...
Yuki Kimoto authored on 2016-04-16
216
      $work_rep_info,
improve create working repos...
Yuki Kimoto authored on 2016-04-15
217
      'config',
218
      'user.email',
fix mail bug
Yuki Kimoto authored on 2016-04-21
219
      "$user_email"
improve create working repos...
Yuki Kimoto authored on 2016-04-15
220
    );
fix mail bug
Yuki Kimoto authored on 2016-04-21
221
    Gitprep::Util::run_command(@git_config_user_email)
222
      or croak "Can't execute git config: @git_config_user_email";
improve create working repos...
Yuki Kimoto authored on 2016-04-15
223
  }
224
}
225

            
added admin tests
Yuki Kimoto authored on 2013-05-16
226
sub admin_user {
cleanup
Yuki Kimoto authored on 2013-05-13
227
  my $self = shift;
228
  
229
  # Admin user
230
  my $admin_user = $self->app->dbi->model('user')
added admin tests
Yuki Kimoto authored on 2013-05-16
231
    ->select(where => {admin => 1})->one;
cleanup
Yuki Kimoto authored on 2013-05-13
232
  
233
  return $admin_user;
234
}
235

            
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
236
sub default_branch {
fix project page
Yuki Kimoto authored on 2016-04-21
237
  my ($self, $user_id, $project_id, $default_branch) = @_;
238
  
239
  my $user_row_id = $self->api->get_user_row_id($user_id);
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
240
  
added default branch change ...
Yuki Kimoto authored on 2013-05-22
241
  # Set default branch
242
  my $dbi = $self->app->dbi;
243
  if (defined $default_branch) {
244
    $dbi->model('project')->update(
245
      {default_branch => $default_branch},
fix project page
Yuki Kimoto authored on 2016-04-21
246
      where => {user => $user_row_id, id => $project_id}
added default branch change ...
Yuki Kimoto authored on 2013-05-22
247
    );
248
  }
249
  else {
250
    # Get default branch
251
    my $default_branch = $dbi->model('project')
fix project page
Yuki Kimoto authored on 2016-04-21
252
      ->select('default_branch', where => {user => $user_row_id, id => $project_id})
added default branch change ...
Yuki Kimoto authored on 2013-05-22
253
      ->value;
254
    
255
    return $default_branch;
256
  }
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
257
}
258

            
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
259
sub fork_project {
cleanup
Yuki Kimoto authored on 2016-04-22
260
  my ($self, $forked_user_id, $user_id, $project_id) = @_;
fix fork
Yuki Kimoto authored on 2016-04-21
261
  
cleanup
Yuki Kimoto authored on 2016-04-22
262
  my $user_row_id = $self->api->get_user_row_id($user_id);
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
263
  
264
  # Fork project
265
  my $dbi = $self->app->dbi;
266
  my $error;
267
  eval {
268
    $dbi->connector->txn(sub {
269
      
270
      # Original project id
fix fork
Yuki Kimoto authored on 2016-04-21
271
      my $project = $dbi->model('project')->select(
cleanup
Yuki Kimoto authored on 2016-04-22
272
        {__MY__ => ['row_id', 'private']},
remove table __ prefix
Yuki Kimoto authored on 2016-06-11
273
        where => {'user.id' => $user_id, 'project.id' => $project_id}
version up and add descripti...
Yuki Kimoto authored on 2013-11-22
274
      )->one;
275
      
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
276
      # Create project
277
      eval {
278
        $self->_create_project(
cleanup
Yuki Kimoto authored on 2016-04-22
279
          $forked_user_id,
fix fork
Yuki Kimoto authored on 2016-04-21
280
          $project_id,
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
281
          {
fix fork
Yuki Kimoto authored on 2016-04-21
282
            original_project => $project->{row_id},
283
            private => $project->{private}
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
284
          }
285
        );
286
      };
287
      croak $error = $@ if $@;
288
      
289
      # Create repository
290
      eval {
cleanup
Yuki Kimoto authored on 2016-04-22
291
        $self->_fork_rep($user_id, $project_id, $forked_user_id, $project_id);
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
292
      };
293
      croak $error = $@ if $@;
294
    });
295
  };
296
  croak $error if $@;
297
}
298

            
cleanup
Yuki Kimoto authored on 2013-05-13
299
sub is_admin {
fix project page
Yuki Kimoto authored on 2016-04-21
300
  my ($self, $user_id) = @_;
cleanup
Yuki Kimoto authored on 2013-05-13
301
  
302
  # Check admin
303
  my $is_admin = $self->app->dbi->model('user')
fix project page
Yuki Kimoto authored on 2016-04-21
304
    ->select('admin', where => {id => $user_id})->value;
cleanup
Yuki Kimoto authored on 2013-05-13
305
  
306
  return $is_admin;
307
}
308

            
add private checkbox
Yuki Kimoto authored on 2013-11-16
309
sub is_private_project {
fix project page
Yuki Kimoto authored on 2016-04-21
310
  my ($self, $user_id, $project_id) = @_;
311
  
312
  my $user_row_id = $self->api->get_user_row_id($user_id);
add private checkbox
Yuki Kimoto authored on 2013-11-16
313
  
314
  # Is private
fix setting page
Yuki Kimoto authored on 2016-04-21
315
  my $private = $self->app->dbi->model('project')->select(
316
    'private', where => {user => $user_row_id, id => $project_id}
317
  )->value;
add private checkbox
Yuki Kimoto authored on 2013-11-16
318
  
319
  return $private;
320
}
321

            
fix project page
Yuki Kimoto authored on 2016-04-21
322
sub api { shift->app->gitprep_api }
323

            
324

            
fix network page
Yuki Kimoto authored on 2016-04-21
325
sub member_projects {
fix project page
Yuki Kimoto authored on 2016-04-21
326
  my ($self, $user_id, $project_id) = @_;
327
  
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
328
  # DBI
329
  my $dbi = $self->app->dbi;
330
  
cleanup
Yuki Kimoto authored on 2016-04-22
331
  # project id
332
  my $project_row_id = $dbi->model('project')->select(
333
    'project.row_id',
remove table __ prefix
Yuki Kimoto authored on 2016-06-11
334
    where => {'user.id' => $user_id, 'project.id' => $project_id}
cleanup
Yuki Kimoto authored on 2016-04-22
335
  )->value;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
336
  
337
  # Members
cleanup
Yuki Kimoto authored on 2016-04-22
338
  my $member_projects = $dbi->model('project')->select(
fix project page
Yuki Kimoto authored on 2016-04-21
339
    [
fix network page
Yuki Kimoto authored on 2016-04-21
340
      {__MY__ => ['id']},
remove table __ prefix
Yuki Kimoto authored on 2016-06-11
341
      {user => ['id']}
fix project page
Yuki Kimoto authored on 2016-04-21
342
    ],
fix network page
Yuki Kimoto authored on 2016-04-21
343
    where => {
344
      original_project => $project_row_id,
345
    },
remove table __ prefix
Yuki Kimoto authored on 2016-06-11
346
    append => 'order by user.id, project.id'
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
347
  )->all;
348

            
cleanup
Yuki Kimoto authored on 2016-04-22
349
  return $member_projects;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
350
}
351

            
352
sub create_project {
fix fork
Yuki Kimoto authored on 2016-04-21
353
  my ($self, $user_id, $project_id, $opts) = @_;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
354
  
add private checkbox to new ...
Yuki Kimoto authored on 2013-11-26
355
  my $params = {};
356
  if ($opts->{private}) {
357
    $params->{private} = 1;
358
  }
359
  
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
360
  # Create project
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
361
  my $dbi = $self->app->dbi;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
362
  my $error;
363
  eval {
364
    $dbi->connector->txn(sub {
fix fork
Yuki Kimoto authored on 2016-04-21
365
      eval { $self->_create_project($user_id, $project_id, $params) };
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
366
      croak $error = $@ if $@;
fix fork
Yuki Kimoto authored on 2016-04-21
367
      eval {$self->_create_rep($user_id, $project_id, $opts) };
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
368
      croak $error = $@ if $@;
369
    });
370
  };
371
  croak $error if $@;
372
}
373

            
374
sub create_user {
375
  my ($self, $user, $data) = @_;
376

            
377
  # Create user
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
378
  my $dbi = $self->app->dbi;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
379
  my $error;
380
  eval {
381
    $dbi->connector->txn(sub {
382
      eval { $self->_create_db_user($user, $data) };
383
      croak $error = $@ if $@;
384
      eval {$self->_create_user_dir($user) };
385
      croak $error = $@ if $@;
386
    });
387
  };
388
  croak $error if $@;
389
}
390

            
391
sub delete_project {
392
  my ($self, $user, $project) = @_;
393
  
394
  # Delete project
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
395
  my $dbi = $self->app->dbi;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
396
  my $error;
397
  eval {
398
    $dbi->connector->txn(sub {
399
      eval { $self->_delete_project($user, $project) };
400
      croak $error = $@ if $@;
401
      eval {$self->_delete_rep($user, $project) };
402
      croak $error = $@ if $@;
403
    });
404
  };
405
  croak $error if $@;
406
}
407

            
408
sub delete_user {
409
  my ($self, $user) = @_;
410
  
411
  # Delete user
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
412
  my $dbi = $self->app->dbi;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
413
  my $error;
added delete user test
Yuki Kimoto authored on 2013-05-18
414
  my $count;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
415
  eval {
416
    $dbi->connector->txn(sub {
added delete user test
Yuki Kimoto authored on 2013-05-18
417
      eval { $count = $self->_delete_db_user($user) };
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
418
      croak $error = $@ if $@;
419
      eval {$self->_delete_user_dir($user) };
420
      croak $error = $@ if $@;
421
    });
422
  };
423
  croak $error if $@;
added delete user test
Yuki Kimoto authored on 2013-05-18
424
  
425
  return $count;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
426
}
427

            
428
sub original_project {
fix project page
Yuki Kimoto authored on 2016-04-21
429
  my ($self, $user_id, $project_id) = @_;
430
  
431
  my $user_row_id = $self->api->get_user_row_id($user_id);
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
432
  
cleanup delete original_proj...
Yuki Kimoto authored on 2013-05-26
433
  # Original project id
434
  my $dbi = $self->app->dbi;
fix project page
Yuki Kimoto authored on 2016-04-21
435
  my $original_project_row_id = $dbi->model('project')->select(
436
    'original_project',
437
    where => {user => $user_row_id, id => $project_id}
438
  )->value;
cleanup delete original_proj...
Yuki Kimoto authored on 2013-05-26
439
  
fix project page
Yuki Kimoto authored on 2016-04-21
440
  croak "Original project don't eixsts." unless defined $original_project_row_id;
cleanup delete original_proj...
Yuki Kimoto authored on 2013-05-26
441
  
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
442
  # Original project
cleanup delete original_proj...
Yuki Kimoto authored on 2013-05-26
443
  my $original_project = $dbi->model('project')->select(
fix project page
Yuki Kimoto authored on 2016-04-21
444
    [
445
      {__MY__ => '*'},
remove table __ prefix
Yuki Kimoto authored on 2016-06-11
446
      {user => ['id']}
fix project page
Yuki Kimoto authored on 2016-04-21
447
    ],
cleanup delete original_proj...
Yuki Kimoto authored on 2013-05-26
448
    where => {
fix project page
Yuki Kimoto authored on 2016-04-21
449
      'project.row_id' => $original_project_row_id
cleanup delete original_proj...
Yuki Kimoto authored on 2013-05-26
450
    }
fix project page
Yuki Kimoto authored on 2016-04-21
451
  )->one;
cleanup delete original_proj...
Yuki Kimoto authored on 2013-05-26
452
  
fix project page
Yuki Kimoto authored on 2016-04-21
453
  return unless defined $original_project;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
454
  
455
  return $original_project;
456
}
457

            
get target branch logic
Yuki Kimoto authored on 2016-04-27
458
sub child_project {
459
  my ($self, $user_id, $project_id, $child_user_id) = @_;
460
  
461
  my $project_row_id = $self->app->dbi->model('project')->select(
remove table __ prefix
Yuki Kimoto authored on 2016-06-11
462
    'project.row_id', where => {'user.id' => $user_id, 'project.id' => $project_id}
get target branch logic
Yuki Kimoto authored on 2016-04-27
463
  )->value;
464
  
465
  my $child_project = $self->app->dbi->model('project')->select(
466
    [
467
      {__MY__ => '*'},
remove table __ prefix
Yuki Kimoto authored on 2016-06-11
468
      {user => ['id']}
get target branch logic
Yuki Kimoto authored on 2016-04-27
469
    ],
470
    where => {
471
      'project.original_project' => $project_row_id,
remove table __ prefix
Yuki Kimoto authored on 2016-06-11
472
      'user.id' => $child_user_id
get target branch logic
Yuki Kimoto authored on 2016-04-27
473
    }
474
  )->one;
475
  
476
  return $child_project;
477
}
478

            
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
479
sub projects {
fix user page
Yuki Kimoto authored on 2016-04-21
480
  my ($self, $user_id) = @_;
481
  
482
  my $user_row_id = $self->app->dbi->model('user')->select('row_id', where => {id => $user_id})->value;
483
  
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
484
  # Projects
485
  my $projects = $self->app->dbi->model('project')->select(
fix user page
Yuki Kimoto authored on 2016-04-21
486
    where => {user => $user_row_id},
487
    append => 'order by id'
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
488
  )->all;
489
  
490
  return $projects;
491
}
492

            
cleanup
Yuki Kimoto authored on 2013-05-13
493
sub users {
494
  my $self = shift;
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
495
  
496
  # Users
cleanup
Yuki Kimoto authored on 2013-05-13
497
  my $users = $self->app->dbi->model('user')->select(
498
    where => [':admin{<>}',{admin => 1}],
499
    append => 'order by id'
500
  )->all;
501
  
502
  return $users;
503
}
504

            
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
505
sub rename_project {
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
506
  my ($self, $user, $project, $to_project) = @_;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
507
  
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
508
  # Rename project
revert encoding support
Yuki Kimoto authored on 2013-11-22
509
  my $git = $self->app->git;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
510
  my $dbi = $self->app->dbi;
simplify rename project
Yuki Kimoto authored on 2013-05-22
511
  my $error;
512
  eval {
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
513
    $dbi->connector->txn(sub {
simplify rename project
Yuki Kimoto authored on 2013-05-22
514
      eval { $self->_rename_project($user, $project, $to_project) };
515
      croak $error = $@ if $@;
516
      eval { $self->_rename_rep($user, $project, $to_project) };
517
      croak $error = $@ if $@;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
518
    });
simplify rename project
Yuki Kimoto authored on 2013-05-22
519
  };
520
  croak $error if $error;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
521
}
522

            
add key delete feature and u...
gitprep authored on 2014-05-19
523
sub update_authorized_keys_file {
524
  my $self = shift;
525

            
526
  my $authorized_keys_file = $self->authorized_keys_file;
527
  if (defined $authorized_keys_file) {
528
    
529
    # Lock file
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
530
    my $lock_file = $self->app->home->rel_file('lock/authorized_keys');
add key delete feature and u...
gitprep authored on 2014-05-19
531
    open my $lock_fh, $lock_file
532
      or croak "Can't open lock file $lock_file";
533
    flock $lock_fh, LOCK_EX
534
      or croak "Can't lock $lock_file";
535
    
536
    # Create authorized_keys_file
537
    unless (-f $authorized_keys_file) {
538
      open my $fh, '>', $authorized_keys_file
fix gitprep-shell
gitprep authored on 2014-05-19
539
        or croak "Can't create authorized_keys file: $authorized_keys_file";
540
      chmod 0600, $authorized_keys_file
541
        or croak "Can't chmod authorized_keys file: $authorized_keys_file";
add key delete feature and u...
gitprep authored on 2014-05-19
542
    }
543
    
544
    # Parse file
forbidden public key which i...
Yuki Kimoto authored on 2014-12-15
545
    my $result = $self->parse_authorized_keys_file($authorized_keys_file);
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
546
    my $before_part = $result->{before_part};
547
    my $gitprep_part = $result->{gitprep_part};
548
    my $after_part = $result->{after_part};
549
    my $start_symbol = $result->{start_symbol};
550
    my $end_symbol = $result->{end_symbol};
add key delete feature and u...
gitprep authored on 2014-05-19
551
    
552
    # Backup at first time
553
    if ($gitprep_part eq '') {
554
      # Backup original file
555
      my $to = "$authorized_keys_file.gitprep.original";
556
      unless (-f $to) {
557
        copy $authorized_keys_file, $to
558
          or croak "Can't copy $authorized_keys_file to $to";
559
      }
560
    }
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
561

            
add key delete feature and u...
gitprep authored on 2014-05-19
562
    # Create public keys
fix ssh public key bug
Yuki Kimoto authored on 2016-05-04
563
    my $ssh_public_keys = $self->app->dbi->model('ssh_public_key')->select(
564
      [
565
        {__MY__ => '*'},
remove table __ prefix
Yuki Kimoto authored on 2016-06-11
566
        {user => ['id']}
fix ssh public key bug
Yuki Kimoto authored on 2016-05-04
567
      ]
568
    )->all;
add key delete feature and u...
gitprep authored on 2014-05-19
569
    my $ssh_public_keys_str = '';
570
    for my $key (@$ssh_public_keys) {
fix permission bug
gitprep authored on 2014-05-19
571
      my $ssh_public_key_str = 'command="' . $self->app->home->rel_file('script/gitprep-shell')
remove table __ prefix
Yuki Kimoto authored on 2016-06-11
572
        . " $key->{'user.id'}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty $key->{key}";
573
      $ssh_public_keys_str .= "$ssh_public_key_str $key->{'user.id'}\n\n";
add key delete feature and u...
gitprep authored on 2014-05-19
574
    }
575
    
576
    # Output tmp file
fix gitprep-shell
gitprep authored on 2014-05-19
577
    my $output = "$before_part$start_symbol\n\n$ssh_public_keys_str$end_symbol$after_part";
add key delete feature and u...
gitprep authored on 2014-05-19
578
    my $output_file = "$authorized_keys_file.gitprep.tmp";
579
    open my $out_fh, '>', $output_file
580
      or croak "Can't create authorized_keys tmp file $output_file";
581
    print $out_fh $output;
582
    close $out_fh
583
      or croak "Can't close authorized_keys tmp file $output_file";
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
584

            
add key delete feature and u...
gitprep authored on 2014-05-19
585
    # Replace
fix permission bug
gitprep authored on 2014-05-19
586
    chmod 0600, $output_file
587
      or croak "Can't chmod authorized_keys tmp file: $output_file";
add key delete feature and u...
gitprep authored on 2014-05-19
588
    move $output_file, $authorized_keys_file
589
      or croak "Can't replace $authorized_keys_file by $output_file";
590
  }
591
  else {
592
    croak qq/authorized_keys file "$authorized_keys_file" is not found./;
593
  }
594
}
595

            
forbidden public key which i...
Yuki Kimoto authored on 2014-12-15
596
sub parse_authorized_keys_file {
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
597
  my ($self, $file) = @_;
add key delete feature and u...
gitprep authored on 2014-05-19
598
  
599
  my $start_symbol = "# gitprep start";
600
  my $end_symbol = "# gitprep end";
601
  
602
  # Parse
603
  open my $fh, '<', $file
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
604
    or croak "Can't open authorized_key file $file";
add key delete feature and u...
gitprep authored on 2014-05-19
605
  my $start_symbol_count = 0;
606
  my $end_symbol_count = 0;
607
  my $before_part = '';
608
  my $gitprep_part = '';
609
  my $after_part = '';
610
  my $error_prefix = "authorized_keys file $file format error:";
611
  while (my $line = <$fh>) {
612
    if ($line =~ /^$start_symbol/) {
613
      if ($start_symbol_count > 0) {
614
        croak qq/$error_prefix "$start_symbol" is found more than one/;
615
      }
616
      else {
617
        if ($end_symbol_count > 0) {
618
          croak qq/$error_prefix "$end_symbol" is found before "$start_symbol"/;
619
        }
620
        else {
621
          $start_symbol_count++;
622
        }
623
      }
624
    }
625
    elsif ($line =~ /^$end_symbol/) {
fix ssh key authentication b...
gitprep authored on 2014-05-20
626
      if ($end_symbol_count > 0) {
add key delete feature and u...
gitprep authored on 2014-05-19
627
        croak qq/$error_prefix "$end_symbol" is found more than one/;
628
      }
629
      else {
fix gitprep-shell
gitprep authored on 2014-05-19
630
        $end_symbol_count++;
add key delete feature and u...
gitprep authored on 2014-05-19
631
      }
632
    }
633
    elsif ($start_symbol_count == 0 && $end_symbol_count == 0) {
634
      $before_part .= $line;
635
    }
636
    elsif ($start_symbol_count == 1 && $end_symbol_count == 0) {
637
      $gitprep_part .= $line;
638
    }
639
    elsif ($start_symbol_count == 1 && $end_symbol_count == 1) {
640
      $after_part .= $line;
641
    }
642
  }
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
643
  
644
  my $result = {
645
    start_symbol => $start_symbol,
646
    end_symbol => $end_symbol,
647
    before_part => $before_part,
648
    gitprep_part => $gitprep_part,
649
    after_part => $after_part
650
  };
651
  
652
  return $result;
add key delete feature and u...
gitprep authored on 2014-05-19
653
}
654

            
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
655
sub _create_project {
fix fork
Yuki Kimoto authored on 2016-04-21
656
  my ($self, $user_id, $project_id, $params) = @_;
657
  
658
  my $user_row_id = $self->api->get_user_row_id($user_id);
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
659
  $params ||= {};
fix fork
Yuki Kimoto authored on 2016-04-21
660
  $params->{user} = $user_row_id;
661
  $params->{id} = $project_id;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
662
  
663
  # Create project
cleanup
Yuki Kimoto authored on 2013-05-15
664
  my $dbi = $self->app->dbi;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
665
  $dbi->connector->txn(sub {
fix fork
Yuki Kimoto authored on 2016-04-21
666
    $dbi->model('project')->insert($params);
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
667
  });
668
}
669

            
670
sub _create_rep {
671
  my ($self, $user, $project, $opts) = @_;
672
  
673
  # Create repository directory
revert encoding support
Yuki Kimoto authored on 2013-11-22
674
  my $git = $self->app->git;
remove rep_path
Yuki Kimoto authored on 2016-04-16
675
  
676
  my $rep_info = $self->app->rep_info($user, $project);
677
  my $rep_git_dir = $rep_info->{git_dir};
678
  
679
  mkdir $rep_git_dir
680
    or croak "Can't create directory $rep_git_dir: $!";
fix bug that in CGI reposito...
Yuki Kimoto authored on 2015-11-05
681
  
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
682
  eval {
683
    # Git init
684
    {
remove cmd_dir
Yuki Kimoto authored on 2016-04-16
685
      my @git_init_cmd = $git->cmd($rep_info, 'init', '--bare');
fix bug that in CGI reposito...
Yuki Kimoto authored on 2015-11-05
686
      Gitprep::Util::run_command(@git_init_cmd)
fix git 2.0 create repositor...
Yuki Kimoto authored on 2015-11-04
687
        or croak  "Can't execute git init --bare:@git_init_cmd";
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
688
    }
689
    
690
    # Add git-daemon-export-ok
691
    {
remove rep_path
Yuki Kimoto authored on 2016-04-16
692
      my $file = "$rep_git_dir/git-daemon-export-ok";
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
693
      open my $fh, '>', $file
694
        or croak "Can't create git-daemon-export-ok: $!"
695
    }
696
    
697
    # HTTP support
remove cmd_dir
Yuki Kimoto authored on 2016-04-16
698
    my @git_update_server_info_cmd = $git->cmd(
699
      $rep_info,
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
700
      '--bare',
701
      'update-server-info'
702
    );
fix bug that in CGI reposito...
Yuki Kimoto authored on 2015-11-05
703
    Gitprep::Util::run_command(@git_update_server_info_cmd)
fix git 2.0 create repositor...
Yuki Kimoto authored on 2015-11-04
704
      or croak "Can't execute git --bare update-server-info";
remove rep_path
Yuki Kimoto authored on 2016-04-16
705
    move("$rep_git_dir/hooks/post-update.sample", "$rep_git_dir/hooks/post-update")
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
706
      or croak "Can't move post-update";
707
    
708
    # Description
version up and add descripti...
Yuki Kimoto authored on 2013-11-22
709
    my $description = $opts->{description};
710
    $description = '' unless defined $description;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
711
    {
remove rep_path
Yuki Kimoto authored on 2016-04-16
712
      my $file = "$rep_git_dir/description";
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
713
      open my $fh, '>', $file
714
        or croak "Can't open $file: $!";
715
      print $fh encode('UTF-8', $description)
716
        or croak "Can't write $file: $!";
717
      close $fh;
718
    }
719
    
720
    # Add README and commit
721
    if ($opts->{readme}) {
722
      # Create working directory
use own tmp directory to cre...
Yuki Kimoto authored on 2016-03-24
723
      my $home_tmp_dir = $self->app->home->rel_file('tmp');
724
      
remove cmd_work_dir
Yuki Kimoto authored on 2016-04-16
725
      # Temp directory
use own tmp directory to cre...
Yuki Kimoto authored on 2016-03-24
726
      my $temp_dir =  File::Temp->newdir(DIR => $home_tmp_dir);
remove cmd_work_dir
Yuki Kimoto authored on 2016-04-16
727
      
728
      # Working repository
729
      my $work_rep_work_tree = "$temp_dir/work";
730
      my $work_rep_git_dir = "$work_rep_work_tree/.git";
731
      my $work_rep_info = {
732
        work_tree => $work_rep_work_tree,
733
        git_dir => $work_rep_git_dir
734
      };
735
      
736
      mkdir $work_rep_work_tree
737
        or croak "Can't create directory $work_rep_work_tree: $!";
use own tmp directory to cre...
Yuki Kimoto authored on 2016-03-24
738
      
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
739
      # Git init
remove cmd_work_dir
Yuki Kimoto authored on 2016-04-16
740
      my @git_init_cmd = $git->cmd($work_rep_info, 'init', '-q');
fix bug that in CGI reposito...
Yuki Kimoto authored on 2015-11-05
741
      Gitprep::Util::run_command(@git_init_cmd)
fix git 2.0 create repositor...
Yuki Kimoto authored on 2015-11-04
742
        or croak "Can't execute git init: @git_init_cmd";
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
743
      
744
      # Add README
remove cmd_work_dir
Yuki Kimoto authored on 2016-04-16
745
      my $file = "$work_rep_work_tree/README.md";
default readme file is chang...
Yuki Kimoto authored on 2013-11-16
746
      open my $readme_fh, '>', $file
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
747
        or croak "Can't create $file: $!";
version up and add descripti...
Yuki Kimoto authored on 2013-11-22
748
      print $readme_fh "# $project\n";
749
      print $readme_fh "\n" . encode('UTF-8', $description) . "\n";
default readme file is chang...
Yuki Kimoto authored on 2013-11-16
750
      close $readme_fh;
751
      
remove cmd_work_dir
Yuki Kimoto authored on 2016-04-16
752
      my @git_add_cmd = $git->cmd(
753
        $work_rep_info,
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
754
        'add',
default readme file is chang...
Yuki Kimoto authored on 2013-11-16
755
        'README.md'
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
756
      );
improve create working repos...
Yuki Kimoto authored on 2016-04-15
757
      
fix bug that in CGI reposito...
Yuki Kimoto authored on 2015-11-05
758
      Gitprep::Util::run_command(@git_add_cmd)
fix git 2.0 create repositor...
Yuki Kimoto authored on 2015-11-04
759
        or croak "Can't execute git add: @git_add_cmd";
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
760
      
fix bug that repository with...
Yuki Kimoto authored on 2016-04-12
761
      # Set user name
remove cmd_work_dir
Yuki Kimoto authored on 2016-04-16
762
      my @git_config_user_name = $git->cmd(
763
        $work_rep_info,
fix bug that repository with...
Yuki Kimoto authored on 2016-04-12
764
        'config',
765
        'user.name',
766
        $user
767
      );
768
      Gitprep::Util::run_command(@git_config_user_name)
769
        or croak "Can't execute git config: @git_config_user_name";
770
      
fix mail bug
Yuki Kimoto authored on 2016-04-21
771
      # Set user email
772
      my $user_email = $self->app->dbi->model('user')->select('email', where => {id => $user})->value;
773
      my @git_config_user_email = $git->cmd(
remove cmd_work_dir
Yuki Kimoto authored on 2016-04-16
774
        $work_rep_info,
fix bug that repository with...
Yuki Kimoto authored on 2016-04-12
775
        'config',
776
        'user.email',
fix mail bug
Yuki Kimoto authored on 2016-04-21
777
        "$user_email"
fix bug that repository with...
Yuki Kimoto authored on 2016-04-12
778
      );
fix mail bug
Yuki Kimoto authored on 2016-04-21
779
      Gitprep::Util::run_command(@git_config_user_email)
780
        or croak "Can't execute git config: @git_config_user_email";
fix bug that repository with...
Yuki Kimoto authored on 2016-04-12
781
      
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
782
      # Commit
remove cmd_work_dir
Yuki Kimoto authored on 2016-04-16
783
      my @git_commit_cmd = $git->cmd(
784
        $work_rep_info,
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
785
        'commit',
786
        '-q',
787
        '-m',
788
        'first commit'
789
      );
fix bug that in CGI reposito...
Yuki Kimoto authored on 2015-11-05
790
      Gitprep::Util::run_command(@git_commit_cmd)
fix git 2.0 create repositor...
Yuki Kimoto authored on 2015-11-04
791
        or croak "Can't execute git commit: @git_commit_cmd";
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
792
      
793
      # Push
794
      {
remove cmd_work_dir
Yuki Kimoto authored on 2016-04-16
795
        my @git_push_cmd = $git->cmd(
796
          $work_rep_info,
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
797
          'push',
798
          '-q',
remove rep_path
Yuki Kimoto authored on 2016-04-16
799
          $rep_git_dir,
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
800
          'master'
801
        );
802
        # (This is bad, but --quiet option can't supress in old git)
fix bug that in CGI reposito...
Yuki Kimoto authored on 2015-11-05
803
        Gitprep::Util::run_command(@git_push_cmd)
fix git 2.0 create repositor...
Yuki Kimoto authored on 2015-11-04
804
          or croak "Can't execute git push: @git_push_cmd";
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
805
      }
806
    }
807
  };
improve faq of pushing lerge...
Yuki Kimoto authored on 2014-02-17
808
  if (my $e = $@) {
remove rep_path
Yuki Kimoto authored on 2016-04-16
809
    rmtree $rep_git_dir;
improve faq of pushing lerge...
Yuki Kimoto authored on 2014-02-17
810
    croak $e;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
811
  }
812
}
813

            
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
814
sub _create_db_user {
fix project page
Yuki Kimoto authored on 2016-04-21
815
  my ($self, $user_id, $data) = @_;
816
  
817
  $data->{id} = $user_id;
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
818
  
819
  # Create database user
fix project page
Yuki Kimoto authored on 2016-04-21
820
  $self->app->dbi->model('user')->insert($data);
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
821
}
822

            
823
sub _create_user_dir {
824
  my ($self, $user) = @_;
825
  
826
  # Create user directory
cleanup ->rep_home
Yuki Kimoto authored on 2016-04-14
827
  my $rep_home = $self->app->rep_home;
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
828
  my $user_dir = "$rep_home/$user";
829
  mkpath $user_dir;
830
}
831

            
832
sub _delete_db_user {
fix project page
Yuki Kimoto authored on 2016-04-21
833
  my ($self, $user_id) = @_;
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
834
  
835
  # Delete database user
fix project page
Yuki Kimoto authored on 2016-04-21
836
  my $count = $self->app->dbi->model('user')->delete(where => {id => $user_id});
added delete user test
Yuki Kimoto authored on 2013-05-18
837
  
838
  return $count;
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
839
}
840

            
841
sub _delete_user_dir {
842
  my ($self, $user) = @_;
843
  
844
  # Delete user directory
cleanup ->rep_home
Yuki Kimoto authored on 2016-04-14
845
  my $rep_home = $self->app->rep_home;
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
846
  my $user_dir = "$rep_home/$user";
847
  rmtree $user_dir;
848
}
849

            
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
850
sub _delete_project {
fix project page
Yuki Kimoto authored on 2016-04-21
851
  my ($self, $user_id, $project_id) = @_;
852
  
853
  my $user_row_id = $self->api->get_user_row_id($user_id);
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
854
  
cleanup
Yuki Kimoto authored on 2013-05-15
855
  # Delete project
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
856
  my $dbi = $self->app->dbi;
fix project page
Yuki Kimoto authored on 2016-04-21
857
  $dbi->model('project')->delete(where => {user => $user_row_id, id => $project_id});
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
858
}
859

            
860
sub _delete_rep {
861
  my ($self, $user, $project) = @_;
862

            
cleanup
Yuki Kimoto authored on 2013-05-15
863
  # Delete repository
cleanup ->rep_home
Yuki Kimoto authored on 2016-04-14
864
  my $rep_home = $self->app->rep_home;
add missing 'o'
reneeb authored on 2013-10-14
865
  croak "Can't remove repository. repository home is empty"
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
866
    if !defined $rep_home || $rep_home eq '';
867
  my $rep = "$rep_home/$user/$project.git";
868
  rmtree $rep;
869
  croak "Can't remove repository. repository is rest"
870
    if -e $rep;
871
}
872

            
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
873
sub exists_project {
fix project page
Yuki Kimoto authored on 2016-04-21
874
  my ($self, $user_id, $project_id) = @_;
875
  
876
  my $user_row_id = $self->api->get_user_row_id($user_id);
cleanup
Yuki Kimoto authored on 2013-05-15
877
  
878
  # Exists project
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
879
  my $dbi = $self->app->dbi;
fix project page
Yuki Kimoto authored on 2016-04-21
880
  my $row = $dbi->model('project')->select(where => {user => $user_row_id, id => $project_id})->one;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
881
  
882
  return $row ? 1 : 0;
883
}
884

            
add rename project and suppr...
Yuki Kimoto authored on 2013-05-24
885
sub exists_user {
fix project page
Yuki Kimoto authored on 2016-04-21
886
  my ($self, $user_id) = @_;
add rename project and suppr...
Yuki Kimoto authored on 2013-05-24
887
  
888
  # Exists project
fix project page
Yuki Kimoto authored on 2016-04-21
889
  my $row = $self->app->dbi->model('user')->select(where => {id => $user_id})->one;
add rename project and suppr...
Yuki Kimoto authored on 2013-05-24
890
  
891
  return $row ? 1 : 0;
892
}
893

            
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
894
sub _exists_rep {
895
  my ($self, $user, $project) = @_;
896
  
cleanup
Yuki Kimoto authored on 2013-05-15
897
  # Exists repository
remove rep_path
Yuki Kimoto authored on 2016-04-16
898
  my $rep_info = $self->app->rep_info($user, $project);
899
  my $rep_git_dir = $rep_info->{git_dir};
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
900
  
remove rep_path
Yuki Kimoto authored on 2016-04-16
901
  return -e $rep_git_dir;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
902
}
903

            
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
904
sub _fork_rep {
fix fork
Yuki Kimoto authored on 2016-04-21
905
  my ($self, $user_id, $project_id, $to_user_id, $to_project_id) = @_;
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
906
  
cleanup
Yuki Kimoto authored on 2013-05-15
907
  # Fork repository
revert encoding support
Yuki Kimoto authored on 2013-11-22
908
  my $git = $self->app->git;
remove rep_path
Yuki Kimoto authored on 2016-04-16
909
  
fix fork
Yuki Kimoto authored on 2016-04-21
910
  my $rep_info = $self->app->rep_info($user_id, $project_id);
remove rep_path
Yuki Kimoto authored on 2016-04-16
911
  my $rep_git_dir = $rep_info->{git_dir};
912
  
fix fork
Yuki Kimoto authored on 2016-04-21
913
  my $to_rep_info = $self->app->rep_info($to_user_id, $to_project_id);
remove rep_path
Yuki Kimoto authored on 2016-04-16
914
  my $to_rep_git_dir = $to_rep_info->{git_dir};
915

            
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
916
  my @cmd = (
917
    $git->bin,
918
    'clone',
919
    '-q',
920
    '--bare',
remove rep_path
Yuki Kimoto authored on 2016-04-16
921
    $rep_git_dir,
922
    $to_rep_git_dir
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
923
  );
fix bug that in CGI reposito...
Yuki Kimoto authored on 2015-11-05
924
  Gitprep::Util::run_command(@cmd)
fix description file not cop...
Yuki Kimoto authored on 2013-05-25
925
    or croak "Can't fork repository(_fork_rep): @cmd";
926
  
927
  # Copy description
remove rep_path
Yuki Kimoto authored on 2016-04-16
928
  copy "$rep_git_dir/description", "$to_rep_git_dir/description"
fix description file not cop...
Yuki Kimoto authored on 2013-05-25
929
    or croak "Can't copy description file(_fork_rep)";
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
930
}
931

            
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
932
sub _rename_project {
fix project page
Yuki Kimoto authored on 2016-04-21
933
  my ($self, $user_id, $project_id, $renamed_project_id) = @_;
934
  
935
  my $user_row_id = $self->api->get_user_row_id($user_id);
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
936
  
cleanup
Yuki Kimoto authored on 2013-05-15
937
  # Check arguments
add rename project and suppr...
Yuki Kimoto authored on 2013-05-24
938
  croak "Invalid parameters(_rename_project)"
fix project page
Yuki Kimoto authored on 2016-04-21
939
    unless defined $user_id && defined $project_id && defined $renamed_project_id;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
940
  
941
  # Rename project
cleanup
Yuki Kimoto authored on 2013-05-15
942
  my $dbi = $self->app->dbi;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
943
  $dbi->model('project')->update(
fix project page
Yuki Kimoto authored on 2016-04-21
944
    {id => $renamed_project_id},
945
    where => {user => $user_row_id, id => $project_id}
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
946
  );
947
}
948

            
949
sub _rename_rep {
950
  my ($self, $user, $project, $renamed_project) = @_;
951
  
cleanup
Yuki Kimoto authored on 2013-05-15
952
  # Check arguments
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
953
  croak "Invalid user name or project"
954
    unless defined $user && defined $project && defined $renamed_project;
cleanup
Yuki Kimoto authored on 2013-05-15
955

            
956
  # Rename repository
remove rep_path
Yuki Kimoto authored on 2016-04-16
957
  my $rep_info = $self->app->rep_info($user, $project);
958
  my $rep_git_dir = $rep_info->{git_dir};
959
  
960
  my $renamed_rep_info = $self->app->rep_info($user, $renamed_project);
961
  my $renamed_rep_git_dir = $renamed_rep_info->{git_dir};
962

            
963
  move($rep_git_dir, $renamed_rep_git_dir)
964
    or croak "Can't move $rep_git_dir to $renamed_rep_git_dir: $!";
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
965
}
966

            
967
1;