Commit 3c45dca6 authored by Igor Drozdov's avatar Igor Drozdov

Fix incorrect marking MR as Draft

If a merge request has Draft or WIP in the middle of title
It shouldn't be marked as a draft merge request
parent b7724b55
---
title: Fix incorrect marking MR as Draft
merge_request: 36869
author:
type: fixed
...@@ -251,11 +251,11 @@ module Gitlab ...@@ -251,11 +251,11 @@ module Gitlab
end end
def merge_request_wip def merge_request_wip
/(?i)(\[WIP\]\s*|WIP:\s*|WIP\s+|WIP$)/ /(?i)(\[WIP\]\s*|WIP:\s*|WIP$)/
end end
def merge_request_draft def merge_request_draft
/(?i)(\[draft\]|\(draft\)|draft:|draft\s\-\s|draft\s|draft$)/ /(?i)(\[draft\]|\(draft\)|draft:|draft\s\-\s|draft$)/
end end
def issue def issue
......
...@@ -1114,8 +1114,8 @@ RSpec.describe MergeRequest do ...@@ -1114,8 +1114,8 @@ RSpec.describe MergeRequest do
subject { build_stubbed(:merge_request) } subject { build_stubbed(:merge_request) }
[ [
'WIP ', 'WIP:', 'WIP: ', '[WIP]', '[WIP] ', ' [WIP] WIP [WIP] WIP: WIP ', 'WIP:', 'WIP: ', '[WIP]', '[WIP] ', ' [WIP] WIP: [WIP] WIP:',
'Draft ', 'draft:', 'Draft: ', '[Draft]', '[DRAFT] ', 'Draft - ' 'draft:', 'Draft: ', '[Draft]', '[DRAFT] ', 'Draft - '
].each do |wip_prefix| ].each do |wip_prefix|
it "detects the '#{wip_prefix}' prefix" do it "detects the '#{wip_prefix}' prefix" do
subject.title = "#{wip_prefix}#{subject.title}" subject.title = "#{wip_prefix}#{subject.title}"
...@@ -1136,6 +1136,18 @@ RSpec.describe MergeRequest do ...@@ -1136,6 +1136,18 @@ RSpec.describe MergeRequest do
expect(subject.work_in_progress?).to eq true expect(subject.work_in_progress?).to eq true
end end
it 'does not detect WIP in the middle of the title' do
subject.title = 'Something with WIP in the middle'
expect(subject.work_in_progress?).to eq false
end
it 'does not detect Draft in the middle of the title' do
subject.title = 'Something with Draft in the middle'
expect(subject.work_in_progress?).to eq false
end
it "doesn't detect WIP for words starting with WIP" do it "doesn't detect WIP for words starting with WIP" do
subject.title = "Wipwap #{subject.title}" subject.title = "Wipwap #{subject.title}"
expect(subject.work_in_progress?).to eq false expect(subject.work_in_progress?).to eq false
...@@ -1155,8 +1167,8 @@ RSpec.describe MergeRequest do ...@@ -1155,8 +1167,8 @@ RSpec.describe MergeRequest do
subject { build_stubbed(:merge_request) } subject { build_stubbed(:merge_request) }
[ [
'WIP ', 'WIP:', 'WIP: ', '[WIP]', '[WIP] ', '[WIP] WIP [WIP] WIP: WIP ', 'WIP:', 'WIP: ', '[WIP]', '[WIP] ', '[WIP] WIP: [WIP] WIP:',
'Draft ', 'draft:', 'Draft: ', '[Draft]', '[DRAFT] ', 'Draft - ' 'draft:', 'Draft: ', '[Draft]', '[DRAFT] ', 'Draft - '
].each do |wip_prefix| ].each do |wip_prefix|
it "removes the '#{wip_prefix}' prefix" do it "removes the '#{wip_prefix}' prefix" do
wipless_title = subject.title wipless_title = subject.title
...@@ -2497,7 +2509,7 @@ RSpec.describe MergeRequest do ...@@ -2497,7 +2509,7 @@ RSpec.describe MergeRequest do
context 'when working in progress' do context 'when working in progress' do
before do before do
subject.title = 'WIP MR' subject.title = '[Draft] MR'
end end
it 'returns false' do it 'returns false' do
......
...@@ -43,23 +43,23 @@ RSpec.describe Issuable::CommonSystemNotesService do ...@@ -43,23 +43,23 @@ RSpec.describe Issuable::CommonSystemNotesService do
it_behaves_like 'system note creation', {}, 'changed milestone' it_behaves_like 'system note creation', {}, 'changed milestone'
end end
context 'with merge requests WIP note' do context 'with merge requests Draft note' do
context 'adding WIP note' do context 'adding Draft note' do
let(:issuable) { create(:merge_request, title: "merge request") } let(:issuable) { create(:merge_request, title: "merge request") }
it_behaves_like 'system note creation', { title: "WIP merge request" }, 'marked as a **Work In Progress**' it_behaves_like 'system note creation', { title: "Draft: merge request" }, 'marked as a **Work In Progress**'
context 'and changing title' do context 'and changing title' do
before do before do
issuable.update_attribute(:title, "WIP changed title") issuable.update_attribute(:title, "Draft: changed title")
end end
it_behaves_like 'WIP notes creation', 'marked' it_behaves_like 'draft notes creation', 'marked'
end end
end end
context 'removing WIP note' do context 'removing Draft note' do
let(:issuable) { create(:merge_request, title: "WIP merge request") } let(:issuable) { create(:merge_request, title: "Draft: merge request") }
it_behaves_like 'system note creation', { title: "merge request" }, 'unmarked as a **Work In Progress**' it_behaves_like 'system note creation', { title: "merge request" }, 'unmarked as a **Work In Progress**'
...@@ -68,7 +68,7 @@ RSpec.describe Issuable::CommonSystemNotesService do ...@@ -68,7 +68,7 @@ RSpec.describe Issuable::CommonSystemNotesService do
issuable.update_attribute(:title, "changed title") issuable.update_attribute(:title, "changed title")
end end
it_behaves_like 'WIP notes creation', 'unmarked' it_behaves_like 'draft notes creation', 'unmarked'
end end
end end
end end
......
...@@ -52,8 +52,8 @@ RSpec.describe ::SystemNotes::MergeRequestsService do ...@@ -52,8 +52,8 @@ RSpec.describe ::SystemNotes::MergeRequestsService do
end end
describe '.handle_merge_request_wip' do describe '.handle_merge_request_wip' do
context 'adding wip note' do context 'adding draft note' do
let(:noteable) { create(:merge_request, source_project: project, title: 'WIP Lorem ipsum') } let(:noteable) { create(:merge_request, source_project: project, title: 'Draft: Lorem ipsum') }
subject { service.handle_merge_request_wip } subject { service.handle_merge_request_wip }
......
...@@ -17,10 +17,10 @@ RSpec.shared_examples 'system note creation' do |update_params, note_text| ...@@ -17,10 +17,10 @@ RSpec.shared_examples 'system note creation' do |update_params, note_text|
end end
end end
RSpec.shared_examples 'WIP notes creation' do |wip_action| RSpec.shared_examples 'draft notes creation' do |wip_action|
subject { described_class.new(project, user).execute(issuable, old_labels: []) } subject { described_class.new(project, user).execute(issuable, old_labels: []) }
it 'creates WIP toggle and title change notes' do it 'creates Draft toggle and title change notes' do
expect { subject }.to change { Note.count }.from(0).to(2) expect { subject }.to change { Note.count }.from(0).to(2)
expect(Note.first.note).to match("#{wip_action} as a **Work In Progress**") expect(Note.first.note).to match("#{wip_action} as a **Work In Progress**")
......
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