Improve the "easy WIP & un-WIP from link" feature
This commit is contained in:
parent
d4b49587b9
commit
0b942541da
|
@ -1,5 +1,5 @@
|
||||||
class @IssuableForm
|
class @IssuableForm
|
||||||
wipRegex: /^\[?WIP(\]|:| )\s*/i
|
wipRegex: /^\s*(\[WIP\]\s*|WIP:\s*|WIP\s+)+\s*/i
|
||||||
constructor: (@form) ->
|
constructor: (@form) ->
|
||||||
GitLab.GfmAutoComplete.setup()
|
GitLab.GfmAutoComplete.setup()
|
||||||
new UsersSelect()
|
new UsersSelect()
|
||||||
|
@ -35,39 +35,39 @@ class @IssuableForm
|
||||||
@descriptionField.data("autosave").reset()
|
@descriptionField.data("autosave").reset()
|
||||||
|
|
||||||
initWip: ->
|
initWip: ->
|
||||||
return unless @form.find(".js-wip-explanation").length
|
@$wipExplanation = @form.find(".js-wip-explanation")
|
||||||
|
@$noWipExplanation = @form.find(".js-no-wip-explanation")
|
||||||
|
return unless @$wipExplanation.length and @$noWipExplanation.length
|
||||||
|
|
||||||
@form.on "click", ".js-remove-wip", @removeWip
|
@form.on "click", ".js-toggle-wip", @toggleWip
|
||||||
|
|
||||||
@form.on "click", ".js-add-wip", @addWip
|
@titleField.on "keyup blur", @renderWipExplanation
|
||||||
|
|
||||||
@titleField.on "change", @renderWipExplanation
|
|
||||||
|
|
||||||
@renderWipExplanation()
|
@renderWipExplanation()
|
||||||
|
|
||||||
workInProgress: ->
|
workInProgress: ->
|
||||||
@titleField.val().match(@wipRegex)
|
@wipRegex.test @titleField.val()
|
||||||
|
|
||||||
renderWipExplanation: =>
|
renderWipExplanation: =>
|
||||||
if @workInProgress()
|
if @workInProgress()
|
||||||
@form.find(".js-wip-explanation").show()
|
@$wipExplanation.show()
|
||||||
@form.find(".js-no-wip-explanation").hide()
|
@$noWipExplanation.hide()
|
||||||
else
|
else
|
||||||
@form.find(".js-wip-explanation").hide()
|
@$wipExplanation.hide()
|
||||||
@form.find(".js-no-wip-explanation").show()
|
@$noWipExplanation.show()
|
||||||
|
|
||||||
removeWip: (event) =>
|
toggleWip: (event) =>
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
|
||||||
return unless @workInProgress()
|
if @workInProgress()
|
||||||
|
@removeWip()
|
||||||
|
else
|
||||||
|
@addWip()
|
||||||
|
|
||||||
|
@renderWipExplanation()
|
||||||
|
|
||||||
|
removeWip: ->
|
||||||
@titleField.val @titleField.val().replace(@wipRegex, "")
|
@titleField.val @titleField.val().replace(@wipRegex, "")
|
||||||
|
|
||||||
@renderWipExplanation()
|
addWip: ->
|
||||||
|
|
||||||
addWip: (event) =>
|
|
||||||
event.preventDefault()
|
|
||||||
|
|
||||||
return if @workInProgress()
|
|
||||||
@titleField.val "WIP: #{@titleField.val()}"
|
@titleField.val "WIP: #{@titleField.val()}"
|
||||||
|
|
||||||
@renderWipExplanation()
|
|
||||||
|
|
|
@ -259,7 +259,7 @@ class MergeRequest < ActiveRecord::Base
|
||||||
self.target_project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::CLOSED).last
|
self.target_project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::CLOSED).last
|
||||||
end
|
end
|
||||||
|
|
||||||
WIP_REGEX = /\A\[?WIP(\]|:| )\s*/i.freeze
|
WIP_REGEX = /\A\s*(\[WIP\]\s*|WIP:\s*|WIP\s+)+\s*/i.freeze
|
||||||
|
|
||||||
def work_in_progress?
|
def work_in_progress?
|
||||||
title =~ WIP_REGEX
|
title =~ WIP_REGEX
|
||||||
|
|
|
@ -6,11 +6,8 @@ module MergeRequests
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_title_change_note(issuable, old_title)
|
def create_title_change_note(issuable, old_title)
|
||||||
wipless_old_title = old_title.sub(MergeRequest::WIP_REGEX, "")
|
removed_wip = old_title =~ MergeRequest::WIP_REGEX && !issuable.work_in_progress?
|
||||||
wipless_new_title = issuable.title.sub(MergeRequest::WIP_REGEX, "")
|
added_wip = old_title !~ MergeRequest::WIP_REGEX && issuable.work_in_progress?
|
||||||
|
|
||||||
removed_wip = wipless_old_title == issuable.title
|
|
||||||
added_wip = wipless_new_title == old_title
|
|
||||||
|
|
||||||
if removed_wip
|
if removed_wip
|
||||||
SystemNoteService.remove_merge_request_wip(issuable, issuable.project, current_user)
|
SystemNoteService.remove_merge_request_wip(issuable, issuable.project, current_user)
|
||||||
|
|
|
@ -145,13 +145,13 @@ class SystemNoteService
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.remove_merge_request_wip(noteable, project, author)
|
def self.remove_merge_request_wip(noteable, project, author)
|
||||||
body = 'Unmarked this merge request as Work In Progress'
|
body = 'Unmarked this merge request as a Work In Progress'
|
||||||
|
|
||||||
create_note(noteable: noteable, project: project, author: author, note: body)
|
create_note(noteable: noteable, project: project, author: author, note: body)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.add_merge_request_wip(noteable, project, author)
|
def self.add_merge_request_wip(noteable, project, author)
|
||||||
body = 'Marked this merge request as **Work In Progress**'
|
body = 'Marked this merge request as a **Work In Progress**'
|
||||||
|
|
||||||
create_note(noteable: noteable, project: project, author: author, note: body)
|
create_note(noteable: noteable, project: project, author: author, note: body)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
%h4
|
%h4
|
||||||
This merge request is currently a Work In Progress
|
This merge request is currently a Work In Progress
|
||||||
|
|
||||||
%p
|
- if can?(current_user, :update_merge_request, @merge_request)
|
||||||
|
%p
|
||||||
When this merge request is ready,
|
When this merge request is ready,
|
||||||
- text = 'remove the "WIP" prefix from the title'
|
= link_to remove_wip_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), method: :post do
|
||||||
- if can?(current_user, :update_merge_request, @merge_request)
|
remove the
|
||||||
= link_to text, remove_wip_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), method: :post
|
%code WIP:
|
||||||
- else
|
prefix from the title
|
||||||
= text
|
|
||||||
to allow it to be merged.
|
to allow it to be merged.
|
||||||
|
|
|
@ -14,15 +14,20 @@
|
||||||
- if issuable.is_a?(MergeRequest)
|
- if issuable.is_a?(MergeRequest)
|
||||||
%p.help-block
|
%p.help-block
|
||||||
.js-wip-explanation
|
.js-wip-explanation
|
||||||
%a{href: "#", class: "js-remove-wip", data: { }}
|
%a.js-toggle-wip{href: ""}
|
||||||
Remove the <code>WIP</code> prefix from the title
|
Remove the
|
||||||
|
%code WIP:
|
||||||
|
prefix from the title
|
||||||
to allow this
|
to allow this
|
||||||
<strong>Work In Progress</strong> merge request to be merged when it's ready.
|
%strong Work In Progress
|
||||||
|
merge request to be merged when it's ready.
|
||||||
.js-no-wip-explanation
|
.js-no-wip-explanation
|
||||||
%a{href: "#", class: "js-add-wip"}
|
%a.js-toggle-wip{href: ""}
|
||||||
Start the title with <code>[WIP]</code> or <code>WIP:</code>
|
Start the title with
|
||||||
|
%code WIP:
|
||||||
to prevent a
|
to prevent a
|
||||||
<strong>Work In Progress</strong> merge request from being merged before it's ready.
|
%strong Work In Progress
|
||||||
|
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'
|
||||||
.col-sm-10
|
.col-sm-10
|
||||||
|
|
|
@ -174,24 +174,11 @@ describe MergeRequest, models: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#work_in_progress?" do
|
describe "#work_in_progress?" do
|
||||||
it "detects the 'WIP ' prefix" do
|
['WIP ', 'WIP:', 'WIP: ', '[WIP]', '[WIP] ', ' [WIP] WIP [WIP] WIP: WIP '].each do |wip_prefix|
|
||||||
subject.title = "WIP #{subject.title}"
|
it "detects the '#{wip_prefix}' prefix" do
|
||||||
|
subject.title = "#{wip_prefix}#{subject.title}"
|
||||||
expect(subject).to be_work_in_progress
|
expect(subject).to be_work_in_progress
|
||||||
end
|
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 "detects the '[WIP]' prefix" do
|
|
||||||
subject.title = "[WIP]#{subject.title}"
|
|
||||||
expect(subject).to be_work_in_progress
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't detect WIP for words starting with WIP" do
|
it "doesn't detect WIP for words starting with WIP" do
|
||||||
|
@ -199,6 +186,11 @@ describe MergeRequest, models: true do
|
||||||
expect(subject).not_to be_work_in_progress
|
expect(subject).not_to be_work_in_progress
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "doesn't detect WIP for words containing with WIP" do
|
||||||
|
subject.title = "WupWipwap #{subject.title}"
|
||||||
|
expect(subject).not_to be_work_in_progress
|
||||||
|
end
|
||||||
|
|
||||||
it "doesn't detect WIP by default" do
|
it "doesn't detect WIP by default" do
|
||||||
expect(subject).not_to be_work_in_progress
|
expect(subject).not_to be_work_in_progress
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue