Commit 15b17b3f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Implement approve button

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 73faf3c7
...@@ -4,7 +4,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -4,7 +4,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
before_action :module_enabled before_action :module_enabled
before_action :merge_request, only: [ before_action :merge_request, only: [
:edit, :update, :show, :diffs, :commits, :automerge, :automerge_check, :edit, :update, :show, :diffs, :commits, :automerge, :automerge_check,
:ci_status, :toggle_subscription :ci_status, :toggle_subscription, :approve
] ]
before_action :closes_issues, only: [:edit, :update, :show, :diffs, :commits] before_action :closes_issues, only: [:edit, :update, :show, :diffs, :commits]
before_action :validates_merge_request, only: [:show, :diffs, :commits] before_action :validates_merge_request, only: [:show, :diffs, :commits]
...@@ -195,6 +195,14 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -195,6 +195,14 @@ class Projects::MergeRequestsController < Projects::ApplicationController
render nothing: true render nothing: true
end end
def approve
@approval = @merge_request.approvals.new
@approval.user = current_user
@approval.save
redirect_to merge_request_path(@merge_request)
end
protected protected
def selected_target_project def selected_target_project
......
...@@ -17,34 +17,39 @@ ...@@ -17,34 +17,39 @@
- if @show_merge_controls - if @show_merge_controls
.automerge_widget.can_be_merged.hide .automerge_widget.can_be_merged.hide
.clearfix .clearfix
= form_for [:automerge, @project.namespace.becomes(Namespace), @project, @merge_request], remote: true, method: :post do |f| - if @merge_request.requires_approve?
.accept-merge-holder.clearfix.js-toggle-container = form_for [:approve, @project.namespace.becomes(Namespace), @project, @merge_request], method: :post do |f|
.accept-action %p This merge request must be approved by #{pluralize(@merge_request.approvals_left, 'user')} before it can be merged
= f.submit "Accept Merge Request", class: "btn btn-create accept_merge_request" = f.submit "Approve Merge Request", class: "btn btn-reopen"
- if can_remove_branch?(@merge_request.source_project, @merge_request.source_branch) && !@merge_request.for_fork? - else
.accept-control.checkbox = form_for [:automerge, @project.namespace.becomes(Namespace), @project, @merge_request], remote: true, method: :post do |f|
= label_tag :should_remove_source_branch, class: "remove_source_checkbox" do .accept-merge-holder.clearfix.js-toggle-container
= check_box_tag :should_remove_source_branch .accept-action
Remove source-branch = f.submit "Accept Merge Request", class: "btn btn-create accept_merge_request"
- if @merge_request.target_project.merge_requests_rebase_enabled && can_rebase?(@merge_request.target_project, @merge_request.target_branch) - if can_remove_branch?(@merge_request.source_project, @merge_request.source_branch) && !@merge_request.for_fork?
.accept-control.remove_branch_holder .accept-control.checkbox
= label_tag :should_rebase, class: "checkbox" do = label_tag :should_remove_source_branch, class: "remove_source_checkbox" do
= check_box_tag :should_rebase, "1", @project.merge_requests_rebase_default = check_box_tag :should_remove_source_branch
Rebase before merge Remove source-branch
.accept-control - if @merge_request.target_project.merge_requests_rebase_enabled && can_rebase?(@merge_request.target_project, @merge_request.target_branch)
= link_to "#", class: "modify-merge-commit-link js-toggle-button", title: "Modify merge commit message" do .accept-control.remove_branch_holder
%i.fa.fa-edit = label_tag :should_rebase, class: "checkbox" do
Modify commit message = check_box_tag :should_rebase, "1", @project.merge_requests_rebase_default
.js-toggle-content.hide.prepend-top-20 Rebase before merge
= render 'shared/commit_message_container', params: params, .accept-control
text: @merge_request.merge_commit_message, = link_to "#", class: "modify-merge-commit-link js-toggle-button", title: "Modify merge commit message" do
rows: 14, hint: true %i.fa.fa-edit
Modify commit message
.js-toggle-content.hide.prepend-top-20
= render 'shared/commit_message_container', params: params,
text: @merge_request.merge_commit_message,
rows: 14, hint: true
%br %br
.light .light
If you want to merge this request manually, you can use the If you want to merge this request manually, you can use the
%strong %strong
= link_to "command line", "#modal_merge_info", class: "how_to_merge_link vlink", title: "How To Merge", "data-toggle" => "modal" = link_to "command line", "#modal_merge_info", class: "how_to_merge_link vlink", title: "How To Merge", "data-toggle" => "modal"
.automerge_widget.no_satellite.hide .automerge_widget.no_satellite.hide
......
...@@ -491,6 +491,7 @@ Gitlab::Application.routes.draw do ...@@ -491,6 +491,7 @@ Gitlab::Application.routes.draw do
get :automerge_check get :automerge_check
get :ci_status get :ci_status
post :toggle_subscription post :toggle_subscription
post :approve
end end
collection do collection do
......
...@@ -220,3 +220,9 @@ Feature: Project Merge Requests ...@@ -220,3 +220,9 @@ Feature: Project Merge Requests
When I click the "Target branch" dropdown When I click the "Target branch" dropdown
And I select a new target branch And I select a new target branch
Then I should see new target branch changes Then I should see new target branch changes
Scenario: I approve merge request
Given merge request 'Bug NS-04' must be approved
Given I click link "Bug NS-04"
And I click link "Approve"
Then I should see approved merge request "Bug NS-04"
...@@ -329,6 +329,21 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps ...@@ -329,6 +329,21 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
page.should have_content 'Target branch changed from master to feature' page.should have_content 'Target branch changed from master to feature'
end end
step 'merge request \'Bug NS-04\' must be approved' do
merge_request = MergeRequest.find_by!(title: "Bug NS-04")
project = merge_request.target_project
project.approvals_before_merge = 1
project.save!
end
step 'I click link "Approve"' do
click_button 'Approve Merge Request'
end
step 'I should see approved merge request "Bug NS-04"' do
page.should have_button("Accept Merge Request")
end
def merge_request def merge_request
@merge_request ||= MergeRequest.find_by!(title: "Bug NS-05") @merge_request ||= MergeRequest.find_by!(title: "Bug NS-05")
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment