<% # API my $api = gitprep_api; # Parameters my $base_user_id = param('user'); my $base_project_id = param('project'); my $row_id = param('row_id'); # Pull requests my $pull_request = app->dbi->model('pull_request')->select( [ {__MY__ => '*'}, {'__open_user' => ['id']} ], where => {'pull_request.row_id' => $row_id} )->one; # Base information my $base_project_row_id = $pull_request->{base_project}; my $base_project = app->dbi->model('project')->select( [ {__MY__ => '*'}, {__user => ['id']} ], where => {'project.row_id' => $base_project_row_id} )->one; my $base_branch = $pull_request->{base_branch}; Carp::croak "pull_request invalid user id" if $base_user_id ne $base_project->{'__user.id'}; Carp::croak "pull_request invalid project id" if $base_project_id ne $base_project->{id}; # Target information my $target_project_row_id = $pull_request->{target_project}; my $target_project = app->dbi->model('project')->select( [ {__MY__ => '*'}, {__user => ['id']} ], where => {'project.row_id' => $target_project_row_id} )->one; my $target_branch = $pull_request->{target_branch}; my $target_user_id = $target_project->{'__user.id'}; my $taregt_project_id = $target_project->{id}; # Session my $session_user_row_id = $api->session_user_row_id; my $session_user_id = $api->session_user_id; # Base repository information my $base_rep_info = app->rep_info($base_user_id, $base_project_id); # Target repository information my $target_rep_info = app->rep_info($target_user_id, $base_project_id); # Working repository information my $work_rep_info = app->work_rep_info($base_user_id, $base_project_id); # Git my $git = $self->app->git; if (lc $self->req->method eq 'post') { # Access controll unless ($api->can_write_access($session_user_id, $base_user_id, $base_project_id)) { $self->reply->exception('Forbbiden'); return; } # Close pull request my $op = param('op'); if ($op eq 'close') { app->dbi->model('pull_request')->update( { open => 0, open_user => $session_user_row_id }, where => {row_id => $row_id} ); $self->redirect_to('current'); return; } elsif ($op eq 'reopen') { my $open_time = time; app->dbi->model('pull_request')->update( { open => 1, open_time => $open_time, open_user => $session_user_row_id }, where => {row_id => $row_id} ); $self->redirect_to('current'); return; } elsif ($op eq 'merge') { # Lock working repository my $lock_fh = $self->app->manager->lock_rep($work_rep_info); # Prepare merge $self->app->manager->prepare_merge( $work_rep_info, $base_rep_info, $base_branch, $target_rep_info, $target_branch ); # Merge my $merge_success = $self->app->manager->merge( $work_rep_info, $target_rep_info, $target_branch ); if ($merge_success) { # Push app->manager->push($work_rep_info, $base_branch); app->dbi->model('pull_request')->update( { open => 0, open_user => $session_user_row_id }, where => {row_id => $row_id} ); $self->redirect_to("/$base_user_id/$base_project_id/tree/$base_branch"); } } } # Commits my $commits = $git->forward_commits($base_rep_info, $base_branch, $target_branch); my $commits_count = @$commits; my $commits_date = {}; my $authors = {}; for my $commit (@$commits) { my $date = $commit->{age_string_date_local}; $commits_date->{$date} ||= []; $authors->{$commit->{author}} = 1; push @{$commits_date->{$date}}, $commit; } my $authors_count = keys %$authors; # Start commit my $start_commit = $git->separated_commit($base_rep_info, $base_branch, $target_branch); # End commit my $end_commit = $git->get_commit($target_rep_info, $target_branch); # Pull request first message my $pull_request_message_first = app->dbi->model('pull_request_message')->select( [ {__MY__ => '*'}, {__user => ['id']} ], where => {pull_request => $row_id, number => 1} )->one; # Check merge automatically my $merge_success; if ($api->can_write_access($session_user_id, $base_user_id, $base_project_id) && $pull_request->{open}) { my $lock_fh = $self->app->manager->lock_rep($work_rep_info); # Prepare merge $self->app->manager->prepare_merge( $work_rep_info, $base_rep_info, $base_branch, $target_rep_info, $target_branch ); # Check merge automatical $merge_success = $self->app->manager->merge( $work_rep_info, $target_rep_info, $target_branch ); } # Commit body arguments my %commit_body_args = ( id => $end_commit->{id}, from_id => $start_commit->{id}, rev => $end_commit->{id}, from_rev => $start_commit->{id} ); %> % layout 'common', title => "Pull Requests Tags \x{30fb} $base_user_id/$base_project_id"; %= include '/include/header';
<% my $pull_title = $pull_request->{target_branch}; $pull_title =~ s/_/ /g; $pull_title = ucfirst $pull_title; %> <%= $pull_title %> #<%= $pull_request->{row_id} %>
% if ($pull_request->{open}) {
Open
% } else {
Closed
% }
% my $open_user_id = $pull_request->{'__open_user.id'}; "><%= $open_user_id %> wants to merge <%= $commits_count %> commits into <%= $pull_request->{base_branch} %> from % if ($base_user_id ne $target_user_id) { <%= $target_user_id %> / % } <%= $pull_request->{target_branch} %>
% if (!$commits_count) {
There isn't anything to compare.
% } else {
<%= $pull_request_message_first->{'__open_user.id'} %> commented <%= $api->age_string($pull_request_message_first->{update_time}) %>
<%= $pull_request_message_first->{message} %>
% for my $date (reverse sort keys %$commits_date) { % my $commits = $commits_date->{$date};
Commits on <%= $date %>
% }
%= include '/include/commit_body', %commit_body_args; % } % if ($api->can_write_access($session_user_id, $base_user_id, $base_project_id)) { % if ($commits_count && $merge_success && $pull_request->{open}) {
<%= "\x{2714}" %>
This branch has no conflicts with the base branch
Merging can be performed automatically.
<%= hidden_field op => 'merge' %> <%= submit_button 'Merge pull request', class => "btn btn-success" %> You can also view command line instructions.
Merging via command line
If you do not want to use the merge button or an automatic merge cannot be performed, you can perform a manual merge on the command line.
<%= text_field clone_url => "https://github.com/kaloyan13/gitprep.git" %>
Step 1: From your project repository, check out a new branch and test the changes.
git checkout -b kaloyan13-master master
git pull https://github.com/kaloyan13/gitprep.git master
Step 2: Merge the changes and update on GitPrep.
git checkout master
git merge --no-ff kaloyan13-master
git push origin master
% } % if ($pull_request->{open}) {
<%= hidden_field op => 'close' %> <%= submit_button 'Close pull request', class => 'btn' %>
% } else {
<%= hidden_field op => 'reopen' %> <%= submit_button 'Reopen pull request', class => 'btn' %>
% } % }
%= include '/include/footer';