Commit 65e3f322 authored by Balasankar "Balu" C's avatar Balasankar "Balu" C

Remove dangling text from suggested branch name

Signed-off-by: default avatarBalasankar "Balu" C <balasankar@gitlab.com>
parent 2bacfda2
......@@ -206,7 +206,16 @@ class Issue < ApplicationRecord
if self.confidential?
"#{iid}-confidential-issue"
else
"#{iid}-#{title.parameterize}"[0, 99]
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
......
......@@ -425,10 +425,15 @@ describe Issue do
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 fringilla convallis') }
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 title part of branch name to 100 characters" do
expect(issue.to_branch_name).to eq("999-lorem-ipsum-dolor-sit-amet-consectetur-adipiscing-elit-mauris-sit-amet-ipsum-id-lacus-fringilla")
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
......
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