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') { |
change pull feature to impor...
|
25 |
|
26 |
# Validation |
|
27 |
my $api = gitprep_api; |
|
28 |
my $params = $api->params; |
|
29 |
my $rule = [ |
|
30 |
user => [ |
|
improve import-branch page d...
|
31 |
['user_name' => 'User name is invalid.'] |
change pull feature to impor...
|
32 |
], |
33 |
project => [ |
|
improve import-branch page d...
|
34 |
['project_name' => 'Repository name is invalid.'] |
change pull feature to impor...
|
35 |
], |
36 |
branch => [ |
|
improve import-branch page d...
|
37 |
['not_blank' => 'Branch name is empty.'] |
change pull feature to impor...
|
38 |
], |
39 |
remote_user => [ |
|
improve import-branch page d...
|
40 |
['user_name' => 'Remote User name is invalid.'] |
change pull feature to impor...
|
41 |
], |
42 |
remote_project => [ |
|
improve import-branch page d...
|
43 |
['project_name' => 'Remote repository is invalid.'] |
change pull feature to impor...
|
44 |
], |
add import branch tests
|
45 |
'remote-branch' => [ |
improve import-branch page d...
|
46 |
['not_blank' => 'Remote branch name is empty.'] |
complete branch import featu...
|
47 |
], |
48 |
force => {require => 0} => [ |
|
49 |
'any' |
|
change pull feature to impor...
|
50 |
] |
51 |
]; |
|
rename validator to vc to up...
|
52 |
my $vresult = app->vc->validate($params, $rule); |
change pull feature to impor...
|
53 |
|
54 |
if ($vresult->is_ok) { |
|
55 |
my $safe_params = $vresult->data; |
|
56 |
|
|
complete branch import featu...
|
57 |
# Valid paramters |
change pull feature to impor...
|
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}; |
|
add import branch tests
|
63 |
my $remote_branch = $safe_params->{'remote-branch'}; |
complete branch import featu...
|
64 |
my $force = $safe_params->{force}; |
change pull feature to impor...
|
65 |
|
complete branch import featu...
|
66 |
# Check branch name |
67 |
my $branches = $git->branches($user, $project); |
|
improve import-branch page d...
|
68 |
|
complete branch import featu...
|
69 |
if (!$force && grep { $branch eq $_->{name} } @$branches) { |
70 |
$errors = ["Branch \"$branch\" is already exists. If you want to import this branch, check force option."]; |
|
improve import-branch page d...
|
71 |
} |
72 |
else { |
|
complete branch import featu...
|
73 |
eval { |
74 |
$git->import_branch( |
|
75 |
$user, |
|
76 |
$project, |
|
77 |
$branch, |
|
78 |
$remote_user, |
|
79 |
$remote_project, |
|
80 |
$remote_branch, |
|
81 |
{force => $force} |
|
82 |
); |
|
83 |
}; |
|
84 |
|
|
85 |
if ($@) { |
|
86 |
$errors = ['Internal Error']; |
|
87 |
} |
|
88 |
else { |
|
89 |
flash(message => "Success: " . ($force ? 'force ' : '') . "import \"$remote_user / $remote_project / $remote_branch\" into \"$user / $project / $branch\""); |
|
90 |
$self->redirect_to('current'); |
|
91 |
return; |
|
92 |
} |
|
improve import-branch page d...
|
93 |
} |
change pull feature to impor...
|
94 |
} |
95 |
else { |
|
improve import-branch page d...
|
96 |
$errors = $vresult->messages; |
change pull feature to impor...
|
97 |
} |
98 |
} |
|
99 |
%> |
|
100 | ||
101 |
% layout 'common', title => "Import branch"; |
|
102 |
%= include 'include/header'; |
|
improve import-branch page d...
|
103 | |
change pull feature to impor...
|
104 |
%= javascript begin |
105 |
$('document').ready(function () { |
|
106 |
|
|
107 |
// Select remote branch |
|
108 |
$('[name=copy-branch-name]').on('click', function () { |
|
109 |
$('[name=branch]').val($('[name=remote_branch]').val()); |
|
110 |
return false; |
|
111 |
}); |
|
112 |
}); |
|
113 |
% end |
|
114 |
|
|
115 |
<div class="container"> |
|
improve import-branch page d...
|
116 |
%= include '/include/project_header'; |
117 |
% if (my $message = flash('message')) { |
|
118 |
<div class="alert alert-success"> |
|
119 |
<button type="button" class="close" data-dismiss="alert">×</button> |
|
120 |
<%= $message %> |
|
121 |
</div> |
|
122 |
% } |
|
change pull feature to impor...
|
123 |
% if ($errors) { |
124 |
<div class="alert alert-error"> |
|
125 |
<button type="button" class="close" data-dismiss="alert">×</button> |
|
126 |
% for my $error (@$errors) { |
|
127 |
<p><%= $error %></p> |
|
128 |
% } |
|
129 |
</div> |
|
130 |
% } |
|
131 |
<h3>Import branch</h3> |
|
add import branch tests
|
132 |
<form action="<%= url_for("/$user/$project/import-branch/$remote_user/$remote_project")->query(op => 'import') %>" method="post"> |
change pull feature to impor...
|
133 |
<div class="row" style="font-size:22px"> |
improve import-branch page d...
|
134 |
<div class="span6"> |
change pull feature to impor...
|
135 |
<div class="well" style="text-align:center"> |
136 |
<div style="color:blue;margin-bottom:15px"> |
|
137 |
%= "$user / $project"; |
|
138 |
</div> |
|
139 |
<div> |
|
improve import-branch page d...
|
140 |
%= text_field 'branch', placeholder => "Branch name", style => "margin-top:12px;width:250px"; |
141 |
<button name="copy-branch-name", class="btn" style="font-size:12px; padding-left:3px;padding-right:3px;color:#666">Copy Branch Name</button> |
|
142 |
</div> |
|
complete branch import featu...
|
143 |
<table style="width:100%"> |
144 |
<tr> |
|
145 |
<td style="width:80px;text-align:right"> |
|
146 |
%= submit_button 'Import', class => "btn"; |
|
147 |
</td> |
|
148 |
<td style="width:20px;"> |
|
149 |
<%= check_box force => 1 %> |
|
150 |
</td> |
|
151 |
<td style="font-size:13px;padding-top:7px;text-align:left"> |
|
152 |
Force |
|
153 |
</td> |
|
154 |
</tr> |
|
155 |
</table> |
|
change pull feature to impor...
|
156 |
</div> |
157 |
</div> |
|
improve import-branch page d...
|
158 |
<div class="span1"> |
change pull feature to impor...
|
159 |
<div style="padding: 19px;text-align:center;font-size:26px"> |
160 |
⇐ |
|
161 |
</div> |
|
162 |
</div> |
|
163 |
<div class="span5"> |
|
164 |
<div class="well" style="text-align:center"> |
|
165 |
<div style="color:green;margin-bottom:15px"> |
|
166 |
%= "$remote_user / $remote_project"; |
|
167 |
</div> |
|
168 |
% param(remote_branch => $remote_branch); |
|
add import branch tests
|
169 |
%= select_field 'remote-branch' => $remote_branch_names, style => "width:250px"; |
change pull feature to impor...
|
170 |
</div> |
171 |
</div> |
|
172 |
</div> |
|
173 |
</form> |
|
174 |
</div> |
|
175 |
|
|
176 |
%= include '/include/footer'; |