Commit 72e32409 authored by Kerri Miller's avatar Kerri Miller

Merge branch '341567-align-fronted-and-backend-draft-regexes' into 'master'

Align front/backend Draft MR regexes

See merge request gitlab-org/gitlab!71839
parents 4d4dd281 8f424be7
...@@ -50,20 +50,16 @@ export default class IssuableForm { ...@@ -50,20 +50,16 @@ export default class IssuableForm {
this.renderWipExplanation = this.renderWipExplanation.bind(this); this.renderWipExplanation = this.renderWipExplanation.bind(this);
this.resetAutosave = this.resetAutosave.bind(this); this.resetAutosave = this.resetAutosave.bind(this);
this.handleSubmit = this.handleSubmit.bind(this); this.handleSubmit = this.handleSubmit.bind(this);
/* eslint-disable @gitlab/require-i18n-strings */
// prettier-ignore // prettier-ignore
this.draftRegex = new RegExp( this.draftRegex = new RegExp(
'^\\s*(' + // Line start, then any amount of leading whitespace '^\\s*(' + // Line start, then any amount of leading whitespace
'draft\\s-\\s' + // Draft_-_ where "_" are *exactly* one whitespace
'|\\[draft\\]\\s*' + // [Draft] and any following whitespace '|\\[draft\\]\\s*' + // [Draft] and any following whitespace
'|draft:\\s*' + // Draft: and any following whitespace '|draft:\\s*' + // Draft: and any following whitespace
'|draft\\s+' + // Draft_ where "_" is at least one whitespace
'|\\(draft\\)\\s*' + // (Draft) and any following whitespace '|\\(draft\\)\\s*' + // (Draft) and any following whitespace
')+' + // At least one repeated match of the preceding parenthetical ')+' + // At least one repeated match of the preceding parenthetical
'\\s*', // Any amount of trailing whitespace '\\s*', // Any amount of trailing whitespace
'i', // Match any case(s) 'i', // Match any case(s)
); );
/* eslint-enable @gitlab/require-i18n-strings */
this.gfmAutoComplete = new GfmAutoComplete( this.gfmAutoComplete = new GfmAutoComplete(
gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources, gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources,
......
...@@ -409,7 +409,7 @@ module Gitlab ...@@ -409,7 +409,7 @@ module Gitlab
end end
def merge_request_draft def merge_request_draft
/\A(?i)(\[draft\]|\(draft\)|draft:|draft\s\-\s|draft\z)/ /\A(?i)(\[draft\]|\(draft\)|draft:)/
end end
def issue def issue
......
...@@ -20,16 +20,13 @@ describe('IssuableForm', () => { ...@@ -20,16 +20,13 @@ describe('IssuableForm', () => {
describe('removeWip', () => { describe('removeWip', () => {
it.each` it.each`
prefix prefix
${'drAft '}
${'draFT: '} ${'draFT: '}
${' [DRaft] '} ${' [DRaft] '}
${'drAft:'} ${'drAft:'}
${'[draFT]'} ${'[draFT]'}
${' dRaFt - '}
${'dRaFt - '}
${'(draft) '} ${'(draft) '}
${' (DrafT)'} ${' (DrafT)'}
${'draft draft - draft: [draft] (draft)'} ${'draft: [draft] (draft)'}
`('removes "$prefix" from the beginning of the title', ({ prefix }) => { `('removes "$prefix" from the beginning of the title', ({ prefix }) => {
instance.titleField.val(`${prefix}The Issuable's Title Value`); instance.titleField.val(`${prefix}The Issuable's Title Value`);
......
...@@ -799,7 +799,7 @@ eos ...@@ -799,7 +799,7 @@ eos
describe '#work_in_progress?' do describe '#work_in_progress?' do
[ [
'squash! ', 'fixup! ', 'wip: ', 'WIP: ', '[WIP] ', 'squash! ', 'fixup! ', 'wip: ', 'WIP: ', '[WIP] ',
'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
commit.message = "#{wip_prefix}#{commit.message}" commit.message = "#{wip_prefix}#{commit.message}"
...@@ -814,22 +814,18 @@ eos ...@@ -814,22 +814,18 @@ eos
expect(commit).to be_work_in_progress expect(commit).to be_work_in_progress
end end
it "detects WIP for a commit just saying 'draft'" do it "does not detect WIP for a commit just saying 'draft'" do
commit.message = "draft" commit.message = "draft"
expect(commit).to be_work_in_progress
end
it "doesn't detect WIP for a commit that begins with 'FIXUP! '" do
commit.message = "FIXUP! #{commit.message}"
expect(commit).not_to be_work_in_progress expect(commit).not_to be_work_in_progress
end end
it "doesn't detect WIP for words starting with WIP" do ["FIXUP!", "Draft - ", "Wipeout"].each do |draft_prefix|
commit.message = "Wipout #{commit.message}" it "doesn't detect '#{draft_prefix}' at the start of the title as a draft" do
commit.message = "#{draft_prefix} #{commit.message}"
expect(commit).not_to be_work_in_progress expect(commit).not_to be_work_in_progress
end
end end
end end
......
...@@ -1348,7 +1348,7 @@ RSpec.describe MergeRequest, factory_default: :keep do ...@@ -1348,7 +1348,7 @@ RSpec.describe MergeRequest, factory_default: :keep do
[ [
'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] '
].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}"
...@@ -1359,7 +1359,7 @@ RSpec.describe MergeRequest, factory_default: :keep do ...@@ -1359,7 +1359,7 @@ RSpec.describe MergeRequest, factory_default: :keep do
[ [
"WIP ", "(WIP)", "WIP ", "(WIP)",
"draft", "Draft" "draft", "Draft", "Draft -", "draft - ", "Draft ", "draft "
].each do |draft_prefix| ].each do |draft_prefix|
it "doesn't detect '#{draft_prefix}' at the start of the title as a draft" do it "doesn't detect '#{draft_prefix}' at the start of the title as a draft" do
subject.title = "#{draft_prefix}#{subject.title}" subject.title = "#{draft_prefix}#{subject.title}"
...@@ -1374,10 +1374,10 @@ RSpec.describe MergeRequest, factory_default: :keep do ...@@ -1374,10 +1374,10 @@ RSpec.describe MergeRequest, factory_default: :keep do
expect(subject.work_in_progress?).to eq true expect(subject.work_in_progress?).to eq true
end end
it "detects merge request title just saying 'draft'" do it "does not detect merge request title just saying 'draft'" do
subject.title = "draft" subject.title = "draft"
expect(subject.work_in_progress?).to eq true expect(subject.work_in_progress?).to eq false
end end
it 'does not detect WIP in the middle of the title' do it 'does not detect WIP in the middle of the title' do
...@@ -1439,7 +1439,7 @@ RSpec.describe MergeRequest, factory_default: :keep do ...@@ -1439,7 +1439,7 @@ RSpec.describe MergeRequest, factory_default: :keep do
[ [
'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] '
].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
......
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