summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-26 06:08:40 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-26 06:08:40 +0000
commit116d4e56e83a1f408afe710ce070e699ba206475 (patch)
treecc62d3820d9bfa199061edfdef3a2f4bda140507 /app
parentdddde902acfa6acfb11583c61faa67cc7c8d11b6 (diff)
downloadgitlab-ce-116d4e56e83a1f408afe710ce070e699ba206475.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/pages/groups/settings/integrations/edit/index.js16
-rw-r--r--app/assets/stylesheets/framework/header.scss1
-rw-r--r--app/controllers/admin/integrations_controller.rb60
-rw-r--r--app/controllers/concerns/integrations_actions.rb94
-rw-r--r--app/controllers/groups/settings/integrations_controller.rb21
-rw-r--r--app/helpers/services_helper.rb30
-rw-r--r--app/models/ci/build.rb2
-rw-r--r--app/models/ci/pipeline.rb2
-rw-r--r--app/serializers/test_case_entity.rb13
-rw-r--r--app/views/admin/integrations/_form.html.haml12
-rw-r--r--app/views/admin/integrations/edit.html.haml5
-rw-r--r--app/views/layouts/header/_current_user_dropdown.html.haml1
-rw-r--r--app/views/shared/integrations/_form.html.haml14
-rw-r--r--app/views/shared/integrations/edit.html.haml5
14 files changed, 201 insertions, 75 deletions
diff --git a/app/assets/javascripts/pages/groups/settings/integrations/edit/index.js b/app/assets/javascripts/pages/groups/settings/integrations/edit/index.js
new file mode 100644
index 00000000000..2d77f2686f7
--- /dev/null
+++ b/app/assets/javascripts/pages/groups/settings/integrations/edit/index.js
@@ -0,0 +1,16 @@
+import IntegrationSettingsForm from '~/integrations/integration_settings_form';
+import PrometheusMetrics from '~/prometheus_metrics/prometheus_metrics';
+import initAlertsSettings from '~/alerts_service_settings';
+
+document.addEventListener('DOMContentLoaded', () => {
+ const prometheusSettingsWrapper = document.querySelector('.js-prometheus-metrics-monitoring');
+ const integrationSettingsForm = new IntegrationSettingsForm('.js-integration-settings-form');
+ integrationSettingsForm.init();
+
+ if (prometheusSettingsWrapper) {
+ const prometheusMetrics = new PrometheusMetrics('.js-prometheus-metrics-monitoring');
+ prometheusMetrics.loadActiveMetrics();
+ }
+
+ initAlertsSettings(document.querySelector('.js-alerts-service-settings'));
+});
diff --git a/app/assets/stylesheets/framework/header.scss b/app/assets/stylesheets/framework/header.scss
index dd338a7134b..0e507fd0988 100644
--- a/app/assets/stylesheets/framework/header.scss
+++ b/app/assets/stylesheets/framework/header.scss
@@ -553,6 +553,7 @@
vertical-align: text-top;
}
+ a.ci-minutes-emoji gl-emoji,
a.trial-link gl-emoji {
font-size: $gl-font-size;
vertical-align: baseline;
diff --git a/app/controllers/admin/integrations_controller.rb b/app/controllers/admin/integrations_controller.rb
index 715aa882bda..0d79032233f 100644
--- a/app/controllers/admin/integrations_controller.rb
+++ b/app/controllers/admin/integrations_controller.rb
@@ -1,67 +1,15 @@
# frozen_string_literal: true
class Admin::IntegrationsController < Admin::ApplicationController
- include ServiceParams
-
- before_action :not_found, unless: :instance_level_integrations_enabled?
- before_action :service, only: [:edit, :update, :test]
-
- def edit
- end
-
- def update
- @service.attributes = service_params[:service]
-
- if @service.save(context: :manual_change)
- redirect_to edit_admin_application_settings_integration_path(@service), notice: success_message
- else
- render :edit
- end
- end
-
- def test
- if @service.can_test?
- render json: service_test_response, status: :ok
- else
- render json: {}, status: :not_found
- end
- end
+ include IntegrationsActions
private
- def instance_level_integrations_enabled?
+ def integrations_enabled?
Feature.enabled?(:instance_level_integrations)
end
- def project
- # TODO: Change to something more meaningful
- Project.first
- end
-
- def service
- @service ||= project.find_or_initialize_service(params[:id])
- end
-
- def success_message
- message = @service.active? ? _('activated') : _('settings saved, but not activated')
-
- _('%{service_title} %{message}.') % { service_title: @service.title, message: message }
- end
-
- def service_test_response
- unless @service.update(service_params[:service])
- return { error: true, message: _('Validations failed.'), service_response: @service.errors.full_messages.join(','), test_failed: false }
- end
-
- data = @service.test_data(project, current_user)
- outcome = @service.test(data)
-
- unless outcome[:success]
- return { error: true, message: _('Test failed.'), service_response: outcome[:result].to_s, test_failed: true }
- end
-
- {}
- rescue Gitlab::HTTP::BlockedUrlError => e
- { error: true, message: _('Test failed.'), service_response: e.message, test_failed: true }
+ def scoped_edit_integration_path(integration)
+ edit_admin_application_settings_integration_path(integration)
end
end
diff --git a/app/controllers/concerns/integrations_actions.rb b/app/controllers/concerns/integrations_actions.rb
new file mode 100644
index 00000000000..ffb5d7a8086
--- /dev/null
+++ b/app/controllers/concerns/integrations_actions.rb
@@ -0,0 +1,94 @@
+# frozen_string_literal: true
+
+module IntegrationsActions
+ extend ActiveSupport::Concern
+
+ included do
+ include ServiceParams
+
+ before_action :not_found, unless: :integrations_enabled?
+ before_action :integration, only: [:edit, :update, :test]
+ end
+
+ def edit
+ render 'shared/integrations/edit'
+ end
+
+ def update
+ integration.attributes = service_params[:service]
+
+ saved = integration.save(context: :manual_change)
+
+ respond_to do |format|
+ format.html do
+ if saved
+ redirect_to scoped_edit_integration_path(integration), notice: success_message
+ else
+ render 'shared/integrations/edit'
+ end
+ end
+
+ format.json do
+ status = saved ? :ok : :unprocessable_entity
+
+ render json: serialize_as_json, status: status
+ end
+ end
+ end
+
+ def test
+ if integration.can_test?
+ render json: service_test_response, status: :ok
+ else
+ render json: {}, status: :not_found
+ end
+ end
+
+ private
+
+ def integrations_enabled?
+ false
+ end
+
+ # TODO: Use actual integrations on the group / instance level
+ # To be completed in https://gitlab.com/groups/gitlab-org/-/epics/2430
+ def project
+ Project.first
+ end
+
+ def integration
+ # Using instance variable `@service` still required as it's used in ServiceParams
+ # and app/views/shared/_service_settings.html.haml. Should be removed once
+ # those 2 are refactored to use `@integration`.
+ @integration = @service ||= project.find_or_initialize_service(params[:id]) # rubocop:disable Gitlab/ModuleWithInstanceVariables
+ end
+
+ def success_message
+ message = integration.active? ? _('activated') : _('settings saved, but not activated')
+
+ _('%{service_title} %{message}.') % { service_title: integration.title, message: message }
+ end
+
+ def serialize_as_json
+ integration
+ .as_json(only: integration.json_fields)
+ .merge(errors: integration.errors.as_json)
+ end
+
+ def service_test_response
+ unless integration.update(service_params[:service])
+ return { error: true, message: _('Validations failed.'), service_response: integration.errors.full_messages.join(','), test_failed: false }
+ end
+
+ data = integration.test_data(project, current_user)
+ outcome = integration.test(data)
+
+ unless outcome[:success]
+ return { error: true, message: _('Test failed.'), service_response: outcome[:result].to_s, test_failed: true }
+ end
+
+ {}
+ rescue Gitlab::HTTP::BlockedUrlError => e
+ { error: true, message: _('Test failed.'), service_response: e.message, test_failed: true }
+ end
+end
diff --git a/app/controllers/groups/settings/integrations_controller.rb b/app/controllers/groups/settings/integrations_controller.rb
new file mode 100644
index 00000000000..43f8a7118d4
--- /dev/null
+++ b/app/controllers/groups/settings/integrations_controller.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+module Groups
+ module Settings
+ class IntegrationsController < Groups::ApplicationController
+ include IntegrationsActions
+
+ before_action :authorize_admin_group!
+
+ private
+
+ def integrations_enabled?
+ Feature.enabled?(:group_level_integrations, group)
+ end
+
+ def scoped_edit_integration_path(integration)
+ edit_group_settings_integration_path(group, integration)
+ end
+ end
+ end
+end
diff --git a/app/helpers/services_helper.rb b/app/helpers/services_helper.rb
index d2336de7193..fe2df918819 100644
--- a/app/helpers/services_helper.rb
+++ b/app/helpers/services_helper.rb
@@ -66,6 +66,36 @@ module ServicesHelper
edit_admin_application_settings_integration_path(integration)
end
+ def scoped_integrations_path
+ if @project.present?
+ project_settings_integrations_path(@project)
+ elsif @group.present?
+ group_settings_integrations_path(@group)
+ else
+ integrations_admin_application_settings_path
+ end
+ end
+
+ def scoped_integration_path(integration)
+ if @project.present?
+ project_settings_integration_path(@project, integration)
+ elsif @group.present?
+ group_settings_integration_path(@group, integration)
+ else
+ admin_application_settings_integration_path(integration)
+ end
+ end
+
+ def scoped_test_integration_path(integration)
+ if @project.present?
+ test_project_settings_integration_path(@project, integration)
+ elsif @group.present?
+ test_group_settings_integration_path(@group, integration)
+ else
+ test_admin_application_settings_integration_path(integration)
+ end
+ end
+
extend self
end
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index f9d17bfc8b7..fb9e341dff7 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -873,7 +873,7 @@ module Ci
def collect_test_reports!(test_reports)
test_reports.get_suite(group_name).tap do |test_suite|
each_report(Ci::JobArtifact::TEST_REPORT_FILE_TYPES) do |file_type, blob|
- Gitlab::Ci::Parsers.fabricate!(file_type).parse!(blob, test_suite)
+ Gitlab::Ci::Parsers.fabricate!(file_type).parse!(blob, test_suite, job: self)
end
end
end
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index ef22b429df9..e9cd0d91bc0 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -813,7 +813,7 @@ module Ci
def test_reports
Gitlab::Ci::Reports::TestReports.new.tap do |test_reports|
- builds.latest.with_reports(Ci::JobArtifact.test_reports).each do |build|
+ builds.latest.with_reports(Ci::JobArtifact.test_reports).preload(:project).find_each do |build|
build.collect_test_reports!(test_reports)
end
end
diff --git a/app/serializers/test_case_entity.rb b/app/serializers/test_case_entity.rb
index 5c915c1302c..d2e08590ef0 100644
--- a/app/serializers/test_case_entity.rb
+++ b/app/serializers/test_case_entity.rb
@@ -1,10 +1,23 @@
# frozen_string_literal: true
class TestCaseEntity < Grape::Entity
+ include API::Helpers::RelatedResourcesHelpers
+
expose :status
expose :name
expose :classname
expose :execution_time
expose :system_output
expose :stack_trace
+ expose :attachment_url, if: -> (*) { can_read_screenshots? } do |test_case|
+ expose_url(test_case.attachment_url)
+ end
+
+ private
+
+ alias_method :test_case, :object
+
+ def can_read_screenshots?
+ Feature.enabled?(:junit_pipeline_screenshots_view, options[:project]) && test_case.has_attachment?
+ end
end
diff --git a/app/views/admin/integrations/_form.html.haml b/app/views/admin/integrations/_form.html.haml
deleted file mode 100644
index aa865c3b052..00000000000
--- a/app/views/admin/integrations/_form.html.haml
+++ /dev/null
@@ -1,12 +0,0 @@
-%h3.page-title
- = @service.title
-
-%p= @service.description
-
-= form_for @service, as: :service, url: admin_application_settings_integration_path, method: :put, html: { class: 'gl-show-field-errors fieldset-form integration-settings-form js-integration-settings-form', data: { 'can-test' => @service.can_test?, 'test-url' => test_admin_application_settings_integration_path(@service) } } do |form|
- = render 'shared/service_settings', form: form, service: @service
-
- - if @service.editable?
- .footer-block.row-content-block
- = service_save_button(@service)
- = link_to _('Cancel'), admin_application_settings_integration_path, class: 'btn btn-cancel'
diff --git a/app/views/admin/integrations/edit.html.haml b/app/views/admin/integrations/edit.html.haml
deleted file mode 100644
index b19d00d7a16..00000000000
--- a/app/views/admin/integrations/edit.html.haml
+++ /dev/null
@@ -1,5 +0,0 @@
-- add_to_breadcrumbs _('Integrations'), integrations_admin_application_settings_path
-- breadcrumb_title @service.title
-- page_title @service.title, _('Integrations')
-
-= render 'form'
diff --git a/app/views/layouts/header/_current_user_dropdown.html.haml b/app/views/layouts/header/_current_user_dropdown.html.haml
index 84906c305a7..c6299f244ec 100644
--- a/app/views/layouts/header/_current_user_dropdown.html.haml
+++ b/app/views/layouts/header/_current_user_dropdown.html.haml
@@ -26,6 +26,7 @@
- if current_user_menu?(:settings)
%li
= link_to s_("CurrentUser|Settings"), profile_path, data: { qa_selector: 'settings_link' }
+ = render_if_exists 'layouts/header/buy_ci_minutes'
- if current_user_menu?(:help)
%li.divider.d-md-none
diff --git a/app/views/shared/integrations/_form.html.haml b/app/views/shared/integrations/_form.html.haml
new file mode 100644
index 00000000000..0ddab1368c2
--- /dev/null
+++ b/app/views/shared/integrations/_form.html.haml
@@ -0,0 +1,14 @@
+- integration = local_assigns.fetch(:integration)
+
+%h3.page-title
+ = integration.title
+
+%p= integration.description
+
+= form_for integration, as: :service, url: scoped_integration_path(integration), method: :put, html: { class: 'gl-show-field-errors fieldset-form integration-settings-form js-integration-settings-form', data: { 'can-test' => integration.can_test?, 'test-url' => scoped_test_integration_path(integration) } } do |form|
+ = render 'shared/service_settings', form: form, integration: integration
+
+ - if integration.editable?
+ .footer-block.row-content-block
+ = service_save_button(integration)
+ = link_to _('Cancel'), scoped_integration_path(integration), class: 'btn btn-cancel'
diff --git a/app/views/shared/integrations/edit.html.haml b/app/views/shared/integrations/edit.html.haml
new file mode 100644
index 00000000000..927d2410132
--- /dev/null
+++ b/app/views/shared/integrations/edit.html.haml
@@ -0,0 +1,5 @@
+- add_to_breadcrumbs _('Integrations'), scoped_integrations_path
+- breadcrumb_title @integration.title
+- page_title @integration.title, _('Integrations')
+
+= render 'shared/integrations/form', integration: @integration