summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-13 21:08:55 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-13 21:08:55 +0000
commita5650b86b5a809d3b7c754afd5ff5671e9bcc584 (patch)
tree6a53414f01dae4b5716a94c8d33136616c8b3eb1 /lib
parente689e858ede41a34b1e9132eba6a602632e6885e (diff)
downloadgitlab-ce-a5650b86b5a809d3b7c754afd5ff5671e9bcc584.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/api/admin/ci/variables.rb137
-rw-r--r--lib/api/api.rb1
-rw-r--r--lib/api/settings.rb11
-rw-r--r--lib/gitlab/alert_management/alert_params.rb3
-rw-r--r--lib/gitlab/alerting/notification_payload_parser.rb10
-rw-r--r--lib/gitlab/background_migration/populate_user_highest_roles_table.rb2
-rw-r--r--lib/gitlab/cycle_analytics/summary/value.rb2
-rw-r--r--lib/gitlab/graphql/query_analyzers/logger_analyzer.rb4
-rw-r--r--lib/gitlab/middleware/multipart.rb1
-rw-r--r--lib/gitlab/tree_summary.rb16
10 files changed, 169 insertions, 18 deletions
diff --git a/lib/api/admin/ci/variables.rb b/lib/api/admin/ci/variables.rb
new file mode 100644
index 00000000000..df731148bac
--- /dev/null
+++ b/lib/api/admin/ci/variables.rb
@@ -0,0 +1,137 @@
+# frozen_string_literal: true
+
+module API
+ module Admin
+ module Ci
+ class Variables < Grape::API
+ include PaginationParams
+
+ before { authenticated_as_admin! }
+
+ namespace 'admin' do
+ namespace 'ci' do
+ namespace 'variables' do
+ desc 'Get instance-level variables' do
+ success Entities::Variable
+ end
+ params do
+ use :pagination
+ end
+ get '/' do
+ variables = ::Ci::InstanceVariable.all
+
+ present paginate(variables), with: Entities::Variable
+ end
+
+ desc 'Get a specific variable from a group' do
+ success Entities::Variable
+ end
+ params do
+ requires :key, type: String, desc: 'The key of the variable'
+ end
+ get ':key' do
+ key = params[:key]
+ variable = ::Ci::InstanceVariable.find_by_key(key)
+
+ break not_found!('InstanceVariable') unless variable
+
+ present variable, with: Entities::Variable
+ end
+
+ desc 'Create a new instance-level variable' do
+ success Entities::Variable
+ end
+ params do
+ requires :key,
+ type: String,
+ desc: 'The key of the variable'
+
+ requires :value,
+ type: String,
+ desc: 'The value of the variable'
+
+ optional :protected,
+ type: String,
+ desc: 'Whether the variable is protected'
+
+ optional :masked,
+ type: String,
+ desc: 'Whether the variable is masked'
+
+ optional :variable_type,
+ type: String,
+ values: ::Ci::InstanceVariable.variable_types.keys,
+ desc: 'The type of variable, must be one of env_var or file. Defaults to env_var'
+ end
+ post '/' do
+ variable_params = declared_params(include_missing: false)
+
+ variable = ::Ci::InstanceVariable.new(variable_params)
+
+ if variable.save
+ present variable, with: Entities::Variable
+ else
+ render_validation_error!(variable)
+ end
+ end
+
+ desc 'Update an existing instance-variable' do
+ success Entities::Variable
+ end
+ params do
+ optional :key,
+ type: String,
+ desc: 'The key of the variable'
+
+ optional :value,
+ type: String,
+ desc: 'The value of the variable'
+
+ optional :protected,
+ type: String,
+ desc: 'Whether the variable is protected'
+
+ optional :masked,
+ type: String,
+ desc: 'Whether the variable is masked'
+
+ optional :variable_type,
+ type: String,
+ values: ::Ci::InstanceVariable.variable_types.keys,
+ desc: 'The type of variable, must be one of env_var or file'
+ end
+ put ':key' do
+ variable = ::Ci::InstanceVariable.find_by_key(params[:key])
+
+ break not_found!('InstanceVariable') unless variable
+
+ variable_params = declared_params(include_missing: false).except(:key)
+
+ if variable.update(variable_params)
+ present variable, with: Entities::Variable
+ else
+ render_validation_error!(variable)
+ end
+ end
+
+ desc 'Delete an existing instance-level variable' do
+ success Entities::Variable
+ end
+ params do
+ requires :key, type: String, desc: 'The key of the variable'
+ end
+ delete ':key' do
+ variable = ::Ci::InstanceVariable.find_by_key(params[:key])
+ not_found!('InstanceVariable') unless variable
+
+ variable.destroy
+
+ no_content!
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/api/api.rb b/lib/api/api.rb
index 433edc1daba..fe8f101e7b5 100644
--- a/lib/api/api.rb
+++ b/lib/api/api.rb
@@ -120,6 +120,7 @@ module API
# Keep in alphabetical order
mount ::API::AccessRequests
+ mount ::API::Admin::Ci::Variables
mount ::API::Admin::Sidekiq
mount ::API::Appearance
mount ::API::Applications
diff --git a/lib/api/settings.rb b/lib/api/settings.rb
index 304baa6aa0b..baae9513c98 100644
--- a/lib/api/settings.rb
+++ b/lib/api/settings.rb
@@ -84,16 +84,7 @@ module API
optional :max_artifacts_size, type: Integer, desc: "Set the maximum file size for each job's artifacts"
optional :max_attachment_size, type: Integer, desc: 'Maximum attachment size in MB'
optional :max_pages_size, type: Integer, desc: 'Maximum size of pages in MB'
- optional :metrics_enabled, type: Boolean, desc: 'Enable the InfluxDB metrics'
- given metrics_enabled: ->(val) { val } do
- requires :metrics_host, type: String, desc: 'The InfluxDB host'
- requires :metrics_method_call_threshold, type: Integer, desc: 'A method call is only tracked when it takes longer to complete than the given amount of milliseconds.'
- requires :metrics_packet_size, type: Integer, desc: 'The amount of points to store in a single UDP packet'
- requires :metrics_pool_size, type: Integer, desc: 'The amount of InfluxDB connections to open'
- requires :metrics_port, type: Integer, desc: 'The UDP port to use for connecting to InfluxDB'
- requires :metrics_sample_interval, type: Integer, desc: 'The sampling interval in seconds'
- requires :metrics_timeout, type: Integer, desc: 'The amount of seconds after which an InfluxDB connection will time out'
- end
+ optional :metrics_method_call_threshold, type: Integer, desc: 'A method call is only tracked when it takes longer to complete than the given amount of milliseconds.'
optional :password_authentication_enabled, type: Boolean, desc: 'Flag indicating if password authentication is enabled for the web interface' # support legacy names, can be removed in v5
optional :password_authentication_enabled_for_web, type: Boolean, desc: 'Flag indicating if password authentication is enabled for the web interface'
mutually_exclusive :password_authentication_enabled_for_web, :password_authentication_enabled, :signin_enabled
diff --git a/lib/gitlab/alert_management/alert_params.rb b/lib/gitlab/alert_management/alert_params.rb
index 876eff6d91e..982479784a9 100644
--- a/lib/gitlab/alert_management/alert_params.rb
+++ b/lib/gitlab/alert_management/alert_params.rb
@@ -19,7 +19,8 @@ module Gitlab
service: annotations[:service],
hosts: Array(annotations[:hosts]),
payload: payload,
- started_at: parsed_payload['startsAt']
+ started_at: parsed_payload['startsAt'],
+ severity: annotations[:severity]
}
end
diff --git a/lib/gitlab/alerting/notification_payload_parser.rb b/lib/gitlab/alerting/notification_payload_parser.rb
index a54bb44d66a..1237c575eac 100644
--- a/lib/gitlab/alerting/notification_payload_parser.rb
+++ b/lib/gitlab/alerting/notification_payload_parser.rb
@@ -5,7 +5,8 @@ module Gitlab
class NotificationPayloadParser
BadPayloadError = Class.new(StandardError)
- DEFAULT_TITLE = 'New: Incident'
+ DEFAULT_TITLE = 'New: Incident'.freeze
+ DEFAULT_SEVERITY = 'critical'.freeze
def initialize(payload)
@payload = payload.to_h.with_indifferent_access
@@ -30,6 +31,10 @@ module Gitlab
payload[:title].presence || DEFAULT_TITLE
end
+ def severity
+ payload[:severity].presence || DEFAULT_SEVERITY
+ end
+
def annotations
primary_params
.reverse_merge(flatten_secondary_params)
@@ -43,7 +48,8 @@ module Gitlab
'description' => payload[:description],
'monitoring_tool' => payload[:monitoring_tool],
'service' => payload[:service],
- 'hosts' => hosts.presence
+ 'hosts' => hosts.presence,
+ 'severity' => severity
}
end
diff --git a/lib/gitlab/background_migration/populate_user_highest_roles_table.rb b/lib/gitlab/background_migration/populate_user_highest_roles_table.rb
index 0c9e15b5a80..16386ebf9c3 100644
--- a/lib/gitlab/background_migration/populate_user_highest_roles_table.rb
+++ b/lib/gitlab/background_migration/populate_user_highest_roles_table.rb
@@ -20,6 +20,8 @@ module Gitlab
end
def perform(from_id, to_id)
+ return unless User.column_names.include?('bot_type')
+
(from_id..to_id).each_slice(BATCH_SIZE) do |ids|
execute(
<<-EOF
diff --git a/lib/gitlab/cycle_analytics/summary/value.rb b/lib/gitlab/cycle_analytics/summary/value.rb
index 9516f9ec974..ce32132e048 100644
--- a/lib/gitlab/cycle_analytics/summary/value.rb
+++ b/lib/gitlab/cycle_analytics/summary/value.rb
@@ -33,7 +33,7 @@ module Gitlab
class PrettyNumeric < Numeric
def to_s
# 0 is shown as -
- value.nonzero? ? super : None.new.to_s
+ (value || 0).nonzero? ? super : None.new.to_s
end
end
end
diff --git a/lib/gitlab/graphql/query_analyzers/logger_analyzer.rb b/lib/gitlab/graphql/query_analyzers/logger_analyzer.rb
index 327a9c549d5..6f705239fa3 100644
--- a/lib/gitlab/graphql/query_analyzers/logger_analyzer.rb
+++ b/lib/gitlab/graphql/query_analyzers/logger_analyzer.rb
@@ -34,7 +34,7 @@ module Gitlab
memo[:depth] = depth
memo[:complexity] = complexity
- memo[:duration] = duration(memo[:time_started]).round(1)
+ memo[:duration_s] = duration(memo[:time_started]).round(1)
GraphqlLogger.info(memo.except!(:time_started, :query))
rescue => e
@@ -62,7 +62,7 @@ module Gitlab
query_string: nil,
query: query,
variables: nil,
- duration: nil
+ duration_s: nil
}
end
end
diff --git a/lib/gitlab/middleware/multipart.rb b/lib/gitlab/middleware/multipart.rb
index 7d0de3aee1c..3c45f841653 100644
--- a/lib/gitlab/middleware/multipart.rb
+++ b/lib/gitlab/middleware/multipart.rb
@@ -110,6 +110,7 @@ module Gitlab
::FileUploader.root,
Gitlab.config.uploads.storage_path,
JobArtifactUploader.workhorse_upload_path,
+ LfsObjectUploader.workhorse_upload_path,
File.join(Rails.root, 'public/uploads/tmp')
]
end
diff --git a/lib/gitlab/tree_summary.rb b/lib/gitlab/tree_summary.rb
index 9861ea7d322..4ec43e62c19 100644
--- a/lib/gitlab/tree_summary.rb
+++ b/lib/gitlab/tree_summary.rb
@@ -3,18 +3,20 @@
module Gitlab
class TreeSummary
include ::Gitlab::Utils::StrongMemoize
+ include ::MarkupHelper
CACHE_EXPIRE_IN = 1.hour
MAX_OFFSET = 2**31
- attr_reader :commit, :project, :path, :offset, :limit
+ attr_reader :commit, :project, :path, :offset, :limit, :user
attr_reader :resolved_commits
private :resolved_commits
- def initialize(commit, project, params = {})
+ def initialize(commit, project, user, params = {})
@commit = commit
@project = project
+ @user = user
@path = params.fetch(:path, nil).presence
@offset = [params.fetch(:offset, 0).to_i, MAX_OFFSET].min
@@ -96,6 +98,7 @@ module Gitlab
end
commits_hsh = repository.list_last_commits_for_tree(commit.id, ensured_path, offset: offset, limit: limit)
+ prerender_commit_full_titles!(commits_hsh.values)
entries.each do |entry|
path_key = entry_path(entry)
@@ -104,6 +107,7 @@ module Gitlab
if commit
entry[:commit] = commit
entry[:commit_path] = commit_path(commit)
+ entry[:commit_title_html] = markdown_field(commit, :full_title)
end
end
end
@@ -131,6 +135,14 @@ module Gitlab
def tree
strong_memoize(:tree) { repository.tree(commit.id, path) }
end
+
+ def prerender_commit_full_titles!(commits)
+ # Preload commit authors as they are used in rendering
+ commits.each(&:lazy_author)
+
+ renderer = Banzai::ObjectRenderer.new(user: user, default_project: project)
+ renderer.render(commits, :full_title)
+ end
end
end