Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-08-26 17:40:33 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-08-26 17:40:33 +0300
commit42dd2634e347e42dc100596a6b2588e5f163322e (patch)
tree4c1e5ceb817a5739ffc79f5a16c475fda5ad9de9
parent93fd80667dcfbacca2b41168da6fcb3f67c0899b (diff)
Add latest changes from gitlab-org/security/gitlab@15-3-stable-ee
-rw-r--r--app/models/issue.rb8
-rw-r--r--spec/models/issue_spec.rb14
2 files changed, 18 insertions, 4 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 4114467eb25..df8ee34b3c3 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -458,7 +458,13 @@ class Issue < ApplicationRecord
return to_branch_name unless project.repository.branch_exists?(to_branch_name)
start_counting_from = 2
- Uniquify.new(start_counting_from).string(-> (counter) { "#{to_branch_name}-#{counter}" }) do |suggested_branch_name|
+
+ branch_name_generator = -> (counter) do
+ suffix = counter > 5 ? SecureRandom.hex(8) : counter
+ "#{to_branch_name}-#{suffix}"
+ end
+
+ Uniquify.new(start_counting_from).string(branch_name_generator) do |suggested_branch_name|
project.repository.branch_exists?(suggested_branch_name)
end
end
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb
index 15fe6d7625a..af4c48775ec 100644
--- a/spec/models/issue_spec.rb
+++ b/spec/models/issue_spec.rb
@@ -823,14 +823,22 @@ RSpec.describe Issue do
end
describe '#to_branch_name exists ending with -index' do
- before do
+ it 'returns #to_branch_name ending with max index + 1' do
allow(repository).to receive(:branch_exists?).and_return(true)
allow(repository).to receive(:branch_exists?).with("#{subject.to_branch_name}-3").and_return(false)
- end
- it 'returns #to_branch_name ending with max index + 1' do
expect(subject.suggested_branch_name).to eq("#{subject.to_branch_name}-3")
end
+
+ context 'when branch name still exists after 5 attempts' do
+ it 'returns #to_branch_name ending with random characters' do
+ allow(repository).to receive(:branch_exists?).with(subject.to_branch_name).and_return(true)
+ allow(repository).to receive(:branch_exists?).with(/#{subject.to_branch_name}-\d/).and_return(true)
+ allow(repository).to receive(:branch_exists?).with(/#{subject.to_branch_name}-\h{8}/).and_return(false)
+
+ expect(subject.suggested_branch_name).to match(/#{subject.to_branch_name}-\h{8}/)
+ end
+ end
end
end