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
path: root/app
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-07 00:08:48 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-07 00:08:48 +0300
commita89cb5cbdd832d4d9e80517973aceda6bc0a3856 (patch)
tree574475bd0901a2f8906d36a4728b8bbb95b41e1c /app
parent0d6fa033121a9bef708b8f2de186c4034c61d4a3 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/clusters/components/application_row.vue2
-rw-r--r--app/assets/javascripts/diffs/components/diff_file_header.vue2
-rw-r--r--app/assets/javascripts/lib/utils/url_utility.js2
-rw-r--r--app/controllers/groups/registry/repositories_controller.rb15
-rw-r--r--app/controllers/projects/registry/repositories_controller.rb14
-rw-r--r--app/finders/projects/prometheus/alerts_finder.rb71
-rw-r--r--app/finders/protected_branches_finder.rb35
-rw-r--r--app/models/project.rb4
-rw-r--r--app/models/protected_branch.rb7
-rw-r--r--app/presenters/projects/prometheus/alert_presenter.rb110
-rw-r--r--app/serializers/container_repositories_serializer.rb1
-rw-r--r--app/services/git/base_hooks_service.rb26
12 files changed, 272 insertions, 17 deletions
diff --git a/app/assets/javascripts/clusters/components/application_row.vue b/app/assets/javascripts/clusters/components/application_row.vue
index 7db9898396b..f8bf778b9e7 100644
--- a/app/assets/javascripts/clusters/components/application_row.vue
+++ b/app/assets/javascripts/clusters/components/application_row.vue
@@ -307,7 +307,7 @@ export default {
<a
v-if="titleLink"
:href="titleLink"
- target="blank"
+ target="_blank"
rel="noopener noreferrer"
class="js-cluster-application-title"
>{{ title }}</a
diff --git a/app/assets/javascripts/diffs/components/diff_file_header.vue b/app/assets/javascripts/diffs/components/diff_file_header.vue
index 48114f9919c..731c53a7339 100644
--- a/app/assets/javascripts/diffs/components/diff_file_header.vue
+++ b/app/assets/javascripts/diffs/components/diff_file_header.vue
@@ -285,7 +285,7 @@ export default {
ref="viewButton"
v-gl-tooltip.hover
:href="diffFile.view_path"
- target="blank"
+ target="_blank"
class="view-file"
data-track-event="click_toggle_view_sha_button"
data-track-label="diff_toggle_view_sha_button"
diff --git a/app/assets/javascripts/lib/utils/url_utility.js b/app/assets/javascripts/lib/utils/url_utility.js
index 202363a1dda..267b49e9d98 100644
--- a/app/assets/javascripts/lib/utils/url_utility.js
+++ b/app/assets/javascripts/lib/utils/url_utility.js
@@ -166,7 +166,7 @@ export const setUrlFragment = (url, fragment) => {
export function visitUrl(url, external = false) {
if (external) {
- // Simulate `target="blank" rel="noopener noreferrer"`
+ // Simulate `target="_blank" rel="noopener noreferrer"`
// See https://mathiasbynens.github.io/rel-noopener/
const otherWindow = window.open();
otherWindow.opener = null;
diff --git a/app/controllers/groups/registry/repositories_controller.rb b/app/controllers/groups/registry/repositories_controller.rb
index a4ef33ecc6a..84c25cfb180 100644
--- a/app/controllers/groups/registry/repositories_controller.rb
+++ b/app/controllers/groups/registry/repositories_controller.rb
@@ -14,13 +14,24 @@ module Groups
track_event(:list_repositories)
- render json: ContainerRepositoriesSerializer
+ serializer = ContainerRepositoriesSerializer
.new(current_user: current_user)
- .represent_read_only(@images)
+
+ if Feature.enabled?(:vue_container_registry_explorer)
+ render json: serializer.with_pagination(request, response)
+ .represent_read_only(@images)
+ else
+ render json: serializer.represent_read_only(@images)
+ end
end
end
end
+ # The show action renders index to allow frontend routing to work on page refresh
+ def show
+ render :index
+ end
+
private
def feature_flag_group_container_registry_browser!
diff --git a/app/controllers/projects/registry/repositories_controller.rb b/app/controllers/projects/registry/repositories_controller.rb
index 5e933b3b51f..b31a74540e2 100644
--- a/app/controllers/projects/registry/repositories_controller.rb
+++ b/app/controllers/projects/registry/repositories_controller.rb
@@ -14,13 +14,23 @@ module Projects
track_event(:list_repositories)
- render json: ContainerRepositoriesSerializer
+ serializer = ContainerRepositoriesSerializer
.new(project: project, current_user: current_user)
- .represent(@images)
+
+ if Feature.enabled?(:vue_container_registry_explorer)
+ render json: serializer.with_pagination(request, response).represent(@images)
+ else
+ render json: serializer.represent(@images)
+ end
end
end
end
+ # The show action renders index to allow frontend routing to work on page refresh
+ def show
+ render :index
+ end
+
def destroy
DeleteContainerRepositoryWorker.perform_async(current_user.id, image.id)
track_event(:delete_repository)
diff --git a/app/finders/projects/prometheus/alerts_finder.rb b/app/finders/projects/prometheus/alerts_finder.rb
new file mode 100644
index 00000000000..3e3b72647c5
--- /dev/null
+++ b/app/finders/projects/prometheus/alerts_finder.rb
@@ -0,0 +1,71 @@
+# frozen_string_literal: true
+
+module Projects
+ module Prometheus
+ # Find Prometheus alerts by +project+, +environment+, +id+,
+ # or any combo thereof.
+ #
+ # Optionally filter by +metric+.
+ #
+ # Arguments:
+ # params:
+ # project: Project | integer
+ # environment: Environment | integer
+ # metric: PrometheusMetric | integer
+ class AlertsFinder
+ def initialize(params = {})
+ unless params[:project] || params[:environment] || params[:id]
+ raise ArgumentError,
+ 'Please provide one or more of the following params: :project, :environment, :id'
+ end
+
+ @params = params
+ end
+
+ # Find all matching alerts
+ #
+ # @return [ActiveRecord::Relation<PrometheusAlert>]
+ def execute
+ relation = by_project(PrometheusAlert)
+ relation = by_environment(relation)
+ relation = by_metric(relation)
+ relation = by_id(relation)
+ relation = ordered(relation)
+
+ relation
+ end
+
+ private
+
+ attr_reader :params
+
+ def by_project(relation)
+ return relation unless params[:project]
+
+ relation.for_project(params[:project])
+ end
+
+ def by_environment(relation)
+ return relation unless params[:environment]
+
+ relation.for_environment(params[:environment])
+ end
+
+ def by_metric(relation)
+ return relation unless params[:metric]
+
+ relation.for_metric(params[:metric])
+ end
+
+ def by_id(relation)
+ return relation unless params[:id]
+
+ relation.id_in(params[:id])
+ end
+
+ def ordered(relation)
+ relation.order_by('id_asc')
+ end
+ end
+ end
+end
diff --git a/app/finders/protected_branches_finder.rb b/app/finders/protected_branches_finder.rb
new file mode 100644
index 00000000000..68e8d2a9f54
--- /dev/null
+++ b/app/finders/protected_branches_finder.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+# ProtectedBranchesFinder
+#
+# Used to filter protected branches by set of params
+#
+# Arguments:
+# project - which project to scope to
+# params:
+# search: string
+class ProtectedBranchesFinder
+ LIMIT = 100
+
+ attr_accessor :project, :params
+
+ def initialize(project, params = {})
+ @project = project
+ @params = params
+ end
+
+ def execute
+ protected_branches = project.limited_protected_branches(LIMIT)
+ protected_branches = by_name(protected_branches)
+
+ protected_branches
+ end
+
+ private
+
+ def by_name(protected_branches)
+ return protected_branches unless params[:search].present?
+
+ protected_branches.by_name(params[:search])
+ end
+end
diff --git a/app/models/project.rb b/app/models/project.rb
index 78c3114ce9c..816d964519d 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -2304,6 +2304,10 @@ class Project < ApplicationRecord
ci_config_path.blank? || ci_config_path == Gitlab::FileDetector::PATTERNS[:gitlab_ci]
end
+ def limited_protected_branches(limit)
+ protected_branches.limit(limit)
+ end
+
private
def closest_namespace_setting(name)
diff --git a/app/models/protected_branch.rb b/app/models/protected_branch.rb
index 735e2bdea81..94c3b83564f 100644
--- a/app/models/protected_branch.rb
+++ b/app/models/protected_branch.rb
@@ -2,6 +2,7 @@
class ProtectedBranch < ApplicationRecord
include ProtectedRef
+ include Gitlab::SQL::Pattern
scope :requiring_code_owner_approval,
-> { where(code_owner_approval_required: true) }
@@ -45,6 +46,12 @@ class ProtectedBranch < ApplicationRecord
# NOOP
#
end
+
+ def self.by_name(query)
+ return none if query.blank?
+
+ where(fuzzy_arel_match(:name, query.downcase))
+ end
end
ProtectedBranch.prepend_if_ee('EE::ProtectedBranch')
diff --git a/app/presenters/projects/prometheus/alert_presenter.rb b/app/presenters/projects/prometheus/alert_presenter.rb
new file mode 100644
index 00000000000..8988c567c5c
--- /dev/null
+++ b/app/presenters/projects/prometheus/alert_presenter.rb
@@ -0,0 +1,110 @@
+# frozen_string_literal: true
+
+module Projects
+ module Prometheus
+ class AlertPresenter < Gitlab::View::Presenter::Delegated
+ RESERVED_ANNOTATIONS = %w(gitlab_incident_markdown title).freeze
+ GENERIC_ALERT_SUMMARY_ANNOTATIONS = %w(monitoring_tool service hosts).freeze
+ MARKDOWN_LINE_BREAK = " \n".freeze
+
+ def full_title
+ [environment_name, alert_title].compact.join(': ')
+ end
+
+ def project_full_path
+ project.full_path
+ end
+
+ def metric_query
+ gitlab_alert&.full_query
+ end
+
+ def environment_name
+ environment&.name
+ end
+
+ def performance_dashboard_link
+ if environment
+ metrics_project_environment_url(project, environment)
+ else
+ metrics_project_environments_url(project)
+ end
+ end
+
+ def starts_at
+ super&.rfc3339
+ end
+
+ def issue_summary_markdown
+ <<~MARKDOWN.chomp
+ #### Summary
+
+ #{metadata_list}
+ #{alert_details}
+ MARKDOWN
+ end
+
+ private
+
+ def alert_title
+ query_title || title
+ end
+
+ def query_title
+ return unless gitlab_alert
+
+ "#{gitlab_alert.title} #{gitlab_alert.computed_operator} #{gitlab_alert.threshold} for 5 minutes"
+ end
+
+ def metadata_list
+ metadata = []
+
+ metadata << list_item('Start time', starts_at) if starts_at
+ metadata << list_item('full_query', backtick(full_query)) if full_query
+ metadata << list_item(service.label.humanize, service.value) if service
+ metadata << list_item(monitoring_tool.label.humanize, monitoring_tool.value) if monitoring_tool
+ metadata << list_item(hosts.label.humanize, host_links) if hosts
+
+ metadata.join(MARKDOWN_LINE_BREAK)
+ end
+
+ def alert_details
+ if annotation_list.present?
+ <<~MARKDOWN.chomp
+
+ #### Alert Details
+
+ #{annotation_list}
+ MARKDOWN
+ end
+ end
+
+ def annotation_list
+ strong_memoize(:annotation_list) do
+ annotations
+ .reject { |annotation| annotation.label.in?(RESERVED_ANNOTATIONS | GENERIC_ALERT_SUMMARY_ANNOTATIONS) }
+ .map { |annotation| list_item(annotation.label, annotation.value) }
+ .join(MARKDOWN_LINE_BREAK)
+ end
+ end
+
+ def list_item(key, value)
+ "**#{key}:** #{value}".strip
+ end
+
+ def backtick(value)
+ "`#{value}`"
+ end
+
+ GENERIC_ALERT_SUMMARY_ANNOTATIONS.each do |annotation_name|
+ define_method(annotation_name) do
+ annotations.find { |a| a.label == annotation_name }
+ end
+ end
+
+ def host_links
+ Array(hosts.value).join(' ')
+ end
+ end
+ end
+end
diff --git a/app/serializers/container_repositories_serializer.rb b/app/serializers/container_repositories_serializer.rb
index bc35a67ff24..0e9bdee187b 100644
--- a/app/serializers/container_repositories_serializer.rb
+++ b/app/serializers/container_repositories_serializer.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
class ContainerRepositoriesSerializer < BaseSerializer
+ include WithPagination
entity ContainerRepositoryEntity
def represent_read_only(resource)
diff --git a/app/services/git/base_hooks_service.rb b/app/services/git/base_hooks_service.rb
index a49983a84fc..ea5b2f401b3 100644
--- a/app/services/git/base_hooks_service.rb
+++ b/app/services/git/base_hooks_service.rb
@@ -81,15 +81,17 @@ module Git
end
def pipeline_params
- {
- before: oldrev,
- after: newrev,
- ref: ref,
- variables_attributes: generate_vars_from_push_options || [],
- push_options: params[:push_options] || {},
- checkout_sha: Gitlab::DataBuilder::Push.checkout_sha(
- project.repository, newrev, ref)
- }
+ strong_memoize(:pipeline_params) do
+ {
+ before: oldrev,
+ after: newrev,
+ ref: ref,
+ variables_attributes: generate_vars_from_push_options || [],
+ push_options: params[:push_options] || {},
+ checkout_sha: Gitlab::DataBuilder::Push.checkout_sha(
+ project.repository, newrev, ref)
+ }
+ end
end
def ci_variables_from_push_options
@@ -156,12 +158,16 @@ module Git
project_path: project.full_path,
message: "Error creating pipeline",
errors: exception.to_s,
- pipeline_params: pipeline_params
+ pipeline_params: sanitized_pipeline_params
}
logger.warn(data)
end
+ def sanitized_pipeline_params
+ pipeline_params.except(:push_options)
+ end
+
def logger
if Gitlab::Runtime.sidekiq?
Sidekiq.logger