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