Commit 754d1ec4 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'sh-fix-issue-43193' into 'master'

Fix Error 500s creating merge requests with external issue tracker

Closes #43193

See merge request gitlab-org/gitlab-ce!17073
parents 8925671a 926002fd
...@@ -160,10 +160,12 @@ module MergeRequests ...@@ -160,10 +160,12 @@ module MergeRequests
merge_request.title = "Resolve \"#{issue.title}\"" if issue.is_a?(Issue) merge_request.title = "Resolve \"#{issue.title}\"" if issue.is_a?(Issue)
unless merge_request.title return if merge_request.title.present?
branch_title = source_branch.downcase.remove(issue_iid.downcase).titleize.humanize
if issue_iid.present?
merge_request.title = "Resolve #{issue_iid}" merge_request.title = "Resolve #{issue_iid}"
merge_request.title += " \"#{branch_title}\"" unless branch_title.empty? branch_title = source_branch.downcase.remove(issue_iid.downcase).titleize.humanize
merge_request.title += " \"#{branch_title}\"" if branch_title.present?
end end
end end
......
...@@ -286,33 +286,43 @@ describe MergeRequests::BuildService do ...@@ -286,33 +286,43 @@ describe MergeRequests::BuildService do
end end
end end
context 'branch starts with JIRA-formatted external issue IID' do describe 'with JIRA enabled' do
let(:source_branch) { 'EXMPL-12345' }
before do before do
allow(project).to receive(:external_issue_tracker).and_return(true) allow(project).to receive(:external_issue_tracker).and_return(true)
allow(project).to receive(:issues_enabled?).and_return(false) allow(project).to receive(:issues_enabled?).and_return(false)
allow(project).to receive(:external_issue_reference_pattern).and_return(IssueTrackerService.reference_pattern) allow(project).to receive(:external_issue_reference_pattern).and_return(IssueTrackerService.reference_pattern)
end end
it 'sets the title to the humanized branch title' do context 'branch does not start with JIRA-formatted external issue IID' do
expect(merge_request.title).to eq('Resolve EXMPL-12345') let(:source_branch) { 'test-branch' }
end
it 'appends the closes text' do it 'sets the title to the humanized branch title' do
expect(merge_request.description).to eq('Closes EXMPL-12345') expect(merge_request.title).to eq('Test branch')
end
end end
context 'followed by hyphenated text' do context 'branch starts with JIRA-formatted external issue IID' do
let(:source_branch) { 'EXMPL-12345-fix-issue' } let(:source_branch) { 'EXMPL-12345' }
it 'sets the title to the humanized branch title' do it 'sets the title to the humanized branch title' do
expect(merge_request.title).to eq('Resolve EXMPL-12345 "Fix issue"') expect(merge_request.title).to eq('Resolve EXMPL-12345')
end end
it 'appends the closes text' do it 'appends the closes text' do
expect(merge_request.description).to eq('Closes EXMPL-12345') expect(merge_request.description).to eq('Closes EXMPL-12345')
end end
context 'followed by hyphenated text' do
let(:source_branch) { 'EXMPL-12345-fix-issue' }
it 'sets the title to the humanized branch title' do
expect(merge_request.title).to eq('Resolve EXMPL-12345 "Fix issue"')
end
it 'appends the closes text' do
expect(merge_request.description).to eq('Closes EXMPL-12345')
end
end
end end
end end
end end
......
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