... | ... |
@@ -178,7 +178,8 @@ sub startup { |
178 | 178 |
{table => 'ssh_public_key', primary_key => 'key'}, |
179 | 179 |
{table => 'project', primary_key => ['user_id', 'name']}, |
180 | 180 |
{table => 'number', primary_key => 'key'}, |
181 |
- {table => 'collaboration', primary_key => ['user_id', 'project_name', 'collaborator_id']} |
|
181 |
+ {table => 'collaboration', primary_key => ['user_id', 'project_name', 'collaborator_id']}, |
|
182 |
+ {table => 'pull_request'} |
|
182 | 183 |
]; |
183 | 184 |
$dbi->create_model($_) for @$models; |
184 | 185 |
|
... | ... |
@@ -404,13 +405,13 @@ sub startup { |
404 | 405 |
$r->get('/archive/(*rev).zip' => sub { shift->render_maybe('/archive') })->to(archive_type => 'zip' ); |
405 | 406 |
|
406 | 407 |
# Compare |
407 |
- $r->get('/compare' => sub { shift->render_maybe('/compare') }); |
|
408 |
- $r->get( |
|
408 |
+ $r->any('/compare' => sub { shift->render_maybe('/compare') }); |
|
409 |
+ $r->any( |
|
409 | 410 |
'/compare/(:rev1)...(:rev2)' |
410 | 411 |
=> [rev1 => qr/[^\.]+/, rev2 => qr/[^\.]+/] |
411 | 412 |
=> sub { shift->render_maybe('/compare') } |
412 | 413 |
); |
413 |
- $r->get('/compare/(:rev2)' => sub { shift->render_maybe('/compare') }); |
|
414 |
+ $r->any('/compare/(:rev2)' => sub { shift->render_maybe('/compare') }); |
|
414 | 415 |
|
415 | 416 |
# Settings |
416 | 417 |
{ |
... | ... |
@@ -569,7 +569,7 @@ EOS |
569 | 569 |
croak $error; |
570 | 570 |
} |
571 | 571 |
|
572 |
- # Original project id numbert |
|
572 |
+ # Original project id number |
|
573 | 573 |
eval { $dbi->insert({key => 'original_pid'}, table => 'number') }; |
574 | 574 |
my $original_pid = $dbi->select( |
575 | 575 |
'key', |
... | ... |
@@ -581,6 +581,37 @@ EOS |
581 | 581 |
$self->app->log->error($error); |
582 | 582 |
croak $error; |
583 | 583 |
} |
584 |
+ |
|
585 |
+ # Create pull_request table |
|
586 |
+ eval { |
|
587 |
+ my $sql = <<"EOS"; |
|
588 |
+create table pull_request ( |
|
589 |
+ row_id integer primary key autoincrement, |
|
590 |
+ project integer not null default 0, |
|
591 |
+ branch1 not null default '', |
|
592 |
+ branch2 not null default '', |
|
593 |
+ unique(project, branch1, branch2) |
|
594 |
+); |
|
595 |
+EOS |
|
596 |
+ $dbi->execute($sql); |
|
597 |
+ }; |
|
598 |
+ |
|
599 |
+ # Create pull_request columns |
|
600 |
+ my @pull_request_columns = ( |
|
601 |
+ "title not null default ''", |
|
602 |
+ "message not null default ''" |
|
603 |
+ ); |
|
604 |
+ for my $column (@pull_request_columns) { |
|
605 |
+ eval { $dbi->execute("alter table pull_request add column $column") }; |
|
606 |
+ } |
|
607 |
+ |
|
608 |
+ # Check pull_request table |
|
609 |
+ eval { $dbi->select([qw/row_id project branch1 branch2 title/], table => 'pull_request') }; |
|
610 |
+ if ($@) { |
|
611 |
+ my $error = "Can't create pull_request table properly: $@"; |
|
612 |
+ $self->app->log->error($error); |
|
613 |
+ croak $error; |
|
614 |
+ } |
|
584 | 615 |
} |
585 | 616 |
|
586 | 617 |
|
... | ... |
@@ -17,6 +17,53 @@ |
17 | 17 |
# Git |
18 | 18 |
my $git = $self->app->git; |
19 | 19 |
|
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 |
+ |
|
20 | 67 |
# Commits |
21 | 68 |
my $commits = $git->forward_commits(app->rep_info($user, $project), $from_rev, $rev); |
22 | 69 |
my $commits_count = @$commits; |
... | ... |
@@ -250,7 +297,8 @@ |
250 | 297 |
|
251 | 298 |
% if ($merge_automatical) { |
252 | 299 |
<div class="compare-open-pull-request"> |
253 |
- <form> |
|
300 |
+ <form action="<%= url_for %>" method="post"> |
|
301 |
+ <%= hidden_field op => 'create-pull-request' %> |
|
254 | 302 |
<div class="compare-open-pull-request-title"> |
255 | 303 |
<%= text_field 'title' => $commits->[0]{title_short} %> |
256 | 304 |
</div> |