added feature that get branc...
|
1 |
<% |
2 |
# API |
|
added compare branch popup t...
|
3 |
my $api = gitprep_api; |
added feature that get branc...
|
4 | |
5 |
# Parameters |
|
6 |
my $user = param('user'); |
|
7 |
my $project = param('project'); |
|
cleanup
|
8 |
my $from_rev = param('rev1'); |
9 |
my $rev = param('rev2'); |
|
added feature that get branc...
|
10 |
my $page = param('page') || 0; |
add pull request form
|
11 |
my $expand = param('expand'); |
added feature that get branc...
|
12 |
|
cleanup branch
|
13 |
unless ($from_rev) { |
14 |
$from_rev = app->manager->default_branch($user, $project); |
|
15 |
} |
|
16 |
|
|
added feature that get branc...
|
17 |
# Git |
revert encoding support
|
18 |
my $git = $self->app->git; |
added feature that get branc...
|
19 |
|
add create pull request logi...
|
20 |
if (lc $self->req->method eq 'post') { |
21 |
my $op = param('op'); |
|
22 |
|
|
23 |
if ($op eq 'create-pull-request') { |
|
24 |
my $title = param('title'); |
|
25 |
my $message = param('message'); |
|
26 |
|
|
27 |
my $project_row_id = app->dbi->model('project')->select( |
|
28 |
'row_id', |
|
29 |
where => {user_id => $user, name => $project} |
|
30 |
)->value; |
|
31 |
|
|
32 |
my $pull_request = app->dbi->model('pull_request')->select( |
|
33 |
where => {project => $project_row_id, branch1 => $from_rev, branch2 => $rev} |
|
34 |
)->one; |
|
35 |
|
|
36 |
if ($pull_request) { |
|
37 |
$self->redirect_to("/$user/$project/pulls/$pull_request->{row_id}"); |
|
38 |
return; |
|
39 |
} |
|
40 |
else { |
|
add pulls description
|
41 |
my $now_tm = Time::Moment->now_utc; |
42 |
my $now_epoch = $now_tm->epoch; |
|
43 |
my $user_row_id = app->dbi->model('user')->select( |
|
44 |
'row_id', |
|
45 |
where => {id => $user} |
|
46 |
)->value; |
|
47 |
|
|
add create pull request logi...
|
48 |
my $new_pull_request_params = { |
49 |
project => $project_row_id, |
|
50 |
branch1 => $from_rev, |
|
51 |
branch2 => $rev, |
|
52 |
title => $title, |
|
create pull request list
|
53 |
message => $message, |
add pulls description
|
54 |
open => 1, |
55 |
open_time => $now_epoch, |
|
56 |
open_user => $user_row_id |
|
add create pull request logi...
|
57 |
}; |
58 |
|
|
59 |
app->dbi->model('pull_request')->insert($new_pull_request_params); |
|
60 |
|
|
61 |
my $new_pull_request_row_id = app->dbi->model('pull_request')->select( |
|
62 |
'row_id', |
|
63 |
where => { |
|
64 |
project => $project_row_id, |
|
65 |
branch1 => $from_rev, |
|
66 |
branch2 => $rev |
|
67 |
} |
|
68 |
)->value; |
|
69 |
|
|
70 |
$self->redirect_to("/$user/$project/pulls/$new_pull_request_row_id"); |
|
71 |
return; |
|
72 |
} |
|
73 |
|
|
74 |
} |
|
75 |
} |
|
76 |
|
|
added feature that get branc...
|
77 |
# Commits |
cleanup method
|
78 |
my $commits = $git->forward_commits(app->rep_info($user, $project), $from_rev, $rev); |
added feature that get branc...
|
79 |
my $commits_count = @$commits; |
80 |
my $commits_date = {}; |
|
improved compare page commit...
|
81 |
my $authors = {}; |
added feature that get branc...
|
82 |
for my $commit (@$commits) { |
support time zone
|
83 |
my $date = $commit->{age_string_date_local}; |
added feature that get branc...
|
84 |
$commits_date->{$date} ||= []; |
improved compare page commit...
|
85 |
$authors->{$commit->{author}} = 1; |
added feature that get branc...
|
86 |
push @{$commits_date->{$date}}, $commit; |
87 |
} |
|
improved compare page commit...
|
88 |
my $authors_count = keys %$authors; |
added compare page file chan...
|
89 | |
90 |
# Start commit |
|
cleanup methods
|
91 |
my $start_commit = $git->separated_commit(app->rep_info($user, $project), $from_rev, $rev); |
added compare page file chan...
|
92 | |
93 |
# End commit |
|
cleanup methods
|
94 |
my $end_commit = $git->get_commit(app->rep_info($user, $project), $rev); |
cleanup
|
95 |
|
96 |
if (!$start_commit || !$end_commit) { |
|
do success xt tests
|
97 |
$self->reply->not_found; |
cleanup
|
98 |
return; |
99 |
} |
|
added compare page file chan...
|
100 |
|
added base branch selection ...
|
101 |
# Branches |
cleanup rep_info
|
102 |
my $branches = $git->branches(app->rep_info($user, $project)); |
added base branch selection ...
|
103 |
@$branches = sort { $a->{commit}{age} <=> $b->{commit}{age} } @$branches; |
104 |
|
|
improve compare page design
|
105 |
# Variables |
106 |
stash id => $end_commit->{id}; |
|
107 |
stash from_id => $start_commit->{id}; |
|
108 |
stash rev => $end_commit->{id}; |
|
109 |
stash from_rev => $start_commit->{id}; |
|
add pull request form
|
110 |
|
111 |
# Can open pull request |
|
112 |
my $can_open_pull_request; |
|
113 |
if (keys %$commits_date && $expand) { |
|
114 |
$can_open_pull_request = 1; |
|
115 |
} |
|
116 |
|
|
cleanup methods
|
117 |
# Can merge |
add automatical merge checki...
|
118 |
my $merge_automatical; |
cleanup methods
|
119 |
if ($can_open_pull_request) { |
120 |
|
|
improve create working repos...
|
121 |
# Create working repository if it don't exist |
cleanup
|
122 |
$self->app->manager->create_work_rep($user, $project); |
add fetch logic
|
123 |
|
124 |
# Fetch repository |
|
cleanup compare logic
|
125 |
my $work_rep_info = app->work_rep_info($user, $project); |
126 |
my @git_fetch_cmd = $self->app->git->cmd($work_rep_info, 'fetch'); |
|
add fetch logic
|
127 |
Gitprep::Util::run_command(@git_fetch_cmd) |
128 |
or Carp::croak "Can't execute git fetch: @git_fetch_cmd"; |
|
cleanup branch
|
129 |
|
add lock system
|
130 |
# Lock repository |
131 |
my $lock = $self->app->manager->lock_rep($work_rep_info); |
|
cleanup compare logic
|
132 |
|
133 |
# Checkout tmp branch and git reset --hard from my remote branch |
|
add lock system
|
134 |
my $gitprep_tmp_branch_name = '__gitprep_tmp_branch__'; |
cleanup compare logic
|
135 |
my @git_checkout_tmp_branch = $self->app->git->cmd( |
136 |
$work_rep_info, |
|
137 |
'checkout', |
|
138 |
$gitprep_tmp_branch_name, |
|
139 |
); |
|
140 |
Gitprep::Util::run_command(@git_checkout_tmp_branch) |
|
141 |
or Carp::croak "Can't execute git checkout: @git_checkout_tmp_branch"; |
|
142 |
|
|
143 |
# git reset --hard |
|
144 |
my @git_reset_hard_cmd = $self->app->git->cmd( |
|
145 |
$work_rep_info, |
|
146 |
'reset', |
|
147 |
'--hard', |
|
148 |
"origin/$from_rev" |
|
149 |
); |
|
150 |
Gitprep::Util::run_command(@git_reset_hard_cmd) |
|
151 |
or Carp::croak "Can't execute git reset --hard: @git_reset_hard_cmd"; |
|
152 |
|
|
add automatical merge checki...
|
153 |
# Check merge automatically |
154 |
$merge_automatical = $self->app->manager->check_merge_automatical( |
|
155 |
app->work_rep_info($user, $project), |
|
156 |
$gitprep_tmp_branch_name, |
|
157 |
"origin/$rev" |
|
158 |
); |
|
cleanup methods
|
159 |
} |
160 |
|
|
add pulls page
|
161 |
layout 'common', title => "Comparing $from_rev...$rev \x{30fb} $user/$project"; |
added feature that get branc...
|
162 |
%> |
163 | ||
cleanup compare page
|
164 | |
improve compare page design
|
165 |
%= javascript begin |
166 |
$(document).ready(function () { |
|
167 |
|
|
168 |
// Change base branch |
|
169 |
$('#base-branch-btn').on('click', function () { |
|
170 |
$('#base-branch-popup') |
|
171 |
.css('display', 'block') |
|
172 |
.css('top', '40px') |
|
173 |
.css('left', '10px') |
|
174 |
; |
|
175 |
}); |
|
176 |
$('#base-branch-close').on('click', function () { |
|
177 |
$('#base-branch-popup').css('display', 'none'); |
|
178 |
}); |
|
179 |
$('[name=base-branch]').on('keypress', function (e) { |
|
180 |
// Enter |
|
181 |
if (e.which == 13) { |
|
show not able to merge
|
182 |
var href = '<%= url_for("/$user/$project/compare/") %>' + $(this).val() + '...<%= $rev %>'; |
183 |
if (<%= $expand ? 1 : 0 %>) { |
|
184 |
href = href + '?expand=1'; |
|
185 |
} |
|
186 |
location.href = href; |
|
improve compare page design
|
187 |
} |
188 |
}); |
|
show not able to merge
|
189 |
|
improve compare page design
|
190 |
// Change compare branch |
191 |
$('#compare-branch-btn').on('click', function () { |
|
192 |
$('#compare-branch-popup') |
|
193 |
.css('display', 'block') |
|
194 |
.css('top', '40px') |
|
195 |
.css('left', '96px') |
|
196 |
; |
|
197 |
}); |
|
198 |
$('#compare-branch-close').on('click', function () { |
|
199 |
$('#compare-branch-popup').css('display', 'none'); |
|
200 |
}); |
|
201 |
$('[name=compare-branch]').on('keypress', function (e) { |
|
202 |
// Enter |
|
203 |
if (e.which == 13) { |
|
show not able to merge
|
204 |
var href = '<%= url_for("/$user/$project/compare/") %>' + '<%= $from_rev %>...' + $(this).val(); |
205 |
if (<%= $expand ? 1 : 0 %>) { |
|
206 |
href = href + '?expand=1'; |
|
207 |
} |
|
208 |
location.href = href; |
|
improve compare page design
|
209 |
} |
improved compare page design
|
210 |
}); |
improve compare page design
|
211 |
}); |
212 |
% end |
|
cleanup
|
213 | |
improve compare page design
|
214 |
%= include '/include/header'; |
cleanup
|
215 | |
improve compare page design
|
216 |
<div class="container"> |
add pull request form
|
217 |
<div class="topic1"> |
218 |
% if ($can_open_pull_request) { |
|
219 |
Open a pull request |
|
220 |
% } else { |
|
221 |
Comparing changes |
|
222 |
% } |
|
223 |
</div> |
|
improve compare page design
|
224 |
<div class="compare-select"> |
225 |
<div> |
|
226 |
<div> |
|
227 |
<button id="base-branch-btn" class="btn btn-small"> |
|
228 |
<span>base:</span><b> <%= $from_rev %></b><i class="icon-arrow-down"></i> |
|
229 |
</button> |
|
230 |
... |
|
231 |
<button id="compare-branch-btn" class="btn btn-small"> |
|
232 |
<span>compare:</span> <b><%= $rev %></b><i class="icon-arrow-down"></i> |
|
233 |
</button> |
|
add automatical merge checki...
|
234 |
|
show not able to merge
|
235 |
% if ($can_open_pull_request) { |
236 |
% if ($merge_automatical) { |
|
237 |
<span style="margin-left:10px"> |
|
238 |
<span style="color:green;font-weight:bold"><%= "\x{2714}" %>Able to merge.</span> These branches can be automatically merged. |
|
239 |
</span> |
|
240 |
% } else { |
|
241 |
<span style="margin-left:10px"> |
|
242 |
<span style="color:red;font-weight:bold"><%= "×" %>Not able to merge.</span> These branches can't be automatically merged. |
|
243 |
</span> |
|
244 |
% } |
|
add automatical merge checki...
|
245 |
% } |
cleanup
|
246 |
</div> |
improve compare page design
|
247 |
</div> |
show not able to merge
|
248 | |
249 |
<div id="base-branch-popup" style="display:none;width:330px;position:absolute"> |
|
250 |
<div class="radius-top border-gray" style="background:#E6E6FA;padding:10px"> |
|
251 |
<div style="overflow:hidden"> |
|
252 |
<div style="float:left;width:90%;"> |
|
253 |
<b>Choose a base branch</b> |
|
254 |
</div> |
|
255 |
<div style="float:left:width:10%;text-align:right;"> |
|
256 |
<i id="base-branch-close" class="icon-remove-circle"></i> |
|
added base branch selection ...
|
257 |
</div> |
show pull request only when ...
|
258 |
</div> |
improve compare page design
|
259 |
</div> |
show not able to merge
|
260 |
<div class="border-gray" style="background:#F5F5F5;border-top:none;border-bottom:none;text-align:center;padding:10px 0"> |
261 |
%= text_field 'base-branch', style => 'margin-bottom:0;width:270px', placeholder => 'Branch, tag, commit, or history marker'; |
|
262 |
</div> |
|
263 |
<div style="background:white;max-height:500px;overflow:auto;"> |
|
264 |
<ul class="nav nav-tabs nav-stacked"> |
|
265 |
% for (my $i = 0; $i < @$branches; $i++) { |
|
266 |
% my $branch = $branches->[$i]; |
|
267 |
<li> |
|
268 |
<a style="border-top-left-radius:0px;border-top-right-radius:0px;" |
|
269 |
href="<%= url_with("/$user/$project/compare/$branch->{name}...$rev") %>"> |
|
270 |
<%= $branch->{name} %> |
|
271 |
</a> |
|
272 |
</li> |
|
273 |
% } |
|
274 |
</ul> |
|
275 |
</div> |
|
276 |
</div> |
|
277 | ||
improve compare page design
|
278 |
<div id="compare-branch-popup" style="display:none;width:330px;position:absolute"> |
279 |
<div class="radius-top border-gray" style="background:#E6E6FA;padding:10px"> |
|
280 |
<div style="overflow:hidden"> |
|
281 |
<div style="float:left;width:90%;"> |
|
282 |
<b>Choose a compare branch</b> |
|
283 |
</div> |
|
284 |
<div style="float:left:width:10%;text-align:right;"> |
|
285 |
<i id="compare-branch-close" class="icon-remove-circle"></i> |
|
added compare branch popup t...
|
286 |
</div> |
287 |
</div> |
|
288 |
</div> |
|
improve compare page design
|
289 |
<div class="border-gray" style="background:#F5F5F5;border-top:none;border-bottom:none;text-align:center;padding:10px 0"> |
290 |
%= text_field 'compare-branch', style => 'margin-bottom:0;width:270px', placeholder => 'Branch, tag, commit, or history marker'; |
|
291 |
</div> |
|
292 |
<div style="background:white;max-height:500px;overflow:auto;"> |
|
293 |
<ul class="nav nav-tabs nav-stacked"> |
|
294 |
% for (my $i = 0; $i < @$branches; $i++) { |
|
295 |
% my $branch = $branches->[$i]; |
|
296 |
<li> |
|
show not able to merge
|
297 |
<a style="border-top-left-radius:0px;border-top-right-radius:0px;" |
298 |
href="<%= url_with("/$user/$project/compare/$from_rev...$branch->{name}") %>"> |
|
improve compare page design
|
299 |
<%= $branch->{name} %> |
300 |
</a> |
|
301 |
</li> |
|
302 |
% } |
|
303 |
</ul> |
|
304 |
</div> |
|
added base branch selection ...
|
305 |
</div> |
improve compare page design
|
306 |
</div> |
add pull request form
|
307 |
|
show not able to merge
|
308 |
% if ($merge_automatical) { |
add pull request form
|
309 |
<div class="compare-open-pull-request"> |
add create pull request logi...
|
310 |
<form action="<%= url_for %>" method="post"> |
311 |
<%= hidden_field op => 'create-pull-request' %> |
|
add pull request form
|
312 |
<div class="compare-open-pull-request-title"> |
cleanup methods
|
313 |
<%= text_field 'title' => $commits->[0]{title_short} %> |
add pull request form
|
314 |
</div> |
315 |
<div class="compare-open-pull-request-message"> |
|
316 |
<%= text_area 'message' %> |
|
317 |
</div> |
|
318 |
<div class="compare-open-pull-request-button"> |
|
319 |
<%= submit_button 'Create pull request', class => 'btn btn-success' %> |
|
320 |
</div> |
|
321 |
</form> |
|
322 |
</div> |
|
323 |
% } |
|
added base branch popup to c...
|
324 | |
improve compare page design
|
325 |
% if (keys %$commits_date) { |
326 |
<ul class="compare-header"> |
|
327 |
<li> |
|
328 |
<b><%= @$commits %></b> <span>commit</span> |
|
329 |
</li> |
|
330 |
<li> |
|
331 |
<b><%= $authors_count %></b> <span>contributor</span> |
|
332 |
</li> |
|
333 |
<li> |
|
334 |
|
|
335 |
</li> |
|
336 |
<li> |
|
337 |
|
|
338 |
</li> |
|
339 |
</ul> |
|
improved compare page design
|
340 |
|
improve compare page design
|
341 |
<div class="commits"> |
expand compare page tabs
|
342 |
% for my $date (reverse sort keys %$commits_date) { |
343 |
% my $commits = $commits_date->{$date}; |
|
344 |
|
|
improve compare page design
|
345 |
<div class="commit-date"> |
346 |
<i class="icon-off"></i><span>Commits on <%= $date %></span> |
|
expand compare page tabs
|
347 |
</div> |
348 |
|
|
improve compare page design
|
349 |
<ul class="compare-commits-date-container"> |
expand compare page tabs
|
350 |
% for my $commit (sort {$b->{author_epoch} <=> $a->{author_epoch}} @$commits) { |
add user page link from user...
|
351 |
<% |
fix mail bug
|
352 |
my $commit_author_email = $commit->{author_email}; |
add user page link from user...
|
353 |
my $commit_author_id = app->dbi->model('user')->select( |
354 |
'id', |
|
fix mail bug
|
355 |
where => {email => $commit_author_email} |
add user page link from user...
|
356 |
)->value; |
357 |
%> |
|
improve compare page design
|
358 |
<li> |
359 |
<div class="compare-commits-author"> |
|
add user page link from user...
|
360 |
<span title="<%= $commit->{author_email} %>"> |
361 |
% if (defined $commit_author_id) { |
|
362 |
<a href="<%= url_for("/$commit_author_id") %>"><%= $commit_author_id %></a> |
|
363 |
% } else { |
|
364 |
<%= $commit->{author_name} %> |
|
365 |
% } |
|
366 |
</span> |
|
expand compare page tabs
|
367 |
</div> |
improve compare page design
|
368 |
<div class="compare-commits-commit-title"> |
369 |
<a style="color:#333" href="<%= url_for("/$user/$project/commit/$commit->{id}") %>"> |
|
370 |
<%= $commit->{title_short} %> |
|
371 |
</a> |
|
372 |
</div> |
|
373 |
<div class="compare-commits-commit-id"> |
|
374 |
<a href="<%= url_for("/$user/$project/commit/$commit->{id}") %>"> |
|
375 |
<%= substr($commit->{id}, 0, 7) %> |
|
376 |
</a> |
|
377 |
</div> |
|
378 |
</li> |
|
improved branches page and c...
|
379 |
% } |
improve compare page design
|
380 |
</ul> |
expand compare page tabs
|
381 |
% } |
improve compare page design
|
382 |
</div> |
383 |
|
|
384 |
%= include '/include/commit_body'; |
|
385 |
% } else { |
|
improve compare page
|
386 |
<div class="compare-nothing"> |
387 |
<div> |
|
388 |
<b><big>There isn't anything to compare.</big></b> |
|
389 |
</div> |
|
390 |
<div> |
|
show not able to merge
|
391 |
<b> |
392 |
<%= $from_rev %></b> is up to date with all commits from |
|
393 |
<b><%= $rev %></b>. |
|
394 |
Try <a href="<%= url_for("/$user/$project/compare/$rev...$from_rev") %>">switching the base</a> for your comparison. |
|
improve compare page
|
395 |
</div> |
improve compare page design
|
396 |
</div> |
397 |
% } |
|
398 |
</div> |
|
399 |
%= include '/include/footer'; |