diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-18 18:09:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-18 18:09:45 +0300 |
commit | aaf59610548d9b0fd01acfd50e831cbe519ecba2 (patch) | |
tree | b6505abedcd965ebae5118b504b185b63129dc4c /lib | |
parent | 1363ca12f1f07c634647cf55c4c16b7401098673 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/helpers/custom_validators.rb | 30 | ||||
-rw-r--r-- | lib/gitlab/graphql/docs/helper.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/graphql/docs/renderer.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/import_export/relation_tree_restorer.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/metrics/exporter/base_exporter.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/set_cache.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/usage_data.rb | 2 | ||||
-rw-r--r-- | lib/tasks/gitlab/graphql.rake | 1 |
8 files changed, 40 insertions, 5 deletions
diff --git a/lib/api/helpers/custom_validators.rb b/lib/api/helpers/custom_validators.rb index 4c15c1d01cd..b4523d7b436 100644 --- a/lib/api/helpers/custom_validators.rb +++ b/lib/api/helpers/custom_validators.rb @@ -56,6 +56,35 @@ module API message: "should be an array, 'None' or 'Any'" end end + + class GitRef < Grape::Validations::Base + # There are few checks that a Git reference should pass through to be valid reference. + # The link contains some rules that have been added to this validator. + # https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html + # We have skipped some checks that are optional and can be skipped for exception. + # We also check for control characters, More info on ctrl chars - https://ruby-doc.org/core-2.7.0/Regexp.html#class-Regexp-label-Character+Classes + INVALID_CHARS = Regexp.union('..', '\\', '@', '@{', ' ', '~', '^', ':', '*', '?', '[', /[[:cntrl:]]/).freeze + GIT_REF_LENGTH = (1..1024).freeze + + def validate_param!(attr_name, params) + revision = params[attr_name] + + return unless invalid_character?(revision) + + raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], + message: 'should be a valid reference path' + end + + private + + def invalid_character?(revision) + revision.nil? || + revision.start_with?('-') || + revision.end_with?('.') || + GIT_REF_LENGTH.exclude?(revision.length) || + INVALID_CHARS.match?(revision) + end + end end end end @@ -65,3 +94,4 @@ Grape::Validations.register_validator(:git_sha, ::API::Helpers::CustomValidators Grape::Validations.register_validator(:absence, ::API::Helpers::CustomValidators::Absence) Grape::Validations.register_validator(:integer_none_any, ::API::Helpers::CustomValidators::IntegerNoneAny) Grape::Validations.register_validator(:array_none_any, ::API::Helpers::CustomValidators::ArrayNoneAny) +Grape::Validations.register_validator(:git_ref, ::API::Helpers::CustomValidators::GitRef) diff --git a/lib/gitlab/graphql/docs/helper.rb b/lib/gitlab/graphql/docs/helper.rb index 0dd28b32511..46f253e08e8 100644 --- a/lib/gitlab/graphql/docs/helper.rb +++ b/lib/gitlab/graphql/docs/helper.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -return if Rails.env.production? - module Gitlab module Graphql module Docs diff --git a/lib/gitlab/graphql/docs/renderer.rb b/lib/gitlab/graphql/docs/renderer.rb index 6abd56c89c6..fe950de7d13 100644 --- a/lib/gitlab/graphql/docs/renderer.rb +++ b/lib/gitlab/graphql/docs/renderer.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -return if Rails.env.production? +require 'gitlab/graphql/docs/helper' module Gitlab module Graphql diff --git a/lib/gitlab/import_export/relation_tree_restorer.rb b/lib/gitlab/import_export/relation_tree_restorer.rb index 466cb03862e..88cf346d8ec 100644 --- a/lib/gitlab/import_export/relation_tree_restorer.rb +++ b/lib/gitlab/import_export/relation_tree_restorer.rb @@ -28,7 +28,7 @@ module Gitlab update_params! bulk_inserts_enabled = @importable.class == ::Project && - Feature.enabled?(:import_bulk_inserts, @importable.group) + Feature.enabled?(:import_bulk_inserts, @importable.group, default_enabled: true) BulkInsertableAssociations.with_bulk_insert(enabled: bulk_inserts_enabled) do fix_ci_pipelines_not_sorted_on_legacy_project_json! create_relations! diff --git a/lib/gitlab/metrics/exporter/base_exporter.rb b/lib/gitlab/metrics/exporter/base_exporter.rb index 7111835c85a..ff8b8bf2237 100644 --- a/lib/gitlab/metrics/exporter/base_exporter.rb +++ b/lib/gitlab/metrics/exporter/base_exporter.rb @@ -1,5 +1,8 @@ # frozen_string_literal: true +require 'webrick' +require 'prometheus/client/rack/exporter' + module Gitlab module Metrics module Exporter diff --git a/lib/gitlab/set_cache.rb b/lib/gitlab/set_cache.rb index 2e72855824a..d1151a431bb 100644 --- a/lib/gitlab/set_cache.rb +++ b/lib/gitlab/set_cache.rb @@ -14,7 +14,10 @@ module Gitlab "#{key}:set" end + # Returns the number of keys deleted by Redis def expire(*keys) + return 0 if keys.empty? + with do |redis| keys = keys.map { |key| cache_key(key) } unlink_or_delete(redis, keys) diff --git a/lib/gitlab/usage_data.rb b/lib/gitlab/usage_data.rb index b9cd4d74914..4457dffd603 100644 --- a/lib/gitlab/usage_data.rb +++ b/lib/gitlab/usage_data.rb @@ -98,7 +98,7 @@ module Gitlab projects_imported_from_github: count(Project.where(import_type: 'github')), projects_with_repositories_enabled: count(ProjectFeature.where('repository_access_level > ?', ProjectFeature::DISABLED)), projects_with_error_tracking_enabled: count(::ErrorTracking::ProjectErrorTrackingSetting.where(enabled: true)), - projects_with_alerts_service_enabled: count(AlertsService.active, batch: false), + projects_with_alerts_service_enabled: count(AlertsService.active), protected_branches: count(ProtectedBranch), releases: count(Release), remote_mirrors: count(RemoteMirror), diff --git a/lib/tasks/gitlab/graphql.rake b/lib/tasks/gitlab/graphql.rake index 5a583183924..4e7d462e850 100644 --- a/lib/tasks/gitlab/graphql.rake +++ b/lib/tasks/gitlab/graphql.rake @@ -3,6 +3,7 @@ return if Rails.env.production? require 'graphql/rake_task' +require 'gitlab/graphql/docs/renderer' namespace :gitlab do OUTPUT_DIR = Rails.root.join("doc/api/graphql/reference") |