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
end
def merge_request_wip
/(?i)(\[WIP\]\s*|WIP:\s*|WIP\s+|WIP$)/
/(?i)(\[WIP\]\s*|WIP:\s*|WIP$)/
end
def merge_request_draft
/(?i)(\[draft\]|\(draft\)|draft:|draft\s\-\s|draft\s|draft$)/
/(?i)(\[draft\]|\(draft\)|draft:|draft\s\-\s|draft$)/
end
def issue
......
......@@ -1114,8 +1114,8 @@ RSpec.describe MergeRequest do
subject { build_stubbed(:merge_request) }
[
'WIP ', 'WIP:', 'WIP: ', '[WIP]', '[WIP] ', ' [WIP] WIP [WIP] WIP: WIP ',
'Draft ', 'draft:', 'Draft: ', '[Draft]', '[DRAFT] ', 'Draft - '
'WIP:', 'WIP: ', '[WIP]', '[WIP] ', ' [WIP] WIP: [WIP] WIP:',
'draft:', 'Draft: ', '[Draft]', '[DRAFT] ', 'Draft - '
].each do |wip_prefix|
it "detects the '#{wip_prefix}' prefix" do
subject.title = "#{wip_prefix}#{subject.title}"
......@@ -1136,6 +1136,18 @@ RSpec.describe MergeRequest do
expect(subject.work_in_progress?).to eq true
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
subject.title = "Wipwap #{subject.title}"
expect(subject.work_in_progress?).to eq false
......@@ -1155,8 +1167,8 @@ RSpec.describe MergeRequest do
subject { build_stubbed(:merge_request) }
[
'WIP ', 'WIP:', 'WIP: ', '[WIP]', '[WIP] ', '[WIP] WIP [WIP] WIP: WIP ',
'Draft ', 'draft:', 'Draft: ', '[Draft]', '[DRAFT] ', 'Draft - '
'WIP:', 'WIP: ', '[WIP]', '[WIP] ', '[WIP] WIP: [WIP] WIP:',
'draft:', 'Draft: ', '[Draft]', '[DRAFT] ', 'Draft - '
].each do |wip_prefix|
it "removes the '#{wip_prefix}' prefix" do
wipless_title = subject.title
......@@ -2497,7 +2509,7 @@ RSpec.describe MergeRequest do
context 'when working in progress' do
before do
subject.title = 'WIP MR'
subject.title = '[Draft] MR'
end
it 'returns false' do
......
......@@ -43,23 +43,23 @@ RSpec.describe Issuable::CommonSystemNotesService do
it_behaves_like 'system note creation', {}, 'changed milestone'
end
context 'with merge requests WIP note' do
context 'adding WIP note' do
context 'with merge requests Draft note' do
context 'adding Draft note' do
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
before do
issuable.update_attribute(:title, "WIP changed title")
issuable.update_attribute(:title, "Draft: changed title")
end
it_behaves_like 'WIP notes creation', 'marked'
it_behaves_like 'draft notes creation', 'marked'
end
end
context 'removing WIP note' do
let(:issuable) { create(:merge_request, title: "WIP merge request") }
context 'removing Draft note' do
let(:issuable) { create(:merge_request, title: "Draft: merge request") }
it_behaves_like 'system note creation', { title: "merge request" }, 'unmarked as a **Work In Progress**'
......@@ -68,7 +68,7 @@ RSpec.describe Issuable::CommonSystemNotesService do
issuable.update_attribute(:title, "changed title")
end
it_behaves_like 'WIP notes creation', 'unmarked'
it_behaves_like 'draft notes creation', 'unmarked'
end
end
end
......
......@@ -52,8 +52,8 @@ RSpec.describe ::SystemNotes::MergeRequestsService do
end
describe '.handle_merge_request_wip' do
context 'adding wip note' do
let(:noteable) { create(:merge_request, source_project: project, title: 'WIP Lorem ipsum') }
context 'adding draft note' do
let(:noteable) { create(:merge_request, source_project: project, title: 'Draft: Lorem ipsum') }
subject { service.handle_merge_request_wip }
......
......@@ -17,10 +17,10 @@ RSpec.shared_examples 'system note creation' do |update_params, note_text|
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: []) }
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(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