Skip to content
Snippets Groups Projects
Commit 926002fd authored by Stan Hu's avatar Stan Hu
Browse files

Fix Error 500s creating merge requests with external issue tracker

When JIRA or Redmine were enabled and the branch name did not match the
matching regular expression, the `issue_iid` would be `nil`, preventing
users from creating merge requests.

Closes #43193
parent 498ade48
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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
 
Loading
Loading
Loading
Loading
@@ -286,33 +286,43 @@ 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
 
it 'sets the title to the humanized branch title' do
expect(merge_request.title).to eq('Resolve EXMPL-12345')
end
context 'branch does not start with JIRA-formatted external issue IID' do
let(:source_branch) { 'test-branch' }
 
it 'appends the closes text' do
expect(merge_request.description).to eq('Closes EXMPL-12345')
it 'sets the title to the humanized branch title' do
expect(merge_request.title).to eq('Test branch')
end
end
 
context 'followed by hyphenated text' do
let(:source_branch) { 'EXMPL-12345-fix-issue' }
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 "Fix issue"')
expect(merge_request.title).to eq('Resolve EXMPL-12345')
end
 
it 'appends the closes text' do
expect(merge_request.description).to eq('Closes EXMPL-12345')
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
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment