diff options
Diffstat (limited to 'app/validators/git_environment_variables_validator.rb')
-rw-r--r-- | app/validators/git_environment_variables_validator.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/app/validators/git_environment_variables_validator.rb b/app/validators/git_environment_variables_validator.rb new file mode 100644 index 00000000000..92041e0a773 --- /dev/null +++ b/app/validators/git_environment_variables_validator.rb @@ -0,0 +1,13 @@ +class GitEnvironmentVariablesValidator < ActiveModel::EachValidator + def validate_each(record, attribute, env) + variables_to_validate = %w(GIT_OBJECT_DIRECTORY GIT_ALTERNATE_OBJECT_DIRECTORIES) + + variables_to_validate.each do |variable_name| + variable_value = env[variable_name] + + if variable_value.present? && !(variable_value =~ /^#{record.project.repository.path_to_repo}/) + record.errors.add(attribute, "The #{variable_name} variable must start with the project repo path") + end + end + end +end |