Commit 462f7942 authored by Sean McGivern's avatar Sean McGivern

Merge branch '27034-new-branch-length' into 'master'

Truncate recommended branch name to a sane length

See merge request gitlab-org/gitlab!18821
parents 770539d4 65e3f322
......@@ -206,7 +206,16 @@ class Issue < ApplicationRecord
if self.confidential?
"#{iid}-confidential-issue"
else
"#{iid}-#{title.parameterize}"
branch_name = "#{iid}-#{title.parameterize}"
if branch_name.length > 100
truncated_string = branch_name[0, 100]
# Delete everything dangling after the last hyphen so as not to risk
# existence of unintended words in the branch name due to mid-word split.
branch_name = truncated_string[0, truncated_string.rindex("-")]
end
branch_name
end
end
......
---
title: Truncate recommended branch name to a sane length
merge_request: 18821
author:
type: changed
......@@ -423,6 +423,19 @@ describe Issue do
issue = create(:issue, title: 'testing-issue', confidential: true)
expect(issue.to_branch_name).to match /confidential-issue\z/
end
context 'issue title longer than 100 characters' do
let(:issue) { create(:issue, iid: 999, title: 'Lorem ipsum dolor sit amet consectetur adipiscing elit Mauris sit amet ipsum id lacus custom fringilla convallis') }
it "truncates branch name to at most 100 characters" do
expect(issue.to_branch_name.length).to be <= 100
end
it "truncates dangling parts of the branch name" do
# 100 characters would've got us "999-lorem...lacus-custom-fri".
expect(issue.to_branch_name).to eq("999-lorem-ipsum-dolor-sit-amet-consectetur-adipiscing-elit-mauris-sit-amet-ipsum-id-lacus-custom")
end
end
end
describe '#can_be_worked_on?' 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