diff options
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/controllers/projects/merge_requests_controller.rb | 4 | ||||
-rw-r--r-- | app/models/merge_request.rb | 18 | ||||
-rw-r--r-- | app/views/projects/merge_requests/_show.html.haml | 2 | ||||
-rw-r--r-- | app/views/projects/merge_requests/show/_mr_accept.html.haml | 18 | ||||
-rw-r--r-- | lib/api/merge_requests.rb | 4 | ||||
-rw-r--r-- | spec/models/merge_request_spec.rb | 26 | ||||
-rw-r--r-- | spec/requests/api/merge_requests_spec.rb | 7 |
8 files changed, 73 insertions, 7 deletions
diff --git a/CHANGELOG b/CHANGELOG index ecffcb5262c..305d2c2508e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Please view this file on the master branch, on stable branches it's out of date. v 7.11.0 (unreleased) + - Don't allow a merge request to be merged when its title starts with "WIP". - Get Gitorious importer to work again. - Fix clone URL field and X11 Primary selection (Dmitry Medvinsky) - Ignore invalid lines in .gitmodules diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 41b4e55a598..5b93e95866a 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -124,13 +124,13 @@ class Projects::MergeRequestsController < Projects::ApplicationController @merge_request.check_if_can_be_merged end - render json: { merge_status: @merge_request.merge_status_name } + render json: { merge_status: @merge_request.automerge_status } end def automerge return access_denied! unless allowed_to_merge? - if @merge_request.open? && @merge_request.can_be_merged? + if @merge_request.automergeable? AutoMergeWorker.perform_async(@merge_request.id, current_user.id, params) @status = true else diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 49a00697ee1..64f3c39f131 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -199,6 +199,8 @@ class MergeRequest < ActiveRecord::Base end def automerge!(current_user, commit_message = nil) + return unless automergeable? + MergeRequests::AutoMergeService. new(target_project, current_user). execute(self, commit_message) @@ -208,6 +210,22 @@ class MergeRequest < ActiveRecord::Base opened? || reopened? end + def work_in_progress? + title =~ /\A\[?WIP\]?:? /i + end + + def automergeable? + open? && !work_in_progress? && can_be_merged? + end + + def automerge_status + if work_in_progress? + "work_in_progress" + else + merge_status_name + end + end + def mr_and_commit_notes # Fetch comments only from last 100 commits commits_for_notes_limit = 100 diff --git a/app/views/projects/merge_requests/_show.html.haml b/app/views/projects/merge_requests/_show.html.haml index cec02de84ca..45dd410dd15 100644 --- a/app/views/projects/merge_requests/_show.html.haml +++ b/app/views/projects/merge_requests/_show.html.haml @@ -72,6 +72,6 @@ check_enable: #{@merge_request.unchecked? ? "true" : "false"}, url_to_ci_check: "#{ci_status_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}", ci_enable: #{@project.ci_service ? "true" : "false"}, - current_status: "#{@merge_request.merge_status_name}", + current_status: "#{@merge_request.automerge_status}", action: "#{controller.action_name}" }); diff --git a/app/views/projects/merge_requests/show/_mr_accept.html.haml b/app/views/projects/merge_requests/show/_mr_accept.html.haml index 9f51f84d400..41f739a45b8 100644 --- a/app/views/projects/merge_requests/show/_mr_accept.html.haml +++ b/app/views/projects/merge_requests/show/_mr_accept.html.haml @@ -4,9 +4,11 @@ %strong Archived projects cannot be committed to! - else .automerge_widget.cannot_be_merged.hide - %strong This can't be merged automatically, even if it could be merged you don't have the permission to do so. + %strong This request can't be merged automatically. Even if it could be merged, you don't have permission to do so. + .automerge_widget.work_in_progress.hide + %strong This request can't be merged automatically because it is marked a Work In Progress. Even if it could be merged, you don't have permission to do so. .automerge_widget.can_be_merged.hide - %strong This can be merged automatically but you don't have the permission to do so. + %strong This request can be merged automatically, but you don't have permission to do so. - if @show_merge_controls @@ -57,6 +59,18 @@ This usually happens when git can not resolve conflicts between branches automatically. + .automerge_widget.work_in_progress.hide + %h4 + This request can't be merged because it is marked a <strong>Work In Progress</strong>. + + %p + %button.btn.disabled + %i.fa.fa-warning + Accept Merge Request + + + When the merge request is ready, remove the "WIP" prefix from the title to allow it to be merged. + .automerge_widget.unchecked %p %strong diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb index f3765f5ab03..b252c57faed 100644 --- a/lib/api/merge_requests.rb +++ b/lib/api/merge_requests.rb @@ -186,7 +186,7 @@ module API merge_request.check_if_can_be_merged end - if merge_request.open? + if merge_request.open? && !merge_request.work_in_progress? if merge_request.can_be_merged? merge_request.automerge!(current_user, params[:merge_commit_message] || merge_request.merge_commit_message) present merge_request, with: Entities::MergeRequest @@ -195,7 +195,7 @@ module API end else # Merge request can not be merged - # because it is already closed/merged + # because it is already closed/merged or marked as WIP not_allowed! end else diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 3fcd063efe8..97b8abc49dd 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -115,6 +115,32 @@ describe MergeRequest do end end + describe "#work_in_progress?" do + it "detects the 'WIP ' prefix" do + subject.title = "WIP #{subject.title}" + expect(subject).to be_work_in_progress + end + + it "detects the 'WIP: ' prefix" do + subject.title = "WIP: #{subject.title}" + expect(subject).to be_work_in_progress + end + + it "detects the '[WIP] ' prefix" do + subject.title = "[WIP] #{subject.title}" + expect(subject).to be_work_in_progress + end + + it "doesn't detect WIP for words starting with WIP" do + subject.title = "Wipwap #{subject.title}" + expect(subject).not_to be_work_in_progress + end + + it "doesn't detect WIP by default" do + expect(subject).not_to be_work_in_progress + end + end + it_behaves_like 'an editable mentionable' do subject { create(:merge_request, source_project: project, target_project: project) } diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index 9e252441a4f..5fca831f9be 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -312,6 +312,13 @@ describe API::API, api: true do expect(json_response['message']).to eq('405 Method Not Allowed') end + it "should return 405 if merge_request is a work in progress" do + merge_request.update_attribute(:title, "WIP: #{merge_request.title}") + put api("/projects/#{project.id}/merge_request/#{merge_request.id}/merge", user) + expect(response.status).to eq(405) + expect(json_response['message']).to eq('405 Method Not Allowed') + end + it "should return 401 if user has no permissions to merge" do user2 = create(:user) project.team << [user2, :reporter] |