diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-31 18:09:11 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-31 18:09:11 +0000 |
commit | 0434f38ef1dce4fe640fe1e4542235746ceb943c (patch) | |
tree | 3affe5902c9da74441dfbf5069f76c023b5cd03a /lib | |
parent | c27acb1d376f7127cd33eadcc8f5683ed55262bc (diff) | |
download | gitlab-ce-0434f38ef1dce4fe640fe1e4542235746ceb943c.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/entities.rb | 46 | ||||
-rw-r--r-- | lib/api/entities/commit.rb | 14 | ||||
-rw-r--r-- | lib/api/entities/commit_detail.rb | 22 | ||||
-rw-r--r-- | lib/api/entities/commit_signature.rb | 12 | ||||
-rw-r--r-- | lib/api/entities/commit_stats.rb | 9 | ||||
-rw-r--r-- | lib/api/entities/commit_with_stats.rb | 9 | ||||
-rw-r--r-- | lib/api/entities/diff_refs.rb | 9 | ||||
-rw-r--r-- | lib/gitlab/alerting/notification_payload_parser.rb | 75 | ||||
-rw-r--r-- | lib/gitlab/database/grant.rb | 11 | ||||
-rw-r--r-- | lib/gitlab/database_importers/common_metrics.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/database_importers/common_metrics/prometheus_metric_enums.rb | 9 |
11 files changed, 159 insertions, 59 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 681bb98b155..451d7c9edca 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -128,51 +128,6 @@ module API end end - class DiffRefs < Grape::Entity - expose :base_sha, :head_sha, :start_sha - end - - class Commit < Grape::Entity - expose :id, :short_id, :created_at - expose :parent_ids - expose :full_title, as: :title - expose :safe_message, as: :message - expose :author_name, :author_email, :authored_date - expose :committer_name, :committer_email, :committed_date - end - - class CommitStats < Grape::Entity - expose :additions, :deletions, :total - end - - class CommitWithStats < Commit - expose :stats, using: Entities::CommitStats - end - - class CommitDetail < Commit - expose :stats, using: Entities::CommitStats, if: :stats - expose :status - expose :project_id - - expose :last_pipeline do |commit, options| - pipeline = commit.last_pipeline if can_read_pipeline? - ::API::Entities::PipelineBasic.represent(pipeline, options) - end - - private - - def can_read_pipeline? - Ability.allowed?(options[:current_user], :read_pipeline, object.last_pipeline) - end - end - - class CommitSignature < Grape::Entity - expose :gpg_key_id - expose :gpg_key_primary_keyid, :gpg_key_user_name, :gpg_key_user_email - expose :verification_status - expose :gpg_key_subkey_id - end - class BasicRef < Grape::Entity expose :type, :name end @@ -1101,6 +1056,7 @@ module API expose :evidence_file_path, expose_nil: false, if: ->(_, _) { can_download_code? } end expose :_links do + expose :self_url, as: :self, expose_nil: false expose :merge_requests_url, expose_nil: false expose :issues_url, expose_nil: false expose :edit_url, expose_nil: false diff --git a/lib/api/entities/commit.rb b/lib/api/entities/commit.rb new file mode 100644 index 00000000000..7ce97c2c3d8 --- /dev/null +++ b/lib/api/entities/commit.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module API + module Entities + class Commit < Grape::Entity + expose :id, :short_id, :created_at + expose :parent_ids + expose :full_title, as: :title + expose :safe_message, as: :message + expose :author_name, :author_email, :authored_date + expose :committer_name, :committer_email, :committed_date + end + end +end diff --git a/lib/api/entities/commit_detail.rb b/lib/api/entities/commit_detail.rb new file mode 100644 index 00000000000..22424b38bb9 --- /dev/null +++ b/lib/api/entities/commit_detail.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module API + module Entities + class CommitDetail < Commit + expose :stats, using: Entities::CommitStats, if: :stats + expose :status + expose :project_id + + expose :last_pipeline do |commit, options| + pipeline = commit.last_pipeline if can_read_pipeline? + ::API::Entities::PipelineBasic.represent(pipeline, options) + end + + private + + def can_read_pipeline? + Ability.allowed?(options[:current_user], :read_pipeline, object.last_pipeline) + end + end + end +end diff --git a/lib/api/entities/commit_signature.rb b/lib/api/entities/commit_signature.rb new file mode 100644 index 00000000000..8e86d4c1aa6 --- /dev/null +++ b/lib/api/entities/commit_signature.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module API + module Entities + class CommitSignature < Grape::Entity + expose :gpg_key_id + expose :gpg_key_primary_keyid, :gpg_key_user_name, :gpg_key_user_email + expose :verification_status + expose :gpg_key_subkey_id + end + end +end diff --git a/lib/api/entities/commit_stats.rb b/lib/api/entities/commit_stats.rb new file mode 100644 index 00000000000..d9ba99c8eb0 --- /dev/null +++ b/lib/api/entities/commit_stats.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module API + module Entities + class CommitStats < Grape::Entity + expose :additions, :deletions, :total + end + end +end diff --git a/lib/api/entities/commit_with_stats.rb b/lib/api/entities/commit_with_stats.rb new file mode 100644 index 00000000000..8a992586e22 --- /dev/null +++ b/lib/api/entities/commit_with_stats.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module API + module Entities + class CommitWithStats < Commit + expose :stats, using: Entities::CommitStats + end + end +end diff --git a/lib/api/entities/diff_refs.rb b/lib/api/entities/diff_refs.rb new file mode 100644 index 00000000000..8772fa2334f --- /dev/null +++ b/lib/api/entities/diff_refs.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module API + module Entities + class DiffRefs < Grape::Entity + expose :base_sha, :head_sha, :start_sha + end + end +end diff --git a/lib/gitlab/alerting/notification_payload_parser.rb b/lib/gitlab/alerting/notification_payload_parser.rb new file mode 100644 index 00000000000..a54bb44d66a --- /dev/null +++ b/lib/gitlab/alerting/notification_payload_parser.rb @@ -0,0 +1,75 @@ +# frozen_string_literal: true + +module Gitlab + module Alerting + class NotificationPayloadParser + BadPayloadError = Class.new(StandardError) + + DEFAULT_TITLE = 'New: Incident' + + def initialize(payload) + @payload = payload.to_h.with_indifferent_access + end + + def self.call(payload) + new(payload).call + end + + def call + { + 'annotations' => annotations, + 'startsAt' => starts_at + }.compact + end + + private + + attr_reader :payload + + def title + payload[:title].presence || DEFAULT_TITLE + end + + def annotations + primary_params + .reverse_merge(flatten_secondary_params) + .transform_values(&:presence) + .compact + end + + def primary_params + { + 'title' => title, + 'description' => payload[:description], + 'monitoring_tool' => payload[:monitoring_tool], + 'service' => payload[:service], + 'hosts' => hosts.presence + } + end + + def hosts + Array(payload[:hosts]).reject(&:blank?) + end + + def current_time + Time.current.change(usec: 0).rfc3339 + end + + def starts_at + Time.parse(payload[:start_time].to_s).rfc3339 + rescue ArgumentError + current_time + end + + def secondary_params + payload.except(:start_time) + end + + def flatten_secondary_params + Gitlab::Utils::SafeInlineHash.merge_keys!(secondary_params) + rescue ArgumentError + raise BadPayloadError, 'The payload is too big' + end + end + end +end diff --git a/lib/gitlab/database/grant.rb b/lib/gitlab/database/grant.rb index 1f47f320a29..7774dd9fffe 100644 --- a/lib/gitlab/database/grant.rb +++ b/lib/gitlab/database/grant.rb @@ -3,23 +3,18 @@ module Gitlab module Database # Model that can be used for querying permissions of a SQL user. - class Grant < ActiveRecord::Base - include FromUnion - - self.table_name = 'information_schema.role_table_grants' - + class Grant # Returns true if the current user can create and execute triggers on the # given table. def self.create_and_execute_trigger?(table) # We _must not_ use quote_table_name as this will produce double # quotes on PostgreSQL and for "has_table_privilege" we need single # quotes. + connection = ActiveRecord::Base.connection quoted_table = connection.quote(table) begin - from(nil) - .pluck(Arel.sql("has_table_privilege(#{quoted_table}, 'TRIGGER')")) - .first + connection.select_one("SELECT has_table_privilege(#{quoted_table}, 'TRIGGER')").present? rescue ActiveRecord::StatementInvalid # This error is raised when using a non-existing table name. In this # case we just want to return false as a user technically can't diff --git a/lib/gitlab/database_importers/common_metrics.rb b/lib/gitlab/database_importers/common_metrics.rb index b9d320f2fc7..f964ae8a275 100644 --- a/lib/gitlab/database_importers/common_metrics.rb +++ b/lib/gitlab/database_importers/common_metrics.rb @@ -6,5 +6,3 @@ module Gitlab end end end - -Gitlab::DatabaseImporters::CommonMetrics.prepend_if_ee('EE::Gitlab::DatabaseImporters::CommonMetrics') diff --git a/lib/gitlab/database_importers/common_metrics/prometheus_metric_enums.rb b/lib/gitlab/database_importers/common_metrics/prometheus_metric_enums.rb index 409a1252da1..fb0fcc5a93b 100644 --- a/lib/gitlab/database_importers/common_metrics/prometheus_metric_enums.rb +++ b/lib/gitlab/database_importers/common_metrics/prometheus_metric_enums.rb @@ -17,7 +17,9 @@ module Gitlab # custom groups business: 0, response: 1, - system: 2 + system: 2, + + cluster_health: -100 } end @@ -31,12 +33,11 @@ module Gitlab ha_proxy: _('Response metrics (HA Proxy)'), aws_elb: _('Response metrics (AWS ELB)'), nginx: _('Response metrics (NGINX)'), - kubernetes: _('System metrics (Kubernetes)') + kubernetes: _('System metrics (Kubernetes)'), + cluster_health: _('Cluster Health') } end end end end end - -::Gitlab::DatabaseImporters::CommonMetrics::PrometheusMetricEnums.prepend_if_ee('EE::Gitlab::DatabaseImporters::CommonMetrics::PrometheusMetricEnums') |