change pull feature to impor...
|
1 |
<% |
add import-branch authentica...
|
2 |
|
3 |
my $api = gitprep_api; |
|
4 |
|
|
change pull feature to impor...
|
5 |
my $user = param('user'); |
6 |
my $project = param('project'); |
|
add import branch tests
|
7 |
my $remote_user = param('remote_user'); |
8 |
my $remote_project = param('remote_project'); |
|
9 |
my $remote_branch = param('remote-branch'); |
|
add import-branch authentica...
|
10 |
|
11 |
# Authentication |
|
12 |
unless ($api->logined($user)) { |
|
13 |
$self->redirect_to('/'); |
|
14 |
return; |
|
15 |
} |
|
change pull feature to impor...
|
16 |
|
17 |
# Branches |
|
revert encoding support
|
18 |
my $git = app->git; |
change pull feature to impor...
|
19 |
my $remote_branches = $git->branches($remote_user, $remote_project); |
20 |
my $remote_branch_names = [map { $_->{name} } @$remote_branches]; |
|
21 |
|
|
22 |
my $op = param('op') || ''; |
|
23 |
my $errors; |
|
improve import-branch page d...
|
24 |
if ($op eq 'import' && lc $self->req->method eq 'post') { |
cleanup import-branch valida...
|
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'); |
|
change pull feature to impor...
|
33 |
|
cleanup import-branch valida...
|
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) { |
|
change pull feature to impor...
|
74 |
|
complete branch import featu...
|
75 |
# Check branch name |
76 |
my $branches = $git->branches($user, $project); |
|
improve import-branch page d...
|
77 |
|
complete branch import featu...
|
78 |
if (!$force && grep { $branch eq $_->{name} } @$branches) { |
79 |
$errors = ["Branch \"$branch\" is already exists. If you want to import this branch, check force option."]; |
|
improve import-branch page d...
|
80 |
} |
81 |
else { |
|
complete branch import featu...
|
82 |
eval { |
83 |
$git->import_branch( |
|
84 |
$user, |
|
85 |
$project, |
|
86 |
$branch, |
|
87 |
$remote_user, |
|
88 |
$remote_project, |
|
89 |
$remote_branch, |
|
90 |
{force => $force} |
|
91 |
); |
|
92 |
}; |
|
93 |
|
|
cleanup import-branch valida...
|
94 |
if (my $e = $@) { |
complete branch import featu...
|
95 |
$errors = ['Internal Error']; |
cleanup import-branch valida...
|
96 |
app->log->error(url_for . ": $e"); |
complete branch import featu...
|
97 |
} |
98 |
else { |
|
99 |
flash(message => "Success: " . ($force ? 'force ' : '') . "import \"$remote_user / $remote_project / $remote_branch\" into \"$user / $project / $branch\""); |
|
100 |
$self->redirect_to('current'); |
|
101 |
return; |
|
102 |
} |
|
improve import-branch page d...
|
103 |
} |
change pull feature to impor...
|
104 |
} |
105 |
else { |
|
cleanup import-branch valida...
|
106 |
$errors = $validation->messages; |
change pull feature to impor...
|
107 |
} |
108 |
} |
|
improve import-branch page d...
|
109 | |
110 |
layout 'common', title => "Import branch"; |
|
change pull feature to impor...
|
111 |
%> |
112 | ||
113 |
%= include 'include/header'; |
|
improve import-branch page d...
|
114 | |
change pull feature to impor...
|
115 |
%= javascript begin |
116 |
$('document').ready(function () { |
|
117 |
|
|
118 |
// Select remote branch |
|
119 |
$('[name=copy-branch-name]').on('click', function () { |
|
improve import-branch page d...
|
120 |
$('[name=branch]').val($('[name=remote-branch]').val()); |
change pull feature to impor...
|
121 |
return false; |
122 |
}); |
|
123 |
}); |
|
124 |
% end |
|
125 |
|
|
126 |
<div class="container"> |
|
improve import-branch page d...
|
127 |
% if (my $message = flash('message')) { |
128 |
<div class="alert alert-success"> |
|
129 |
<button type="button" class="close" data-dismiss="alert">×</button> |
|
130 |
<%= $message %> |
|
131 |
</div> |
|
132 |
% } |
|
change pull feature to impor...
|
133 |
% if ($errors) { |
134 |
<div class="alert alert-error"> |
|
135 |
<button type="button" class="close" data-dismiss="alert">×</button> |
|
136 |
% for my $error (@$errors) { |
|
137 |
<p><%= $error %></p> |
|
138 |
% } |
|
139 |
</div> |
|
140 |
% } |
|
improve import-branch page d...
|
141 |
<h3 class="topic1">Import branch</h3> |
add import branch tests
|
142 |
<form action="<%= url_for("/$user/$project/import-branch/$remote_user/$remote_project")->query(op => 'import') %>" method="post"> |
improve import-branch page d...
|
143 |
<div class="import-branch"> |
144 |
<div class="left"> |
|
145 |
<div class="import-branch-to"> |
|
146 |
<div> |
|
change pull feature to impor...
|
147 |
%= "$user / $project"; |
148 |
</div> |
|
149 |
<div> |
|
improve import-branch page d...
|
150 |
%= text_field 'branch', placeholder => "Branch name", style => "width:250px"; |
improve import-branch page d...
|
151 |
<button name="copy-branch-name", class="btn" style="font-size:12px; padding-left:3px;padding-right:3px;color:#666">Copy Branch Name</button> |
152 |
</div> |
|
improve import-branch page d...
|
153 |
<div class="import-branch-button-panel"> |
154 |
<div> |
|
155 |
%= submit_button 'Import', class => "btn btn-info"; |
|
156 |
</div> |
|
157 |
<div> |
|
158 |
<%= check_box force => 1 %> |
|
159 |
</div> |
|
160 |
<div> |
|
161 |
Force |
|
162 |
</div> |
|
163 |
</div> |
|
change pull feature to impor...
|
164 |
</div> |
165 |
</div> |
|
improve import-branch page d...
|
166 |
<div class="center"> |
167 |
⇐ |
|
change pull feature to impor...
|
168 |
</div> |
improve import-branch page d...
|
169 |
<div class="right"> |
170 |
<div class="import-branch-from"> |
|
171 |
<div> |
|
change pull feature to impor...
|
172 |
%= "$remote_user / $remote_project"; |
173 |
</div> |
|
improve import-branch page d...
|
174 |
<div> |
175 |
% param('remote-branch' => $remote_branch); |
|
176 |
%= select_field 'remote-branch' => $remote_branch_names, style => "width:250px"; |
|
177 |
</div> |
|
change pull feature to impor...
|
178 |
</div> |
179 |
</div> |
|
180 |
</div> |
|
181 |
</form> |
|
182 |
</div> |
|
183 |
|
|
184 |
%= include '/include/footer'; |