Commit 09ff9bc7 authored by Douwe Maan's avatar Douwe Maan

Easily (un)mark merge request as WIP using link

Fixes #3768
parent acf9778e
...@@ -3,6 +3,7 @@ Please view this file on the master branch, on stable branches it's out of date. ...@@ -3,6 +3,7 @@ Please view this file on the master branch, on stable branches it's out of date.
v 8.6.0 (unreleased) v 8.6.0 (unreleased)
- Improve the formatting for the user page bio (Connor Shea) - Improve the formatting for the user page bio (Connor Shea)
- Fix avatar stretching by providing a cropping feature (Johann Pardanaud) - Fix avatar stretching by providing a cropping feature (Johann Pardanaud)
- Easily (un)mark merge request as WIP using link
- Use specialized system notes when MR is (un)marked as WIP - Use specialized system notes when MR is (un)marked as WIP
v 8.5.1 v 8.5.1
......
class @IssuableForm class @IssuableForm
wipRegex: /^\[?WIP(\]|:| )\s*/i
constructor: (@form) -> constructor: (@form) ->
GitLab.GfmAutoComplete.setup() GitLab.GfmAutoComplete.setup()
new UsersSelect() new UsersSelect()
...@@ -14,6 +15,8 @@ class @IssuableForm ...@@ -14,6 +15,8 @@ class @IssuableForm
@form.on "submit", @resetAutosave @form.on "submit", @resetAutosave
@form.on "click", ".btn-cancel", @resetAutosave @form.on "click", ".btn-cancel", @resetAutosave
@initWip()
initAutosave: -> initAutosave: ->
new Autosave @titleField, [ new Autosave @titleField, [
document.location.pathname, document.location.pathname,
...@@ -30,3 +33,41 @@ class @IssuableForm ...@@ -30,3 +33,41 @@ class @IssuableForm
resetAutosave: => resetAutosave: =>
@titleField.data("autosave").reset() @titleField.data("autosave").reset()
@descriptionField.data("autosave").reset() @descriptionField.data("autosave").reset()
initWip: ->
return unless @form.find(".js-wip-explanation").length
@form.on "click", ".js-remove-wip", @removeWip
@form.on "click", ".js-add-wip", @addWip
@titleField.on "change", @renderWipExplanation
@renderWipExplanation()
workInProgress: ->
@titleField.val().match(@wipRegex)
renderWipExplanation: =>
if @workInProgress()
@form.find(".js-wip-explanation").show()
@form.find(".js-no-wip-explanation").hide()
else
@form.find(".js-wip-explanation").hide()
@form.find(".js-no-wip-explanation").show()
removeWip: (event) =>
event.preventDefault()
return unless @workInProgress()
@titleField.val @titleField.val().replace(@wipRegex, "")
@renderWipExplanation()
addWip: (event) =>
event.preventDefault()
return if @workInProgress()
@titleField.val "WIP: #{@titleField.val()}"
@renderWipExplanation()
...@@ -2,7 +2,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -2,7 +2,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, :builds, :merge, :merge_check, :edit, :update, :show, :diffs, :commits, :builds, :merge, :merge_check,
:ci_status, :toggle_subscription, :cancel_merge_when_build_succeeds :ci_status, :toggle_subscription, :cancel_merge_when_build_succeeds, :remove_wip
] ]
before_action :closes_issues, only: [:edit, :update, :show, :diffs, :commits, :builds] before_action :closes_issues, only: [:edit, :update, :show, :diffs, :commits, :builds]
before_action :validates_merge_request, only: [:show, :diffs, :commits, :builds] before_action :validates_merge_request, only: [:show, :diffs, :commits, :builds]
...@@ -17,7 +17,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -17,7 +17,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
before_action :authorize_create_merge_request!, only: [:new, :create] before_action :authorize_create_merge_request!, only: [:new, :create]
# Allow modify merge_request # Allow modify merge_request
before_action :authorize_update_merge_request!, only: [:close, :edit, :update, :sort] before_action :authorize_update_merge_request!, only: [:close, :edit, :update, :remove_wip, :sort]
def index def index
terms = params['issue_search'] terms = params['issue_search']
...@@ -161,6 +161,13 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -161,6 +161,13 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end end
end end
def remove_wip
MergeRequests::UpdateService.new(project, current_user, title: @merge_request.wipless_title).execute(@merge_request)
redirect_to namespace_project_merge_request_path(@project.namespace, @project, @merge_request),
notice: "The merge request can now be merged."
end
def merge_check def merge_check
@merge_request.check_if_can_be_merged @merge_request.check_if_can_be_merged
......
...@@ -2,4 +2,10 @@ ...@@ -2,4 +2,10 @@
This merge request is currently a Work In Progress This merge request is currently a Work In Progress
%p %p
When this merge request is ready, remove the "WIP" prefix from the title to allow it to be merged. When this merge request is ready,
- text = 'remove the "WIP" prefix from the title'
- if can?(current_user, :update_merge_request, @merge_request)
= link_to text, remove_wip_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), method: :post
- else
= text
to allow it to be merged.
...@@ -13,11 +13,15 @@ ...@@ -13,11 +13,15 @@
- if issuable.is_a?(MergeRequest) - if issuable.is_a?(MergeRequest)
%p.help-block %p.help-block
- if issuable.work_in_progress? .js-wip-explanation
Remove the <code>WIP</code> prefix from the title to allow this %a{href: "#", class: "js-remove-wip", data: { }}
Remove the <code>WIP</code> prefix from the title
to allow this
<strong>Work In Progress</strong> merge request to be merged when it's ready. <strong>Work In Progress</strong> merge request to be merged when it's ready.
- else .js-no-wip-explanation
Start the title with <code>[WIP]</code> or <code>WIP:</code> to prevent a %a{href: "#", class: "js-add-wip"}
Start the title with <code>[WIP]</code> or <code>WIP:</code>
to prevent a
<strong>Work In Progress</strong> merge request from being merged before it's ready. <strong>Work In Progress</strong> merge request from being merged before it's ready.
.form-group.detail-page-description .form-group.detail-page-description
= f.label :description, 'Description', class: 'control-label' = f.label :description, 'Description', class: 'control-label'
......
...@@ -599,6 +599,7 @@ Rails.application.routes.draw do ...@@ -599,6 +599,7 @@ Rails.application.routes.draw do
post :cancel_merge_when_build_succeeds post :cancel_merge_when_build_succeeds
get :ci_status get :ci_status
post :toggle_subscription post :toggle_subscription
post :remove_wip
end end
collection do collection do
......
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