... | ... |
@@ -94,13 +94,5 @@ sub default_branch { |
94 | 94 |
return $config->{default_branch}; |
95 | 95 |
} |
96 | 96 |
|
97 |
-sub delete_project { |
|
98 |
- my ($self, $user, $project) = @_; |
|
99 |
- |
|
100 |
- my $c = $self->cntl; |
|
101 |
- my $dbi = $c->app->dbi; |
|
102 |
- $dbi->model('project')->delete(id => [$user, $project]); |
|
103 |
-} |
|
104 |
- |
|
105 | 97 |
1; |
106 | 98 |
|
... | ... |
@@ -262,56 +262,6 @@ sub check_head_link { |
262 | 262 |
(-l $head_file && readlink($head_file) =~ /^refs\/heads\//)); |
263 | 263 |
} |
264 | 264 |
|
265 |
-sub create_repository { |
|
266 |
- my ($self, $user, $project, $opts) = @_; |
|
267 |
- |
|
268 |
- my $rep_home = $self->rep_home; |
|
269 |
- my $rep = "$rep_home/$user/$project.git"; |
|
270 |
- eval { |
|
271 |
- # Repository |
|
272 |
- mkpath $rep; |
|
273 |
- |
|
274 |
- # Git init |
|
275 |
- my @git_init_cmd = $self->_cmd($user, $project, 'init', '--bare'); |
|
276 |
- system(@git_init_cmd) == 0 |
|
277 |
- or croak "Can't execute git init"; |
|
278 |
- |
|
279 |
- # Add git-daemon-export-ok |
|
280 |
- { |
|
281 |
- my $file = "$rep/git-daemon-export-ok"; |
|
282 |
- open my $fh, '>', $file |
|
283 |
- or croak "Can't create git-daemon-export-ok: $!" |
|
284 |
- } |
|
285 |
- |
|
286 |
- # HTTP support |
|
287 |
- my @git_update_server_info_cmd = $self->_cmd( |
|
288 |
- $user, |
|
289 |
- $project, |
|
290 |
- '--bare', |
|
291 |
- 'update-server-info' |
|
292 |
- ); |
|
293 |
- system(@git_update_server_info_cmd) == 0 |
|
294 |
- or croak "Can't execute git --bare update-server-info"; |
|
295 |
- move("$rep/hooks/post-update.sample", "$rep/hooks/post-update") |
|
296 |
- or croak "Can't move post-update"; |
|
297 |
- |
|
298 |
- # Description |
|
299 |
- if (my $description = $opts->{description}) { |
|
300 |
- my $file = "$rep/description"; |
|
301 |
- open my $fh, '>', $file |
|
302 |
- or croak "Can't open $file: $!"; |
|
303 |
- print $fh $description |
|
304 |
- or croak "Can't write $file: $!"; |
|
305 |
- close $fh; |
|
306 |
- } |
|
307 |
- }; |
|
308 |
- if ($@) { |
|
309 |
- my $error = $@; |
|
310 |
- $self->remove_repository($user, $project); |
|
311 |
- die "$error\n"; |
|
312 |
- } |
|
313 |
-} |
|
314 |
- |
|
315 | 265 |
sub commits_number { |
316 | 266 |
my ($self, $user, $project, $ref) = @_; |
317 | 267 |
|
... | ... |
@@ -1152,16 +1102,6 @@ sub parse_ls_tree_line { |
1152 | 1102 |
return \%res; |
1153 | 1103 |
} |
1154 | 1104 |
|
1155 |
-sub remove_repository { |
|
1156 |
- my ($self, $user, $project) = @_; |
|
1157 |
- |
|
1158 |
- my $rep_home = $self->rep_home; |
|
1159 |
- croak "Can't remove repository. repositry home is empty" |
|
1160 |
- if !defined $rep_home || $rep_home eq ''; |
|
1161 |
- my $rep = "$rep_home/$user/$project.git"; |
|
1162 |
- rmtree $rep; |
|
1163 |
-} |
|
1164 |
- |
|
1165 | 1105 |
sub search_bin { |
1166 | 1106 |
my $self = shift; |
1167 | 1107 |
|
... | ... |
@@ -3,9 +3,103 @@ use Mojo::Base -base; |
3 | 3 |
|
4 | 4 |
use Carp 'croak'; |
5 | 5 |
use File::Copy 'move'; |
6 |
+use File::Path qw/mkpath rmtree/; |
|
6 | 7 |
|
7 | 8 |
has 'app'; |
8 | 9 |
|
10 |
+sub create_repository { |
|
11 |
+ my ($self, $user, $project, $opts) = @_; |
|
12 |
+ |
|
13 |
+ my $git = $self->app->git; |
|
14 |
+ |
|
15 |
+ my $rep_home = $git->rep_home; |
|
16 |
+ my $rep = "$rep_home/$user/$project.git"; |
|
17 |
+ eval { |
|
18 |
+ # Repository |
|
19 |
+ mkpath $rep; |
|
20 |
+ |
|
21 |
+ # Git init |
|
22 |
+ my @git_init_cmd = $git->_cmd($user, $project, 'init', '--bare'); |
|
23 |
+ system(@git_init_cmd) == 0 |
|
24 |
+ or croak "Can't execute git init"; |
|
25 |
+ |
|
26 |
+ # Add git-daemon-export-ok |
|
27 |
+ { |
|
28 |
+ my $file = "$rep/git-daemon-export-ok"; |
|
29 |
+ open my $fh, '>', $file |
|
30 |
+ or croak "Can't create git-daemon-export-ok: $!" |
|
31 |
+ } |
|
32 |
+ |
|
33 |
+ # HTTP support |
|
34 |
+ my @git_update_server_info_cmd = $git->_cmd( |
|
35 |
+ $user, |
|
36 |
+ $project, |
|
37 |
+ '--bare', |
|
38 |
+ 'update-server-info' |
|
39 |
+ ); |
|
40 |
+ system(@git_update_server_info_cmd) == 0 |
|
41 |
+ or croak "Can't execute git --bare update-server-info"; |
|
42 |
+ move("$rep/hooks/post-update.sample", "$rep/hooks/post-update") |
|
43 |
+ or croak "Can't move post-update"; |
|
44 |
+ |
|
45 |
+ # Description |
|
46 |
+ if (my $description = $opts->{description}) { |
|
47 |
+ my $file = "$rep/description"; |
|
48 |
+ open my $fh, '>', $file |
|
49 |
+ or croak "Can't open $file: $!"; |
|
50 |
+ print $fh $description |
|
51 |
+ or croak "Can't write $file: $!"; |
|
52 |
+ close $fh; |
|
53 |
+ } |
|
54 |
+ }; |
|
55 |
+ if ($@) { |
|
56 |
+ my $error = $@; |
|
57 |
+ $self->remove_repository($user, $project); |
|
58 |
+ die "$error\n"; |
|
59 |
+ } |
|
60 |
+} |
|
61 |
+ |
|
62 |
+sub delete_project { |
|
63 |
+ my ($self, $user, $project) = @_; |
|
64 |
+ |
|
65 |
+ my $dbi = $self->app->dbi; |
|
66 |
+ |
|
67 |
+ # Delete project |
|
68 |
+ my $error; |
|
69 |
+ eval { |
|
70 |
+ $dbi->connector->txn(sub { |
|
71 |
+ eval { $self->_delete_project($user, $project) }; |
|
72 |
+ croak $error = $@ if $@; |
|
73 |
+ eval {$self->_delete_rep($user, $project) }; |
|
74 |
+ $error->{message} = $@; |
|
75 |
+ croak $error = $@ if $@; |
|
76 |
+ }); |
|
77 |
+ }; |
|
78 |
+ croak $error if $@; |
|
79 |
+ |
|
80 |
+ return 1; |
|
81 |
+} |
|
82 |
+ |
|
83 |
+ |
|
84 |
+sub _delete_project { |
|
85 |
+ my ($self, $user, $project) = @_; |
|
86 |
+ |
|
87 |
+ my $dbi = $self->app->dbi; |
|
88 |
+ $dbi->model('project')->delete(id => [$user, $project]); |
|
89 |
+} |
|
90 |
+ |
|
91 |
+sub _delete_rep { |
|
92 |
+ my ($self, $user, $project) = @_; |
|
93 |
+ |
|
94 |
+ my $rep_home = $self->app->git->rep_home; |
|
95 |
+ croak "Can't remove repository. repositry home is empty" |
|
96 |
+ if !defined $rep_home || $rep_home eq ''; |
|
97 |
+ my $rep = "$rep_home/$user/$project.git"; |
|
98 |
+ rmtree $rep; |
|
99 |
+ croak "Can't remove repository. repository is rest" |
|
100 |
+ if -e $rep; |
|
101 |
+} |
|
102 |
+ |
|
9 | 103 |
sub rename_project { |
10 | 104 |
my ($self, $user, $project, $renamed_project) = @_; |
11 | 105 |
|
... | ... |
@@ -44,7 +44,7 @@ |
44 | 44 |
else { |
45 | 45 |
# Create repository |
46 | 46 |
eval { |
47 |
- $git->create_repository( |
|
47 |
+ app->manager->create_project( |
|
48 | 48 |
$user, |
49 | 49 |
$project, |
50 | 50 |
{description => $description} |
... | ... |
@@ -57,8 +57,9 @@ |
57 | 57 |
return $self->res->body; |
58 | 58 |
} |
59 | 59 |
elsif ($op eq 'delete-project') { |
60 |
+ |
|
61 |
+ # Validation |
|
60 | 62 |
my $params = $api->params; |
61 |
- |
|
62 | 63 |
my $rule = [ |
63 | 64 |
user => [ |
64 | 65 |
'user_name' |
... | ... |
@@ -69,27 +70,26 @@ |
69 | 70 |
]; |
70 | 71 |
my $vresult = app->validator->validate($params, $rule); |
71 | 72 |
|
73 |
+ # Delete project |
|
72 | 74 |
if ($vresult->is_ok) { |
73 | 75 |
my $data = $vresult->data; |
74 | 76 |
my $user = $data->{user}; |
75 | 77 |
my $project = $data->{project}; |
76 | 78 |
|
77 |
- eval { $git->delete_project($user, $project) }; |
|
78 |
- my $error1 = $@; |
|
79 |
- eval { $api->delete_project($user, $project) }; |
|
80 |
- my $error2 = $@; |
|
81 |
- |
|
82 |
- if (!$error1 && !$error2) { |
|
83 |
- $self->render(json => {ok => 1}); |
|
79 |
+ eval { app->manager->delete_project($user, $project) }; |
|
80 |
+ if ($@) { |
|
81 |
+ app->log->fatal($@); |
|
82 |
+ $self->render(json => {ok => 0, message => 'Internal error'}); |
|
84 | 83 |
} |
85 | 84 |
else { |
86 |
- app->log->fatal($error1) if $error1; |
|
87 |
- app->log->fatal($error2) if $error2; |
|
88 |
- $self->render(json => {ok => 0}); |
|
85 |
+ $self->render(json => {ok => 1}); |
|
89 | 86 |
} |
90 |
- return $self->res->body; |
|
91 | 87 |
} |
92 |
- else { $api->croak('Invalid') } |
|
88 |
+ else { |
|
89 |
+ $self->render(json => {ok => 0, message => 'Invalid paramter'}); |
|
90 |
+ } |
|
91 |
+ |
|
92 |
+ return $self->res->body; |
|
93 | 93 |
} |
94 | 94 |
%> |
95 | 95 |
|
... | ... |
@@ -115,8 +115,8 @@ |
115 | 115 |
location.href = "<%= url_for("/$user") %>" + '/' + renamed_project; |
116 | 116 |
} |
117 | 117 |
else { |
118 |
- $('#modal-message').text('Rename failed:' + result.message); |
|
119 |
- $('#success').modal('show'); |
|
118 |
+ $('#modal-message-text').text('Rename failed:' + result.message); |
|
119 |
+ $('#modal-message').modal('show'); |
|
120 | 120 |
} |
121 | 121 |
}); |
122 | 122 |
}); |
... | ... |
@@ -127,8 +127,8 @@ |
127 | 127 |
var url = "<%= url_for %>?op=change_description&description=" + description; |
128 | 128 |
$.post(url, function (result) { |
129 | 129 |
if (result.ok) { |
130 |
- $('#modal-message').text('Description is changed'); |
|
131 |
- $('#success').modal('show'); |
|
130 |
+ $('#modal-message-text').text('Description is changed'); |
|
131 |
+ $('#modal-message').modal('show'); |
|
132 | 132 |
} |
133 | 133 |
}); |
134 | 134 |
}); |
... | ... |
@@ -162,6 +162,10 @@ |
162 | 162 |
if (result.ok) { |
163 | 163 |
location.href = "<%= url_for("/$user") %>"; |
164 | 164 |
} |
165 |
+ else { |
|
166 |
+ $('#modal-message-text').text('Error:' + result.message); |
|
167 |
+ $('#modal-message').modal('show'); |
|
168 |
+ } |
|
165 | 169 |
}); |
166 | 170 |
}); |
167 | 171 |
|
... | ... |
@@ -227,9 +231,9 @@ |
227 | 231 |
</div> |
228 | 232 |
</div> |
229 | 233 |
|
230 |
- <div id="success" class="modal hide"> |
|
234 |
+ <div id="modal-message" class="modal hide"> |
|
231 | 235 |
<div class="modal-header"> |
232 |
- <div id="modal-message" style="font-weight:bold"></div> |
|
236 |
+ <div id="modal-message-text" style="font-weight:bold"></div> |
|
233 | 237 |
</div> |
234 | 238 |
<div class="modal-body"> |
235 | 239 |
<button class="btn" data-dismiss="modal" aria-hidden="true">OK</button> |
... | ... |
@@ -239,7 +243,7 @@ |
239 | 243 |
<div id="rename-confirm" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="rename-confirm-label" aria-hidden="true"> |
240 | 244 |
<div class="modal-header"> |
241 | 245 |
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> |
242 |
- <div id="modal-message" style="font-weight:bold">Are you sure you want to rename?</div> |
|
246 |
+ <div style="font-weight:bold">Are you sure you want to rename?</div> |
|
243 | 247 |
</div> |
244 | 248 |
<div class="modal-body"> |
245 | 249 |
<p> |
... | ... |
@@ -264,7 +268,7 @@ |
264 | 268 |
<div id="delete-confirm" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="delete-confirm-label" aria-hidden="true"> |
265 | 269 |
<div class="modal-header"> |
266 | 270 |
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> |
267 |
- <div id="modal-message" style="font-weight:bold">Are you ABSOLUTELY sure?</div> |
|
271 |
+ <div style="font-weight:bold">Are you ABSOLUTELY sure?</div> |
|
268 | 272 |
</div> |
269 | 273 |
<div class="modal-body"> |
270 | 274 |
<p> |