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