| ... | ... |
@@ -22,46 +22,55 @@ |
| 22 | 22 |
my $op = param('op') || '';
|
| 23 | 23 |
my $errors; |
| 24 | 24 |
if ($op eq 'import' && lc $self->req->method eq 'post') {
|
| 25 |
- |
|
| 26 |
- # Validation |
|
| 27 |
- my $api = gitprep_api; |
|
| 28 |
- my $params = $api->params; |
|
| 29 |
- my $rule = [ |
|
| 30 |
- user => [ |
|
| 31 |
- ['user_name' => 'User name is invalid.'] |
|
| 32 |
- ], |
|
| 33 |
- project => [ |
|
| 34 |
- ['project_name' => 'Repository name is invalid.'] |
|
| 35 |
- ], |
|
| 36 |
- branch => [ |
|
| 37 |
- ['not_blank' => 'Branch name is empty.'] |
|
| 38 |
- ], |
|
| 39 |
- remote_user => [ |
|
| 40 |
- ['user_name' => 'Remote User name is invalid.'] |
|
| 41 |
- ], |
|
| 42 |
- remote_project => [ |
|
| 43 |
- ['project_name' => 'Remote repository is invalid.'] |
|
| 44 |
- ], |
|
| 45 |
- 'remote-branch' => [ |
|
| 46 |
- ['not_blank' => 'Remote branch name is empty.'] |
|
| 47 |
- ], |
|
| 48 |
- force => {require => 0} => [
|
|
| 49 |
- 'any' |
|
| 50 |
- ] |
|
| 51 |
- ]; |
|
| 52 |
- my $vresult = app->vc->validate($params, $rule); |
|
| 25 |
+ # Parameters |
|
| 26 |
+ my $user = param('user');
|
|
| 27 |
+ my $project = param('project');
|
|
| 28 |
+ my $branch = param('branch');
|
|
| 29 |
+ my $remote_user = param('remote_user');
|
|
| 30 |
+ my $remote_project = param('remote_project');
|
|
| 31 |
+ my $remote_branch = param('remote-branch');
|
|
| 32 |
+ my $force = param('force');
|
|
| 53 | 33 |
|
| 54 |
- if ($vresult->is_ok) {
|
|
| 55 |
- my $safe_params = $vresult->data; |
|
| 56 |
- |
|
| 57 |
- # Valid paramters |
|
| 58 |
- my $user = $safe_params->{user};
|
|
| 59 |
- my $project = $safe_params->{project};
|
|
| 60 |
- my $branch = $safe_params->{branch};
|
|
| 61 |
- my $remote_user = $safe_params->{remote_user};
|
|
| 62 |
- my $remote_project = $safe_params->{remote_project};
|
|
| 63 |
- my $remote_branch = $safe_params->{'remote-branch'};
|
|
| 64 |
- my $force = $safe_params->{force};
|
|
| 34 |
+ # Validator |
|
| 35 |
+ my $vc = app->vc; |
|
| 36 |
+ |
|
| 37 |
+ # Validation result |
|
| 38 |
+ my $validation = $vc->validation; |
|
| 39 |
+ |
|
| 40 |
+ # "user" |
|
| 41 |
+ if (!$vc->check($user, 'user_name')) {
|
|
| 42 |
+ $validation->add_failed('User name is invalid.');
|
|
| 43 |
+ } |
|
| 44 |
+ |
|
| 45 |
+ # "project" |
|
| 46 |
+ if (!$vc->check($project, 'project_name')) {
|
|
| 47 |
+ $validation->add_failed('Repository name is invalid.');
|
|
| 48 |
+ } |
|
| 49 |
+ |
|
| 50 |
+ # "branch" |
|
| 51 |
+ if (!(defined $branch && length $branch)) {
|
|
| 52 |
+ $validation->add_failed('Branch name is empty.');
|
|
| 53 |
+ } |
|
| 54 |
+ |
|
| 55 |
+ # "remote_user" |
|
| 56 |
+ if (!$vc->check($remote_user, 'user_name')) {
|
|
| 57 |
+ $validation->add_failed('Remote User name is invalid.');
|
|
| 58 |
+ } |
|
| 59 |
+ |
|
| 60 |
+ # "remote_project" |
|
| 61 |
+ if (!$vc->check($remote_project, 'project_name')) {
|
|
| 62 |
+ $validation->add_failed('Remote repository is invalid.');
|
|
| 63 |
+ } |
|
| 64 |
+ |
|
| 65 |
+ # "remote-branch" |
|
| 66 |
+ if (!(defined $remote_branch && length $remote_branch)) {
|
|
| 67 |
+ $validation->add_failed('Remote branch name is empty.');
|
|
| 68 |
+ } |
|
| 69 |
+ |
|
| 70 |
+ # "force" |
|
| 71 |
+ $force = $force ? 1 : 0; |
|
| 72 |
+ |
|
| 73 |
+ if ($validation->is_valid) {
|
|
| 65 | 74 |
|
| 66 | 75 |
# Check branch name |
| 67 | 76 |
my $branches = $git->branches($user, $project); |
| ... | ... |
@@ -82,8 +91,9 @@ |
| 82 | 91 |
); |
| 83 | 92 |
}; |
| 84 | 93 |
|
| 85 |
- if ($@) {
|
|
| 94 |
+ if (my $e = $@) {
|
|
| 86 | 95 |
$errors = ['Internal Error']; |
| 96 |
+ app->log->error(url_for . ": $e"); |
|
| 87 | 97 |
} |
| 88 | 98 |
else {
|
| 89 | 99 |
flash(message => "Success: " . ($force ? 'force ' : '') . "import \"$remote_user / $remote_project / $remote_branch\" into \"$user / $project / $branch\""); |
| ... | ... |
@@ -93,7 +103,7 @@ |
| 93 | 103 |
} |
| 94 | 104 |
} |
| 95 | 105 |
else {
|
| 96 |
- $errors = $vresult->messages; |
|
| 106 |
+ $errors = $validation->messages; |
|
| 97 | 107 |
} |
| 98 | 108 |
} |
| 99 | 109 |
|