<% # API my $api = gitprep_api; # Parameters my $base_user_id = param('user'); my $base_project_id = param('project'); my $issue_number = param('number'); # Issue my $issue = app->dbi->model('issue')->select( [ {__MY__ => '*'}, {open_user => ['id']} ], where => { 'project.id' => $base_project_id, 'issue.number' => $issue_number } )->one; # Pull requests my $pull_request = app->dbi->model('pull_request')->select( where => {row_id => $issue->{pull_request}} )->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 $target_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); # Display patch if (stash('patch')) { # 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 ); # Create patch my $patch = $self->app->manager->get_patch( $work_rep_info, $target_rep_info, $target_branch ); $self->res->headers->content_type('text/plain; charset=utf-8'); $self->render(text => $patch); return; } # Git my $git = $self->app->git; my $op = param('op') // ''; my $errors; if (lc $self->req->method eq 'post') { # Close pull request my $op = param('op'); if ($op eq 'close-issue') { app->dbi->model('issue')->update( { open => 0 }, where => {row_id => $issue->{row_id}} ); $self->redirect_to('current'); return; } elsif ($op eq 'reopen-issue') { my $open_time = time; app->dbi->model('issue')->update( { open => 1, open_time => $open_time, open_user => $session_user_row_id }, where => { row_id => $issue->{row_id} } ); $self->redirect_to('current'); return; } elsif ($op eq 'merge') { # Access controll unless ($api->can_write_access($session_user_id, $base_user_id, $base_project_id)) { $self->reply->exception('Forbbiden'); return; } # 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); # Close app->dbi->model('issue')->update( { open => 0 }, where => {row_id => $issue->{row_id}} ); $self->redirect_to("/$base_user_id/$base_project_id/tree/$base_branch"); } } elsif ($op eq 'add-comment') { # Parameters my $message = param('message'); # Validation my $vc = app->vc; my $validation = $vc->validation; # Check Message if (!length $message) { $validation->add_failed(message => 'message is empty'); } elsif (length $message > 1000) { $validation->add_failed(message => 'message is too long'); } if ($validation->is_valid) { $api->add_issue_message($base_user_id, $base_project_id, $issue_number, $message); $self->redirect_to; return; } else { $errors = $validation->messages; } } elsif ($op eq 'api-delete-issue-message') { my $issue_message_row_id = param('issue_message_row_id'); my $json = $api->api_delete_issue_message($issue_message_row_id, $base_user_id); $self->render(json => $json); return; } elsif ($op eq 'api-update-issue-message') { my $issue_message_row_id = param('issue_message_row_id'); my $message = param('message'); my $json = $api->api_update_issue_message($issue_message_row_id, $message, $base_user_id); $self->render(json => $json); return; } } # Commits my $commits = $git->forward_commits( $work_rep_info, $base_rep_info, $base_branch, $target_rep_info, $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_id = app->git->ref_to_object_id($base_rep_info, $base_branch); # End commit my $end_commit_id = app->git->ref_to_object_id($target_rep_info, $target_branch); # Issue messages my $issue_messages = app->dbi->model('issue_message')->select( [ {__MY__ => '*'}, {user => ['id']} ], where => {issue => $issue->{row_id}} )->all; # Issue message count my $issue_messages_count = app->dbi->model('issue_message')->select( 'count(*)', where => {issue => $issue->{row_id}}, )->value; # Check merge automatically my $merge_success; if ($api->can_write_access($session_user_id, $base_user_id, $base_project_id) && $issue->{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 ); } # HTTP repository URL my $http_rep_url = url_for("$target_user_id/$target_project_id.git")->to_abs; # SSH repository URL my $url = url_for->to_abs; $url->base(undef); my $ssh_port = config->{basic}{ssh_port}; my $rep_home = app->rep_home; my $execute_user = getpwuid($>); my $ssh_rep_url_base = defined app->config->{basic}{'ssh_rep_url_base'} ? app->config->{basic}{'ssh_rep_url_base'} : $rep_home; my $ssh_rep_url = "ssh://$execute_user\@" . $url->host . ($ssh_port ? ":$ssh_port" : '') . "$ssh_rep_url_base/$user/$project.git"; my $patch_url = url_for("/$base_user_id/$base_project_id/pull/$issue->{number}.patch")->to_abs; my $pre_content_base = "git checkout -b $target_user_id-$target_branch $base_branch"; my $pre_content_http = "git pull $http_rep_url $target_branch"; my $pre_content_ssh = "git pull $ssh_rep_url $target_branch"; # Commit body arguments my %commit_body_args = ( rep_info => $work_rep_info, rev => $end_commit_id, from_rev => $start_commit_id ); layout 'common', title => "Pull Requests Tags \x{30fb} $base_user_id/$base_project_id"; %> %= javascript begin $(document).ready(function() { %= include '/include/js/issue'; }); % end %= include '/include/header';
%= include '/include/errors', errors => $errors;
<% my $pull_title = $pull_request->{target_branch}; $pull_title =~ s/_/ /g; $pull_title = ucfirst $pull_title; %> <%= $pull_title %> #<%= $issue->{number} %>
% if ($issue->{open}) {
Open
% } else {
Closed
% }
% my $open_user_id = $issue->{'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 {
% for my $issue_message (@$issue_messages) { <% my %issue_message_param = ( user_id => $base_user_id, issue_message => $issue_message ); %> %= include '/include/issue_message', %issue_message_param; % }
% 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 && $issue->{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.
% } % } % if ($api->logined) {
<%= hidden_field 'op' %>
%= include '/include/issue_comment_icon';
<%= text_area 'message' %>
Styling with Markdown is supported
% if ($issue->{open}) { % } else { % }
% }
%= include '/include/footer';