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-10-21 00:09:04 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-10-21 00:09:04 +0300
commit40e8ba2fc8ac6c3695d7f297ff4143518615a3f9 (patch)
treeed39c719819b3f2a5e6216f2221cb31bbac3f62c /app/validators
parenta3764262c04bafcd6a54aff635541d73a8a630fd (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/validators')
-rw-r--r--app/validators/branch_filter_validator.rb37
-rw-r--r--app/validators/web_hooks/wildcard_branch_filter_validator.rb34
2 files changed, 34 insertions, 37 deletions
diff --git a/app/validators/branch_filter_validator.rb b/app/validators/branch_filter_validator.rb
deleted file mode 100644
index 89d6343a9a4..00000000000
--- a/app/validators/branch_filter_validator.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-# frozen_string_literal: true
-
-# BranchFilterValidator
-#
-# Custom validator for branch names. Squishes whitespace and ignores empty
-# string. This only checks that a string is a valid git branch name. It does
-# not check whether a branch already exists.
-#
-# Example:
-#
-# class Webhook < ActiveRecord::Base
-# validates :push_events_branch_filter, branch_name: true
-# end
-#
-class BranchFilterValidator < ActiveModel::EachValidator
- def validate_each(record, attribute, value)
- value.squish! unless value.nil?
-
- if value.present?
- value_without_wildcards = value.tr('*', 'x')
-
- unless Gitlab::GitRefValidator.validate(value_without_wildcards)
- record.errors.add(attribute, "is not a valid branch name")
- end
-
- unless value.length <= 4000
- record.errors.add(attribute, "is longer than the allowed length of 4000 characters.")
- end
- end
- end
-
- private
-
- def contains_wildcard?(value)
- value.include?('*')
- end
-end
diff --git a/app/validators/web_hooks/wildcard_branch_filter_validator.rb b/app/validators/web_hooks/wildcard_branch_filter_validator.rb
new file mode 100644
index 00000000000..12ec78f05de
--- /dev/null
+++ b/app/validators/web_hooks/wildcard_branch_filter_validator.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+# WildcardBranchFilterValidator
+#
+# Custom validator for wildcard branch filter. Squishes whitespace and ignores
+# empty string. This only checks that a string is a valid wildcard git branch
+# like "feature/login" and "feature/*". It doesn't check whether a branch already
+# exists.
+#
+# Example:
+#
+# class Webhook < ActiveRecord::Base
+# validates :push_events_branch_filter, "web_hooks/wildcard_branch_filter": true
+# end
+#
+module WebHooks
+ class WildcardBranchFilterValidator < ActiveModel::EachValidator
+ def validate_each(record, attribute, value)
+ value.squish! unless value.nil?
+
+ return unless value.present?
+
+ value_without_wildcards = value.tr('*', 'x')
+
+ unless Gitlab::GitRefValidator.validate(value_without_wildcards)
+ record.errors.add(attribute, "is not a valid branch name")
+ end
+
+ return if value.length <= 4000
+
+ record.errors.add(attribute, "is longer than the allowed length of 4000 characters.")
+ end
+ end
+end