... | ... |
@@ -17,6 +17,21 @@ has 'authorized_keys_file'; |
17 | 17 |
|
18 | 18 |
has '_tmp_branch' => '__gitprep_tmp_branch__'; |
19 | 19 |
|
20 |
+sub merge_and_push { |
|
21 |
+ my ($self, $work_rep_info, $rep_info1, $base_branch, $rep_info2, $target_branch) = @_; |
|
22 |
+ |
|
23 |
+ # Merge |
|
24 |
+ my $target_user_id = $rep_info2->{user}; |
|
25 |
+ my @git_merge_cmd = $self->app->git->cmd($work_rep_info, 'merge', "$target_user_id/$target_branch"); |
|
26 |
+ Gitprep::Util::run_command(@git_merge_cmd) |
|
27 |
+ or Carp::croak "Can't execute git merge: @git_merge_cmd"; |
|
28 |
+ |
|
29 |
+ # Push |
|
30 |
+ my @git_push_cmd = $self->app->git->cmd($work_rep_info, 'push', 'origin', $base_branch); |
|
31 |
+ Gitprep::Util::run_command(@git_push_cmd) |
|
32 |
+ or Carp::croak "Can't execute git push: @git_push_cmd"; |
|
33 |
+} |
|
34 |
+ |
|
20 | 35 |
sub prepare_merge { |
21 | 36 |
my ($self, $work_rep_info, $rep_info1, $base_branch, $rep_info2, $target_branch) = @_; |
22 | 37 |
|
... | ... |
@@ -82,7 +97,7 @@ sub check_merge_automatical { |
82 | 97 |
my @git_format_patch_cmd = $self->app->git->cmd( |
83 | 98 |
$work_rep_info, |
84 | 99 |
'format-patch', |
85 |
- "$tmp_branch..$target_user_id/$target_branch", |
|
100 |
+ "origin/$base_branch..$target_user_id/$target_branch", |
|
86 | 101 |
"--stdout" |
87 | 102 |
); |
88 | 103 |
open my $git_format_patch_fh, '-|', @git_format_patch_cmd |
... | ... |
@@ -104,8 +119,10 @@ sub check_merge_automatical { |
104 | 119 |
$patch_file, |
105 | 120 |
'--check' |
106 | 121 |
); |
122 |
+ |
|
107 | 123 |
my $automatical = Gitprep::Util::run_command(@git_apply_cmd); |
108 | 124 |
|
125 |
+ |
|
109 | 126 |
return $automatical; |
110 | 127 |
} |
111 | 128 |
|
... | ... |
@@ -13,8 +13,23 @@ |
13 | 13 |
# Repository information |
14 | 14 |
my $rep_info = app->rep_info($user_id, $project_id); |
15 | 15 |
|
16 |
+ # Working repository information |
|
17 |
+ my $work_rep_info = app->work_rep_info($user_id, $project_id); |
|
18 |
+ |
|
16 | 19 |
# Git |
17 | 20 |
my $git = $self->app->git; |
21 |
+ |
|
22 |
+ # Pull requests |
|
23 |
+ my $pull_request = app->dbi->model('pull_request')->select( |
|
24 |
+ [ |
|
25 |
+ {__MY__ => '*'}, |
|
26 |
+ {user => ['id']} |
|
27 |
+ ], |
|
28 |
+ where => {'pull_request.row_id' => $row_id} |
|
29 |
+ )->one; |
|
30 |
+ |
|
31 |
+ my $branch1 = $pull_request->{branch1}; |
|
32 |
+ my $branch2 = $pull_request->{branch2}; |
|
18 | 33 |
|
19 | 34 |
if (lc $self->req->method eq 'post') { |
20 | 35 |
|
... | ... |
@@ -46,20 +61,48 @@ |
46 | 61 |
$self->redirect_to('current'); |
47 | 62 |
return; |
48 | 63 |
} |
64 |
+ elsif ($op eq 'merge') { |
|
65 |
+ |
|
66 |
+ # Lock working repository |
|
67 |
+ my $lock_fh = $self->app->manager->lock_rep($work_rep_info); |
|
68 |
+ |
|
69 |
+ # Prepare merge |
|
70 |
+ $self->app->manager->prepare_merge( |
|
71 |
+ $work_rep_info, |
|
72 |
+ $rep_info, |
|
73 |
+ $branch1, |
|
74 |
+ $rep_info, |
|
75 |
+ $branch2 |
|
76 |
+ ); |
|
77 |
+ |
|
78 |
+ # Check merge automatical |
|
79 |
+ my $merge_automatical = $self->app->manager->check_merge_automatical( |
|
80 |
+ $work_rep_info, |
|
81 |
+ $rep_info, |
|
82 |
+ $branch1, |
|
83 |
+ $rep_info, |
|
84 |
+ $branch2 |
|
85 |
+ ); |
|
86 |
+ |
|
87 |
+ if ($merge_automatical) { |
|
88 |
+ app->manager->merge_and_push( |
|
89 |
+ $work_rep_info, |
|
90 |
+ $rep_info, |
|
91 |
+ $branch1, |
|
92 |
+ $rep_info, |
|
93 |
+ $branch2 |
|
94 |
+ ); |
|
95 |
+ |
|
96 |
+ app->dbi->model('pull_request')->update( |
|
97 |
+ {open => 0}, |
|
98 |
+ where => {row_id => $row_id} |
|
99 |
+ ); |
|
100 |
+ |
|
101 |
+ $self->redirect_to("/$user_id/$project_id/tree/$branch1"); |
|
102 |
+ } |
|
103 |
+ } |
|
49 | 104 |
} |
50 | 105 |
|
51 |
- # Pull requests |
|
52 |
- my $pull_request = app->dbi->model('pull_request')->select( |
|
53 |
- [ |
|
54 |
- {__MY__ => '*'}, |
|
55 |
- {user => ['id']} |
|
56 |
- ], |
|
57 |
- where => {'pull_request.row_id' => $row_id} |
|
58 |
- )->one; |
|
59 |
- |
|
60 |
- my $branch1 = $pull_request->{branch1}; |
|
61 |
- my $branch2 = $pull_request->{branch2}; |
|
62 |
- |
|
63 | 106 |
# Commits |
64 | 107 |
my $commits = $git->forward_commits($rep_info, $branch1, $branch2); |
65 | 108 |
my $commits_count = @$commits; |
... | ... |
@@ -91,8 +134,21 @@ |
91 | 134 |
# Check merge automatically |
92 | 135 |
my $merge_automatical; |
93 | 136 |
if ($api->can_write_access($session_user_id, $user_id, $project_id) && $pull_request->{open}) { |
137 |
+ |
|
138 |
+ my $lock_fh = $self->app->manager->lock_rep($work_rep_info); |
|
139 |
+ |
|
140 |
+ # Prepare merge |
|
141 |
+ $self->app->manager->prepare_merge( |
|
142 |
+ $work_rep_info, |
|
143 |
+ $rep_info, |
|
144 |
+ $branch1, |
|
145 |
+ $rep_info, |
|
146 |
+ $branch2 |
|
147 |
+ ); |
|
148 |
+ |
|
149 |
+ # Check merge automatical |
|
94 | 150 |
$merge_automatical = $self->app->manager->check_merge_automatical( |
95 |
- app->work_rep_info($user_id, $project_id), |
|
151 |
+ $work_rep_info, |
|
96 | 152 |
$rep_info, |
97 | 153 |
$branch1, |
98 | 154 |
$rep_info, |
... | ... |
@@ -224,8 +280,9 @@ |
224 | 280 |
%= include '/include/commit_body', %commit_body_args; |
225 | 281 |
|
226 | 282 |
% if ($api->can_write_access($session_user_id, $user_id, $project_id)) { |
227 |
- % if ($pull_request->{open}) { |
|
283 |
+ % if ($merge_automatical && $pull_request->{open}) { |
|
228 | 284 |
<form action="<%= url_for %>" method="post"> |
285 |
+ <%= hidden_field op => 'merge' %> |
|
229 | 286 |
<div class="pull-request-form"> |
230 | 287 |
<div style="overflow:hidden"> |
231 | 288 |
<div style="float:left;padding:10px;padding-right:0"> |