gitprep / lib / Gitprep / Manager.pm /
Newer Older
945 lines | 24.81kb
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});
cleanup prepare merge
Yuki Kimoto authored on 2016-04-23
31
  Gitprep::Util::run_command(@git_fetch_target_cmd)
32
    or Carp::croak "Can't execute git fetch: @git_fetch_target_cmd";
cleanup merge and push logic
Yuki Kimoto authored on 2016-04-27
33

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

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

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

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

            
132
sub push {
fix merge pull request bug
Yuki Kimoto authored on 2016-04-27
133
  my ($self, $work_rep_info, $base_branch) = @_;
cleanup merge and push logic
Yuki Kimoto authored on 2016-04-27
134
  
135
  # Push
fix merge pull request bug
Yuki Kimoto authored on 2016-04-27
136
  my $tmp_branch = $self->_tmp_branch;
137
  my @git_push_cmd = $self->app->git->cmd(
138
    $work_rep_info,
139
    'push',
140
    'origin',
141
    "$tmp_branch:$base_branch"
142
  );
cleanup merge and push logic
Yuki Kimoto authored on 2016-04-27
143
  Gitprep::Util::run_command(@git_push_cmd)
144
    or Carp::croak "Can't execute git push: @git_push_cmd";
145
}
146

            
cleanup prepare merge
Yuki Kimoto authored on 2016-04-23
147
sub lock_rep {
148
  my ($self, $rep_info) = @_;
149
  
150
  my $git_dir = $rep_info->{git_dir};
151
  my $lock_file = "$git_dir/config";
152
  
153
  open my $lock_fh, '<', $lock_file
154
    or croak "Can't open lock file $lock_file: $!";
155
    
156
  flock $lock_fh, LOCK_EX
157
    or croak "Can't lock $lock_file";
158
  
159
  return $lock_fh;
160
}
161

            
cleanup
Yuki Kimoto authored on 2016-04-16
162
sub create_work_rep {
improve create working repos...
Yuki Kimoto authored on 2016-04-15
163
  my ($self, $user, $project) = @_;
164
  
cleanup create working direc...
Yuki Kimoto authored on 2016-04-16
165
  # Remote repository
166
  my $rep_info = $self->app->rep_info($user, $project);
167
  my $rep_git_dir = $rep_info->{git_dir};
168
  
169
  # Working repository
170
  my $work_rep_info = $self->app->work_rep_info($user, $project);
171
  my $work_tree = $work_rep_info->{work_tree};
172
  
improve create working repos...
Yuki Kimoto authored on 2016-04-15
173
  # Create working repository if it don't exist
cleanup create working direc...
Yuki Kimoto authored on 2016-04-16
174
  unless (-e $work_tree) {
175

            
improve create working repos...
Yuki Kimoto authored on 2016-04-15
176
    # git clone
cleanup create working direc...
Yuki Kimoto authored on 2016-04-16
177
    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
178
    Gitprep::Util::run_command(@git_clone_cmd)
179
      or croak "Can't git clone: @git_clone_cmd";
cleanup compare logic
Yuki Kimoto authored on 2016-04-18
180
    
improve create working repos...
Yuki Kimoto authored on 2016-04-15
181
    # Set user name
cleanup create working direc...
Yuki Kimoto authored on 2016-04-16
182
    my @git_config_user_name = $self->app->git->cmd(
183
      $work_rep_info,
improve create working repos...
Yuki Kimoto authored on 2016-04-15
184
      'config',
185
      'user.name',
186
      $user
187
    );
188
    Gitprep::Util::run_command(@git_config_user_name)
189
      or croak "Can't execute git config: @git_config_user_name";
190
    
fix mail bug
Yuki Kimoto authored on 2016-04-21
191
    # Set user email
192
    my $user_email = $self->app->dbi->model('user')->select('email', where => {id => $user})->value;
193
    my @git_config_user_email = $self->app->git->cmd(
cleanup create working direc...
Yuki Kimoto authored on 2016-04-16
194
      $work_rep_info,
improve create working repos...
Yuki Kimoto authored on 2016-04-15
195
      'config',
196
      'user.email',
fix mail bug
Yuki Kimoto authored on 2016-04-21
197
      "$user_email"
improve create working repos...
Yuki Kimoto authored on 2016-04-15
198
    );
fix mail bug
Yuki Kimoto authored on 2016-04-21
199
    Gitprep::Util::run_command(@git_config_user_email)
200
      or croak "Can't execute git config: @git_config_user_email";
improve create working repos...
Yuki Kimoto authored on 2016-04-15
201
  }
202
}
203

            
added admin tests
Yuki Kimoto authored on 2013-05-16
204
sub admin_user {
cleanup
Yuki Kimoto authored on 2013-05-13
205
  my $self = shift;
206
  
207
  # Admin user
208
  my $admin_user = $self->app->dbi->model('user')
added admin tests
Yuki Kimoto authored on 2013-05-16
209
    ->select(where => {admin => 1})->one;
cleanup
Yuki Kimoto authored on 2013-05-13
210
  
211
  return $admin_user;
212
}
213

            
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
214
sub default_branch {
fix project page
Yuki Kimoto authored on 2016-04-21
215
  my ($self, $user_id, $project_id, $default_branch) = @_;
216
  
217
  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
218
  
added default branch change ...
Yuki Kimoto authored on 2013-05-22
219
  # Set default branch
220
  my $dbi = $self->app->dbi;
221
  if (defined $default_branch) {
222
    $dbi->model('project')->update(
223
      {default_branch => $default_branch},
fix project page
Yuki Kimoto authored on 2016-04-21
224
      where => {user => $user_row_id, id => $project_id}
added default branch change ...
Yuki Kimoto authored on 2013-05-22
225
    );
226
  }
227
  else {
228
    # Get default branch
229
    my $default_branch = $dbi->model('project')
fix project page
Yuki Kimoto authored on 2016-04-21
230
      ->select('default_branch', where => {user => $user_row_id, id => $project_id})
added default branch change ...
Yuki Kimoto authored on 2013-05-22
231
      ->value;
232
    
233
    return $default_branch;
234
  }
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
235
}
236

            
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
237
sub fork_project {
cleanup
Yuki Kimoto authored on 2016-04-22
238
  my ($self, $forked_user_id, $user_id, $project_id) = @_;
fix fork
Yuki Kimoto authored on 2016-04-21
239
  
cleanup
Yuki Kimoto authored on 2016-04-22
240
  my $user_row_id = $self->api->get_user_row_id($user_id);
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
241
  
242
  # Fork project
243
  my $dbi = $self->app->dbi;
244
  my $error;
245
  eval {
246
    $dbi->connector->txn(sub {
247
      
248
      # Original project id
fix fork
Yuki Kimoto authored on 2016-04-21
249
      my $project = $dbi->model('project')->select(
cleanup
Yuki Kimoto authored on 2016-04-22
250
        {__MY__ => ['row_id', 'private']},
cleanup join table
Yuki Kimoto authored on 2016-04-28
251
        where => {'__user.id' => $user_id, 'project.id' => $project_id}
version up and add descripti...
Yuki Kimoto authored on 2013-11-22
252
      )->one;
253
      
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
254
      # Create project
255
      eval {
256
        $self->_create_project(
cleanup
Yuki Kimoto authored on 2016-04-22
257
          $forked_user_id,
fix fork
Yuki Kimoto authored on 2016-04-21
258
          $project_id,
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
259
          {
fix fork
Yuki Kimoto authored on 2016-04-21
260
            original_project => $project->{row_id},
261
            private => $project->{private}
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
262
          }
263
        );
264
      };
265
      croak $error = $@ if $@;
266
      
267
      # Create repository
268
      eval {
cleanup
Yuki Kimoto authored on 2016-04-22
269
        $self->_fork_rep($user_id, $project_id, $forked_user_id, $project_id);
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
270
      };
271
      croak $error = $@ if $@;
272
    });
273
  };
274
  croak $error if $@;
275
}
276

            
cleanup
Yuki Kimoto authored on 2013-05-13
277
sub is_admin {
fix project page
Yuki Kimoto authored on 2016-04-21
278
  my ($self, $user_id) = @_;
cleanup
Yuki Kimoto authored on 2013-05-13
279
  
280
  # Check admin
281
  my $is_admin = $self->app->dbi->model('user')
fix project page
Yuki Kimoto authored on 2016-04-21
282
    ->select('admin', where => {id => $user_id})->value;
cleanup
Yuki Kimoto authored on 2013-05-13
283
  
284
  return $is_admin;
285
}
286

            
add private checkbox
Yuki Kimoto authored on 2013-11-16
287
sub is_private_project {
fix project page
Yuki Kimoto authored on 2016-04-21
288
  my ($self, $user_id, $project_id) = @_;
289
  
290
  my $user_row_id = $self->api->get_user_row_id($user_id);
add private checkbox
Yuki Kimoto authored on 2013-11-16
291
  
292
  # Is private
fix setting page
Yuki Kimoto authored on 2016-04-21
293
  my $private = $self->app->dbi->model('project')->select(
294
    'private', where => {user => $user_row_id, id => $project_id}
295
  )->value;
add private checkbox
Yuki Kimoto authored on 2013-11-16
296
  
297
  return $private;
298
}
299

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

            
302

            
fix network page
Yuki Kimoto authored on 2016-04-21
303
sub member_projects {
fix project page
Yuki Kimoto authored on 2016-04-21
304
  my ($self, $user_id, $project_id) = @_;
305
  
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
306
  # DBI
307
  my $dbi = $self->app->dbi;
308
  
cleanup
Yuki Kimoto authored on 2016-04-22
309
  # project id
310
  my $project_row_id = $dbi->model('project')->select(
311
    'project.row_id',
cleanup join table
Yuki Kimoto authored on 2016-04-28
312
    where => {'__user.id' => $user_id, 'project.id' => $project_id}
cleanup
Yuki Kimoto authored on 2016-04-22
313
  )->value;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
314
  
315
  # Members
cleanup
Yuki Kimoto authored on 2016-04-22
316
  my $member_projects = $dbi->model('project')->select(
fix project page
Yuki Kimoto authored on 2016-04-21
317
    [
fix network page
Yuki Kimoto authored on 2016-04-21
318
      {__MY__ => ['id']},
cleanup join table
Yuki Kimoto authored on 2016-04-28
319
      {__user => ['id']}
fix project page
Yuki Kimoto authored on 2016-04-21
320
    ],
fix network page
Yuki Kimoto authored on 2016-04-21
321
    where => {
322
      original_project => $project_row_id,
323
    },
cleanup join table
Yuki Kimoto authored on 2016-04-28
324
    append => 'order by __user.id, project.id'
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
325
  )->all;
326

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

            
330
sub create_project {
fix fork
Yuki Kimoto authored on 2016-04-21
331
  my ($self, $user_id, $project_id, $opts) = @_;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
332
  
add private checkbox to new ...
Yuki Kimoto authored on 2013-11-26
333
  my $params = {};
334
  if ($opts->{private}) {
335
    $params->{private} = 1;
336
  }
337
  
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
338
  # Create project
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
339
  my $dbi = $self->app->dbi;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
340
  my $error;
341
  eval {
342
    $dbi->connector->txn(sub {
fix fork
Yuki Kimoto authored on 2016-04-21
343
      eval { $self->_create_project($user_id, $project_id, $params) };
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
344
      croak $error = $@ if $@;
fix fork
Yuki Kimoto authored on 2016-04-21
345
      eval {$self->_create_rep($user_id, $project_id, $opts) };
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
346
      croak $error = $@ if $@;
347
    });
348
  };
349
  croak $error if $@;
350
}
351

            
352
sub create_user {
353
  my ($self, $user, $data) = @_;
354

            
355
  # Create user
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
356
  my $dbi = $self->app->dbi;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
357
  my $error;
358
  eval {
359
    $dbi->connector->txn(sub {
360
      eval { $self->_create_db_user($user, $data) };
361
      croak $error = $@ if $@;
362
      eval {$self->_create_user_dir($user) };
363
      croak $error = $@ if $@;
364
    });
365
  };
366
  croak $error if $@;
367
}
368

            
369
sub delete_project {
370
  my ($self, $user, $project) = @_;
371
  
372
  # Delete project
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
373
  my $dbi = $self->app->dbi;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
374
  my $error;
375
  eval {
376
    $dbi->connector->txn(sub {
377
      eval { $self->_delete_project($user, $project) };
378
      croak $error = $@ if $@;
379
      eval {$self->_delete_rep($user, $project) };
380
      croak $error = $@ if $@;
381
    });
382
  };
383
  croak $error if $@;
384
}
385

            
386
sub delete_user {
387
  my ($self, $user) = @_;
388
  
389
  # Delete user
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
390
  my $dbi = $self->app->dbi;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
391
  my $error;
added delete user test
Yuki Kimoto authored on 2013-05-18
392
  my $count;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
393
  eval {
394
    $dbi->connector->txn(sub {
added delete user test
Yuki Kimoto authored on 2013-05-18
395
      eval { $count = $self->_delete_db_user($user) };
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
396
      croak $error = $@ if $@;
397
      eval {$self->_delete_user_dir($user) };
398
      croak $error = $@ if $@;
399
    });
400
  };
401
  croak $error if $@;
added delete user test
Yuki Kimoto authored on 2013-05-18
402
  
403
  return $count;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
404
}
405

            
406
sub original_project {
fix project page
Yuki Kimoto authored on 2016-04-21
407
  my ($self, $user_id, $project_id) = @_;
408
  
409
  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
410
  
cleanup delete original_proj...
Yuki Kimoto authored on 2013-05-26
411
  # Original project id
412
  my $dbi = $self->app->dbi;
fix project page
Yuki Kimoto authored on 2016-04-21
413
  my $original_project_row_id = $dbi->model('project')->select(
414
    'original_project',
415
    where => {user => $user_row_id, id => $project_id}
416
  )->value;
cleanup delete original_proj...
Yuki Kimoto authored on 2013-05-26
417
  
fix project page
Yuki Kimoto authored on 2016-04-21
418
  croak "Original project don't eixsts." unless defined $original_project_row_id;
cleanup delete original_proj...
Yuki Kimoto authored on 2013-05-26
419
  
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
420
  # Original project
cleanup delete original_proj...
Yuki Kimoto authored on 2013-05-26
421
  my $original_project = $dbi->model('project')->select(
fix project page
Yuki Kimoto authored on 2016-04-21
422
    [
423
      {__MY__ => '*'},
cleanup join table
Yuki Kimoto authored on 2016-04-28
424
      {__user => ['id']}
fix project page
Yuki Kimoto authored on 2016-04-21
425
    ],
cleanup delete original_proj...
Yuki Kimoto authored on 2013-05-26
426
    where => {
fix project page
Yuki Kimoto authored on 2016-04-21
427
      'project.row_id' => $original_project_row_id
cleanup delete original_proj...
Yuki Kimoto authored on 2013-05-26
428
    }
fix project page
Yuki Kimoto authored on 2016-04-21
429
  )->one;
cleanup delete original_proj...
Yuki Kimoto authored on 2013-05-26
430
  
fix project page
Yuki Kimoto authored on 2016-04-21
431
  return unless defined $original_project;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
432
  
433
  return $original_project;
434
}
435

            
get target branch logic
Yuki Kimoto authored on 2016-04-27
436
sub child_project {
437
  my ($self, $user_id, $project_id, $child_user_id) = @_;
438
  
439
  my $project_row_id = $self->app->dbi->model('project')->select(
cleanup join table
Yuki Kimoto authored on 2016-04-28
440
    'project.row_id', where => {'__user.id' => $user_id, 'project.id' => $project_id}
get target branch logic
Yuki Kimoto authored on 2016-04-27
441
  )->value;
442
  
443
  my $child_project = $self->app->dbi->model('project')->select(
444
    [
445
      {__MY__ => '*'},
improve compare page popup
Yuki Kimoto authored on 2016-04-28
446
      {__user => ['id']}
get target branch logic
Yuki Kimoto authored on 2016-04-27
447
    ],
448
    where => {
449
      'project.original_project' => $project_row_id,
cleanup join table
Yuki Kimoto authored on 2016-04-28
450
      '__user.id' => $child_user_id
get target branch logic
Yuki Kimoto authored on 2016-04-27
451
    }
452
  )->one;
453
  
454
  return $child_project;
455
}
456

            
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
457
sub projects {
fix user page
Yuki Kimoto authored on 2016-04-21
458
  my ($self, $user_id) = @_;
459
  
460
  my $user_row_id = $self->app->dbi->model('user')->select('row_id', where => {id => $user_id})->value;
461
  
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
462
  # Projects
463
  my $projects = $self->app->dbi->model('project')->select(
fix user page
Yuki Kimoto authored on 2016-04-21
464
    where => {user => $user_row_id},
465
    append => 'order by id'
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
466
  )->all;
467
  
468
  return $projects;
469
}
470

            
cleanup
Yuki Kimoto authored on 2013-05-13
471
sub users {
472
  my $self = shift;
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
473
  
474
  # Users
cleanup
Yuki Kimoto authored on 2013-05-13
475
  my $users = $self->app->dbi->model('user')->select(
476
    where => [':admin{<>}',{admin => 1}],
477
    append => 'order by id'
478
  )->all;
479
  
480
  return $users;
481
}
482

            
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
483
sub rename_project {
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
484
  my ($self, $user, $project, $to_project) = @_;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
485
  
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
486
  # Rename project
revert encoding support
Yuki Kimoto authored on 2013-11-22
487
  my $git = $self->app->git;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
488
  my $dbi = $self->app->dbi;
simplify rename project
Yuki Kimoto authored on 2013-05-22
489
  my $error;
490
  eval {
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
491
    $dbi->connector->txn(sub {
simplify rename project
Yuki Kimoto authored on 2013-05-22
492
      eval { $self->_rename_project($user, $project, $to_project) };
493
      croak $error = $@ if $@;
494
      eval { $self->_rename_rep($user, $project, $to_project) };
495
      croak $error = $@ if $@;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
496
    });
simplify rename project
Yuki Kimoto authored on 2013-05-22
497
  };
498
  croak $error if $error;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
499
}
500

            
add key delete feature and u...
gitprep authored on 2014-05-19
501
sub update_authorized_keys_file {
502
  my $self = shift;
503

            
504
  my $authorized_keys_file = $self->authorized_keys_file;
505
  if (defined $authorized_keys_file) {
506
    
507
    # Lock file
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
508
    my $lock_file = $self->app->home->rel_file('lock/authorized_keys');
add key delete feature and u...
gitprep authored on 2014-05-19
509
    open my $lock_fh, $lock_file
510
      or croak "Can't open lock file $lock_file";
511
    flock $lock_fh, LOCK_EX
512
      or croak "Can't lock $lock_file";
513
    
514
    # Create authorized_keys_file
515
    unless (-f $authorized_keys_file) {
516
      open my $fh, '>', $authorized_keys_file
fix gitprep-shell
gitprep authored on 2014-05-19
517
        or croak "Can't create authorized_keys file: $authorized_keys_file";
518
      chmod 0600, $authorized_keys_file
519
        or croak "Can't chmod authorized_keys file: $authorized_keys_file";
add key delete feature and u...
gitprep authored on 2014-05-19
520
    }
521
    
522
    # Parse file
forbidden public key which i...
Yuki Kimoto authored on 2014-12-15
523
    my $result = $self->parse_authorized_keys_file($authorized_keys_file);
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
524
    my $before_part = $result->{before_part};
525
    my $gitprep_part = $result->{gitprep_part};
526
    my $after_part = $result->{after_part};
527
    my $start_symbol = $result->{start_symbol};
528
    my $end_symbol = $result->{end_symbol};
add key delete feature and u...
gitprep authored on 2014-05-19
529
    
530
    # Backup at first time
531
    if ($gitprep_part eq '') {
532
      # Backup original file
533
      my $to = "$authorized_keys_file.gitprep.original";
534
      unless (-f $to) {
535
        copy $authorized_keys_file, $to
536
          or croak "Can't copy $authorized_keys_file to $to";
537
      }
538
    }
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
539

            
add key delete feature and u...
gitprep authored on 2014-05-19
540
    # Create public keys
fix ssh public key bug
Yuki Kimoto authored on 2016-05-04
541
    my $ssh_public_keys = $self->app->dbi->model('ssh_public_key')->select(
542
      [
543
        {__MY__ => '*'},
544
        {__user => ['id']}
545
      ]
546
    )->all;
add key delete feature and u...
gitprep authored on 2014-05-19
547
    my $ssh_public_keys_str = '';
548
    for my $key (@$ssh_public_keys) {
fix permission bug
gitprep authored on 2014-05-19
549
      my $ssh_public_key_str = 'command="' . $self->app->home->rel_file('script/gitprep-shell')
fix ssh public key bug
Yuki Kimoto authored on 2016-05-04
550
        . " $key->{'__user.id'}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty $key->{key}";
551
      $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
552
    }
553
    
554
    # Output tmp file
fix gitprep-shell
gitprep authored on 2014-05-19
555
    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
556
    my $output_file = "$authorized_keys_file.gitprep.tmp";
557
    open my $out_fh, '>', $output_file
558
      or croak "Can't create authorized_keys tmp file $output_file";
559
    print $out_fh $output;
560
    close $out_fh
561
      or croak "Can't close authorized_keys tmp file $output_file";
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
562

            
add key delete feature and u...
gitprep authored on 2014-05-19
563
    # Replace
fix permission bug
gitprep authored on 2014-05-19
564
    chmod 0600, $output_file
565
      or croak "Can't chmod authorized_keys tmp file: $output_file";
add key delete feature and u...
gitprep authored on 2014-05-19
566
    move $output_file, $authorized_keys_file
567
      or croak "Can't replace $authorized_keys_file by $output_file";
568
  }
569
  else {
570
    croak qq/authorized_keys file "$authorized_keys_file" is not found./;
571
  }
572
}
573

            
forbidden public key which i...
Yuki Kimoto authored on 2014-12-15
574
sub parse_authorized_keys_file {
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
575
  my ($self, $file) = @_;
add key delete feature and u...
gitprep authored on 2014-05-19
576
  
577
  my $start_symbol = "# gitprep start";
578
  my $end_symbol = "# gitprep end";
579
  
580
  # Parse
581
  open my $fh, '<', $file
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
582
    or croak "Can't open authorized_key file $file";
add key delete feature and u...
gitprep authored on 2014-05-19
583
  my $start_symbol_count = 0;
584
  my $end_symbol_count = 0;
585
  my $before_part = '';
586
  my $gitprep_part = '';
587
  my $after_part = '';
588
  my $error_prefix = "authorized_keys file $file format error:";
589
  while (my $line = <$fh>) {
590
    if ($line =~ /^$start_symbol/) {
591
      if ($start_symbol_count > 0) {
592
        croak qq/$error_prefix "$start_symbol" is found more than one/;
593
      }
594
      else {
595
        if ($end_symbol_count > 0) {
596
          croak qq/$error_prefix "$end_symbol" is found before "$start_symbol"/;
597
        }
598
        else {
599
          $start_symbol_count++;
600
        }
601
      }
602
    }
603
    elsif ($line =~ /^$end_symbol/) {
fix ssh key authentication b...
gitprep authored on 2014-05-20
604
      if ($end_symbol_count > 0) {
add key delete feature and u...
gitprep authored on 2014-05-19
605
        croak qq/$error_prefix "$end_symbol" is found more than one/;
606
      }
607
      else {
fix gitprep-shell
gitprep authored on 2014-05-19
608
        $end_symbol_count++;
add key delete feature and u...
gitprep authored on 2014-05-19
609
      }
610
    }
611
    elsif ($start_symbol_count == 0 && $end_symbol_count == 0) {
612
      $before_part .= $line;
613
    }
614
    elsif ($start_symbol_count == 1 && $end_symbol_count == 0) {
615
      $gitprep_part .= $line;
616
    }
617
    elsif ($start_symbol_count == 1 && $end_symbol_count == 1) {
618
      $after_part .= $line;
619
    }
620
  }
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
621
  
622
  my $result = {
623
    start_symbol => $start_symbol,
624
    end_symbol => $end_symbol,
625
    before_part => $before_part,
626
    gitprep_part => $gitprep_part,
627
    after_part => $after_part
628
  };
629
  
630
  return $result;
add key delete feature and u...
gitprep authored on 2014-05-19
631
}
632

            
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
633
sub _create_project {
fix fork
Yuki Kimoto authored on 2016-04-21
634
  my ($self, $user_id, $project_id, $params) = @_;
635
  
636
  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
637
  $params ||= {};
fix fork
Yuki Kimoto authored on 2016-04-21
638
  $params->{user} = $user_row_id;
639
  $params->{id} = $project_id;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
640
  
641
  # Create project
cleanup
Yuki Kimoto authored on 2013-05-15
642
  my $dbi = $self->app->dbi;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
643
  $dbi->connector->txn(sub {
fix fork
Yuki Kimoto authored on 2016-04-21
644
    $dbi->model('project')->insert($params);
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
645
  });
646
}
647

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

            
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
792
sub _create_db_user {
fix project page
Yuki Kimoto authored on 2016-04-21
793
  my ($self, $user_id, $data) = @_;
794
  
795
  $data->{id} = $user_id;
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
796
  
797
  # Create database user
fix project page
Yuki Kimoto authored on 2016-04-21
798
  $self->app->dbi->model('user')->insert($data);
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
799
}
800

            
801
sub _create_user_dir {
802
  my ($self, $user) = @_;
803
  
804
  # Create user directory
cleanup ->rep_home
Yuki Kimoto authored on 2016-04-14
805
  my $rep_home = $self->app->rep_home;
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
806
  my $user_dir = "$rep_home/$user";
807
  mkpath $user_dir;
808
}
809

            
810
sub _delete_db_user {
fix project page
Yuki Kimoto authored on 2016-04-21
811
  my ($self, $user_id) = @_;
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
812
  
813
  # Delete database user
fix project page
Yuki Kimoto authored on 2016-04-21
814
  my $count = $self->app->dbi->model('user')->delete(where => {id => $user_id});
added delete user test
Yuki Kimoto authored on 2013-05-18
815
  
816
  return $count;
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
817
}
818

            
819
sub _delete_user_dir {
820
  my ($self, $user) = @_;
821
  
822
  # Delete user directory
cleanup ->rep_home
Yuki Kimoto authored on 2016-04-14
823
  my $rep_home = $self->app->rep_home;
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
824
  my $user_dir = "$rep_home/$user";
825
  rmtree $user_dir;
826
}
827

            
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
828
sub _delete_project {
fix project page
Yuki Kimoto authored on 2016-04-21
829
  my ($self, $user_id, $project_id) = @_;
830
  
831
  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
832
  
cleanup
Yuki Kimoto authored on 2013-05-15
833
  # Delete project
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
834
  my $dbi = $self->app->dbi;
fix project page
Yuki Kimoto authored on 2016-04-21
835
  $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
836
}
837

            
838
sub _delete_rep {
839
  my ($self, $user, $project) = @_;
840

            
cleanup
Yuki Kimoto authored on 2013-05-15
841
  # Delete repository
cleanup ->rep_home
Yuki Kimoto authored on 2016-04-14
842
  my $rep_home = $self->app->rep_home;
add missing 'o'
reneeb authored on 2013-10-14
843
  croak "Can't remove repository. repository home is empty"
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
844
    if !defined $rep_home || $rep_home eq '';
845
  my $rep = "$rep_home/$user/$project.git";
846
  rmtree $rep;
847
  croak "Can't remove repository. repository is rest"
848
    if -e $rep;
849
}
850

            
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
851
sub exists_project {
fix project page
Yuki Kimoto authored on 2016-04-21
852
  my ($self, $user_id, $project_id) = @_;
853
  
854
  my $user_row_id = $self->api->get_user_row_id($user_id);
cleanup
Yuki Kimoto authored on 2013-05-15
855
  
856
  # Exists project
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
857
  my $dbi = $self->app->dbi;
fix project page
Yuki Kimoto authored on 2016-04-21
858
  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
859
  
860
  return $row ? 1 : 0;
861
}
862

            
add rename project and suppr...
Yuki Kimoto authored on 2013-05-24
863
sub exists_user {
fix project page
Yuki Kimoto authored on 2016-04-21
864
  my ($self, $user_id) = @_;
add rename project and suppr...
Yuki Kimoto authored on 2013-05-24
865
  
866
  # Exists project
fix project page
Yuki Kimoto authored on 2016-04-21
867
  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
868
  
869
  return $row ? 1 : 0;
870
}
871

            
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
872
sub _exists_rep {
873
  my ($self, $user, $project) = @_;
874
  
cleanup
Yuki Kimoto authored on 2013-05-15
875
  # Exists repository
remove rep_path
Yuki Kimoto authored on 2016-04-16
876
  my $rep_info = $self->app->rep_info($user, $project);
877
  my $rep_git_dir = $rep_info->{git_dir};
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
878
  
remove rep_path
Yuki Kimoto authored on 2016-04-16
879
  return -e $rep_git_dir;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
880
}
881

            
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
882
sub _fork_rep {
fix fork
Yuki Kimoto authored on 2016-04-21
883
  my ($self, $user_id, $project_id, $to_user_id, $to_project_id) = @_;
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
884
  
cleanup
Yuki Kimoto authored on 2013-05-15
885
  # Fork repository
revert encoding support
Yuki Kimoto authored on 2013-11-22
886
  my $git = $self->app->git;
remove rep_path
Yuki Kimoto authored on 2016-04-16
887
  
fix fork
Yuki Kimoto authored on 2016-04-21
888
  my $rep_info = $self->app->rep_info($user_id, $project_id);
remove rep_path
Yuki Kimoto authored on 2016-04-16
889
  my $rep_git_dir = $rep_info->{git_dir};
890
  
fix fork
Yuki Kimoto authored on 2016-04-21
891
  my $to_rep_info = $self->app->rep_info($to_user_id, $to_project_id);
remove rep_path
Yuki Kimoto authored on 2016-04-16
892
  my $to_rep_git_dir = $to_rep_info->{git_dir};
893

            
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
894
  my @cmd = (
895
    $git->bin,
896
    'clone',
897
    '-q',
898
    '--bare',
remove rep_path
Yuki Kimoto authored on 2016-04-16
899
    $rep_git_dir,
900
    $to_rep_git_dir
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
901
  );
fix bug that in CGI reposito...
Yuki Kimoto authored on 2015-11-05
902
  Gitprep::Util::run_command(@cmd)
fix description file not cop...
Yuki Kimoto authored on 2013-05-25
903
    or croak "Can't fork repository(_fork_rep): @cmd";
904
  
905
  # Copy description
remove rep_path
Yuki Kimoto authored on 2016-04-16
906
  copy "$rep_git_dir/description", "$to_rep_git_dir/description"
fix description file not cop...
Yuki Kimoto authored on 2013-05-25
907
    or croak "Can't copy description file(_fork_rep)";
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
908
}
909

            
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
910
sub _rename_project {
fix project page
Yuki Kimoto authored on 2016-04-21
911
  my ($self, $user_id, $project_id, $renamed_project_id) = @_;
912
  
913
  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
914
  
cleanup
Yuki Kimoto authored on 2013-05-15
915
  # Check arguments
add rename project and suppr...
Yuki Kimoto authored on 2013-05-24
916
  croak "Invalid parameters(_rename_project)"
fix project page
Yuki Kimoto authored on 2016-04-21
917
    unless defined $user_id && defined $project_id && defined $renamed_project_id;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
918
  
919
  # Rename project
cleanup
Yuki Kimoto authored on 2013-05-15
920
  my $dbi = $self->app->dbi;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
921
  $dbi->model('project')->update(
fix project page
Yuki Kimoto authored on 2016-04-21
922
    {id => $renamed_project_id},
923
    where => {user => $user_row_id, id => $project_id}
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
924
  );
925
}
926

            
927
sub _rename_rep {
928
  my ($self, $user, $project, $renamed_project) = @_;
929
  
cleanup
Yuki Kimoto authored on 2013-05-15
930
  # Check arguments
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
931
  croak "Invalid user name or project"
932
    unless defined $user && defined $project && defined $renamed_project;
cleanup
Yuki Kimoto authored on 2013-05-15
933

            
934
  # Rename repository
remove rep_path
Yuki Kimoto authored on 2016-04-16
935
  my $rep_info = $self->app->rep_info($user, $project);
936
  my $rep_git_dir = $rep_info->{git_dir};
937
  
938
  my $renamed_rep_info = $self->app->rep_info($user, $renamed_project);
939
  my $renamed_rep_git_dir = $renamed_rep_info->{git_dir};
940

            
941
  move($rep_git_dir, $renamed_rep_git_dir)
942
    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
943
}
944

            
945
1;