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
merge_request.title = "Resolve \"#{issue.title}\"" if issue.is_a?(Issue)
unless merge_request.title
branch_title = source_branch.downcase.remove(issue_iid.downcase).titleize.humanize
return if merge_request.title.present?
if issue_iid.present?
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
......
......@@ -286,15 +286,24 @@ describe MergeRequests::BuildService do
end
end
context 'branch starts with JIRA-formatted external issue IID' do
let(:source_branch) { 'EXMPL-12345' }
describe 'with JIRA enabled' do
before do
allow(project).to receive(:external_issue_tracker).and_return(true)
allow(project).to receive(:issues_enabled?).and_return(false)
allow(project).to receive(:external_issue_reference_pattern).and_return(IssueTrackerService.reference_pattern)
end
context 'branch does not start with JIRA-formatted external issue IID' do
let(:source_branch) { 'test-branch' }
it 'sets the title to the humanized branch title' do
expect(merge_request.title).to eq('Test branch')
end
end
context 'branch starts with JIRA-formatted external issue IID' do
let(:source_branch) { 'EXMPL-12345' }
it 'sets the title to the humanized branch title' do
expect(merge_request.title).to eq('Resolve EXMPL-12345')
end
......@@ -316,6 +325,7 @@ describe MergeRequests::BuildService do
end
end
end
end
context 'source branch does not exist' do
before do
......
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