Commit 0671028a authored by Alex Kalderimis's avatar Alex Kalderimis Committed by Matthias Käppler

Rename services helpers

This renames the services helpers modules:

- the main controller helper is renamed to `IntegrationsHelper`
- the API helper is renamed likewise

The test helper is removed and replaced by a matcher, since that was
just confusing things.

Method names in these helpers are renamed.
parent 7e126601
...@@ -440,7 +440,7 @@ Rails/ApplicationController: ...@@ -440,7 +440,7 @@ Rails/ApplicationController:
- 'app/controllers/health_controller.rb' - 'app/controllers/health_controller.rb'
- 'app/controllers/metrics_controller.rb' - 'app/controllers/metrics_controller.rb'
- 'ee/app/controllers/oauth/geo_auth_controller.rb' - 'ee/app/controllers/oauth/geo_auth_controller.rb'
- 'ee/spec/helpers/ee/services_helper_spec.rb' - 'ee/spec/helpers/ee/integrations_helper_spec.rb'
- 'lib/gitlab/base_doorkeeper_controller.rb' - 'lib/gitlab/base_doorkeeper_controller.rb'
- 'lib/gitlab/request_forgery_protection.rb' - 'lib/gitlab/request_forgery_protection.rb'
- 'spec/controllers/concerns/continue_params_spec.rb' - 'spec/controllers/concerns/continue_params_spec.rb'
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
class Admin::ApplicationSettingsController < Admin::ApplicationController class Admin::ApplicationSettingsController < Admin::ApplicationController
include InternalRedirect include InternalRedirect
include ServicesHelper include IntegrationsHelper
# NOTE: Use @application_setting in this controller when you need to access # NOTE: Use @application_setting in this controller when you need to access
# application_settings after it has been modified. This is because the # application_settings after it has been modified. This is because the
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
class Admin::IntegrationsController < Admin::ApplicationController class Admin::IntegrationsController < Admin::ApplicationController
include IntegrationsActions include IntegrationsActions
include ServicesHelper include IntegrationsHelper
before_action :not_found, unless: -> { instance_level_integrations? } before_action :not_found, unless: -> { instance_level_integrations? }
......
# frozen_string_literal: true # frozen_string_literal: true
module ServicesHelper module IntegrationsHelper
def service_event_description(event) def integration_event_description(event)
case event case event
when "push", "push_events" when "push", "push_events"
s_("ProjectService|Trigger event for pushes to the repository.") s_("ProjectService|Trigger event for pushes to the repository.")
...@@ -30,7 +30,7 @@ module ServicesHelper ...@@ -30,7 +30,7 @@ module ServicesHelper
end end
end end
def service_event_field_name(event) def integration_event_field_name(event)
event = event.pluralize if %w[merge_request issue confidential_issue].include?(event) event = event.pluralize if %w[merge_request issue confidential_issue].include?(event)
"#{event}_events" "#{event}_events"
end end
...@@ -96,8 +96,8 @@ module ServicesHelper ...@@ -96,8 +96,8 @@ module ServicesHelper
enable_comments: integration.comment_on_event_enabled.to_s, enable_comments: integration.comment_on_event_enabled.to_s,
comment_detail: integration.comment_detail, comment_detail: integration.comment_detail,
learn_more_path: integrations_help_page_path, learn_more_path: integrations_help_page_path,
trigger_events: trigger_events_for_service(integration), trigger_events: trigger_events_for_integration(integration),
fields: fields_for_service(integration), fields: fields_for_integration(integration),
inherit_from_id: integration.inherit_from_id, inherit_from_id: integration.inherit_from_id,
integration_level: integration_level(integration), integration_level: integration_level(integration),
editable: integration.editable?.to_s, editable: integration.editable?.to_s,
...@@ -121,14 +121,6 @@ module ServicesHelper ...@@ -121,14 +121,6 @@ module ServicesHelper
} }
end end
def trigger_events_for_service(integration)
ServiceEventSerializer.new(service: integration).represent(integration.configurable_events).to_json
end
def fields_for_service(integration)
ServiceFieldSerializer.new(service: integration).represent(integration.global_fields).to_json
end
def integrations_help_page_path def integrations_help_page_path
help_page_path('user/admin_area/settings/project_integration_management') help_page_path('user/admin_area/settings/project_integration_management')
end end
...@@ -152,6 +144,14 @@ module ServicesHelper ...@@ -152,6 +144,14 @@ module ServicesHelper
private private
def trigger_events_for_integration(integration)
ServiceEventSerializer.new(service: integration).represent(integration.configurable_events).to_json
end
def fields_for_integration(integration)
ServiceFieldSerializer.new(service: integration).represent(integration.global_fields).to_json
end
def integration_level(integration) def integration_level(integration)
if integration.instance_level? if integration.instance_level?
'instance' 'instance'
...@@ -178,8 +178,8 @@ module ServicesHelper ...@@ -178,8 +178,8 @@ module ServicesHelper
end end
end end
ServicesHelper.prepend_mod_with('ServicesHelper') IntegrationsHelper.prepend_mod_with('IntegrationsHelper')
# The methods in `EE::ServicesHelper` should be available as both instance and # The methods in `EE::IntegrationsHelper` should be available as both instance and
# class methods. # class methods.
ServicesHelper.extend_mod_with('ServicesHelper') IntegrationsHelper.extend_mod_with('IntegrationsHelper')
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
module OperationsHelper module OperationsHelper
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
include IntegrationsHelper
def prometheus_integration def prometheus_integration
strong_memoize(:prometheus_integration) do strong_memoize(:prometheus_integration) do
......
...@@ -178,7 +178,7 @@ class Integration < ApplicationRecord ...@@ -178,7 +178,7 @@ class Integration < ApplicationRecord
end end
def self.event_names def self.event_names
self.supported_events.map { |event| ServicesHelper.service_event_field_name(event) } self.supported_events.map { |event| IntegrationsHelper.integration_event_field_name(event) }
end end
def self.supported_event_actions def self.supported_event_actions
...@@ -194,7 +194,7 @@ class Integration < ApplicationRecord ...@@ -194,7 +194,7 @@ class Integration < ApplicationRecord
end end
def self.event_description(event) def self.event_description(event)
ServicesHelper.service_event_description(event) IntegrationsHelper.integration_event_description(event)
end end
def self.find_or_create_templates def self.find_or_create_templates
......
...@@ -10,11 +10,11 @@ class ServiceEventEntity < Grape::Entity ...@@ -10,11 +10,11 @@ class ServiceEventEntity < Grape::Entity
expose :event_field_name, as: :name expose :event_field_name, as: :name
expose :value do |event| expose :value do |event|
service[event_field_name] integration[event_field_name]
end end
expose :description do |event| expose :description do |event|
ServicesHelper.service_event_description(event) IntegrationsHelper.integration_event_description(event)
end end
expose :field, if: -> (_, _) { event_field } do expose :field, if: -> (_, _) { event_field } do
...@@ -22,7 +22,7 @@ class ServiceEventEntity < Grape::Entity ...@@ -22,7 +22,7 @@ class ServiceEventEntity < Grape::Entity
event_field[:name] event_field[:name]
end end
expose :value do |event| expose :value do |event|
service.public_send(event_field[:name]) # rubocop:disable GitlabSecurity/PublicSend integration.public_send(event_field[:name]) # rubocop:disable GitlabSecurity/PublicSend
end end
end end
...@@ -31,14 +31,14 @@ class ServiceEventEntity < Grape::Entity ...@@ -31,14 +31,14 @@ class ServiceEventEntity < Grape::Entity
alias_method :event, :object alias_method :event, :object
def event_field_name def event_field_name
ServicesHelper.service_event_field_name(event) IntegrationsHelper.integration_event_field_name(event)
end end
def event_field def event_field
@event_field ||= service.event_field(event) @event_field ||= integration.event_field(event)
end end
def service def integration
request.service request.service
end end
end end
# frozen_string_literal: true # frozen_string_literal: true
class Profiles::SlacksController < Profiles::ApplicationController class Profiles::SlacksController < Profiles::ApplicationController
include ServicesHelper include IntegrationsHelper
skip_before_action :authenticate_user! skip_before_action :authenticate_user!
......
# frozen_string_literal: true # frozen_string_literal: true
module EE module EE
module ServicesHelper module IntegrationsHelper
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
override :project_jira_issues_integration? override :project_jira_issues_integration?
......
...@@ -3,14 +3,14 @@ ...@@ -3,14 +3,14 @@
module EE module EE
module API module API
module Helpers module Helpers
module ServicesHelpers module IntegrationsHelpers
extend ActiveSupport::Concern extend ActiveSupport::Concern
class_methods do class_methods do
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
override :services override :integrations
def services def integrations
super.merge( super.merge(
'github' => [ 'github' => [
{ {
...@@ -35,8 +35,8 @@ module EE ...@@ -35,8 +35,8 @@ module EE
) )
end end
override :service_classes override :integration_classes
def service_classes def integration_classes
[ [
::Integrations::Github, ::Integrations::Github,
*super *super
......
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe EE::ServicesHelper do RSpec.describe EE::IntegrationsHelper do
include Devise::Test::ControllerHelpers include Devise::Test::ControllerHelpers
let(:controller_class) do let(:controller_class) do
helper_mod = described_class
Class.new(ActionController::Base) do Class.new(ActionController::Base) do
include EE::ServicesHelper include helper_mod
include ActionView::Helpers::AssetUrlHelper include ActionView::Helpers::AssetUrlHelper
def slack_auth_project_settings_slack_url(project) def slack_auth_project_settings_slack_url(project)
......
...@@ -4,7 +4,6 @@ require 'spec_helper' ...@@ -4,7 +4,6 @@ require 'spec_helper'
RSpec.describe PostReceive do RSpec.describe PostReceive do
include AfterNextHelpers include AfterNextHelpers
include ServicesHelper
let(:changes) { "123456 789012 refs/heads/tést\n654321 210987 refs/tags/tag" } let(:changes) { "123456 789012 refs/heads/tést\n654321 210987 refs/tags/tag" }
let(:changes_with_master) { "#{changes}\n423423 797823 refs/heads/master" } let(:changes_with_master) { "#{changes}\n423423 797823 refs/heads/master" }
...@@ -77,7 +76,7 @@ RSpec.describe PostReceive do ...@@ -77,7 +76,7 @@ RSpec.describe PostReceive do
it 'calls Geo::RepositoryUpdatedService when running on a Geo primary node' do it 'calls Geo::RepositoryUpdatedService when running on a Geo primary node' do
allow(Gitlab::Geo).to receive(:primary?) { true } allow(Gitlab::Geo).to receive(:primary?) { true }
expect_execution_of(::Geo::RepositoryUpdatedService) expect(::Geo::RepositoryUpdatedService).to get_executed
described_class.new.perform(gl_repository, key_id, base64_changes) described_class.new.perform(gl_repository, key_id, base64_changes)
end end
...@@ -113,7 +112,7 @@ RSpec.describe PostReceive do ...@@ -113,7 +112,7 @@ RSpec.describe PostReceive do
it 'calls Geo::RepositoryUpdatedService when running on a Geo primary node' do it 'calls Geo::RepositoryUpdatedService when running on a Geo primary node' do
allow(Gitlab::Geo).to receive(:primary?) { true } allow(Gitlab::Geo).to receive(:primary?) { true }
expect_execution_of(::Geo::RepositoryUpdatedService) expect(::Geo::RepositoryUpdatedService).to get_executed
described_class.new.perform(gl_repository, key_id, base64_changes) described_class.new.perform(gl_repository, key_id, base64_changes)
end end
......
...@@ -6,7 +6,7 @@ module API ...@@ -6,7 +6,7 @@ module API
# #
# The data structures inside this model are returned using class methods, # The data structures inside this model are returned using class methods,
# allowing EE to extend them where necessary. # allowing EE to extend them where necessary.
module ServicesHelpers module IntegrationsHelpers
def self.chat_notification_settings def self.chat_notification_settings
[ [
{ {
...@@ -159,7 +159,7 @@ module API ...@@ -159,7 +159,7 @@ module API
].freeze ].freeze
end end
def self.services def self.integrations
{ {
'asana' => [ 'asana' => [
{ {
...@@ -772,7 +772,7 @@ module API ...@@ -772,7 +772,7 @@ module API
} }
end end
def self.service_classes def self.integration_classes
[ [
::Integrations::Asana, ::Integrations::Asana,
::Integrations::Assembla, ::Integrations::Assembla,
...@@ -809,7 +809,7 @@ module API ...@@ -809,7 +809,7 @@ module API
] ]
end end
def self.development_service_classes def self.development_integration_classes
[ [
::Integrations::MockCi, ::Integrations::MockCi,
::Integrations::MockMonitoring ::Integrations::MockMonitoring
...@@ -819,4 +819,4 @@ module API ...@@ -819,4 +819,4 @@ module API
end end
end end
API::Helpers::ServicesHelpers.prepend_mod_with('API::Helpers::ServicesHelpers') API::Helpers::IntegrationsHelpers.prepend_mod_with('API::Helpers::IntegrationsHelpers')
...@@ -3,11 +3,11 @@ module API ...@@ -3,11 +3,11 @@ module API
class Services < ::API::Base class Services < ::API::Base
feature_category :integrations feature_category :integrations
services = Helpers::ServicesHelpers.services integrations = Helpers::IntegrationsHelpers.integrations
service_classes = Helpers::ServicesHelpers.service_classes integration_classes = Helpers::IntegrationsHelpers.integration_classes
if Rails.env.development? if Rails.env.development?
services['mock-ci'] = [ integrations['mock-ci'] = [
{ {
required: true, required: true,
name: :mock_service_url, name: :mock_service_url,
...@@ -15,19 +15,18 @@ module API ...@@ -15,19 +15,18 @@ module API
desc: 'URL to the mock service' desc: 'URL to the mock service'
} }
] ]
services['mock-deployment'] = [] integrations['mock-deployment'] = []
services['mock-monitoring'] = [] integrations['mock-monitoring'] = []
service_classes += Helpers::ServicesHelpers.development_service_classes integration_classes += Helpers::IntegrationsHelpers.development_integration_classes
end end
SERVICES = services.freeze INTEGRATIONS = integrations.freeze
SERVICE_CLASSES = service_classes.freeze
SERVICE_CLASSES.each do |service| integration_classes.each do |service|
event_names = service.try(:event_names) || next event_names = service.try(:event_names) || next
event_names.each do |event_name| event_names.each do |event_name|
SERVICES[service.to_param.tr("_", "-")] << { INTEGRATIONS[service.to_param.tr("_", "-")] << {
required: false, required: false,
name: event_name.to_sym, name: event_name.to_sym,
type: String, type: String,
...@@ -77,7 +76,7 @@ module API ...@@ -77,7 +76,7 @@ module API
present services, with: Entities::ProjectServiceBasic present services, with: Entities::ProjectServiceBasic
end end
SERVICES.each do |slug, settings| INTEGRATIONS.each do |slug, settings|
desc "Set #{slug} service for project" desc "Set #{slug} service for project"
params do params do
settings.each do |setting| settings.each do |setting|
...@@ -100,9 +99,9 @@ module API ...@@ -100,9 +99,9 @@ module API
end end
end end
desc "Delete a service for project" desc "Delete an integration from a project"
params do params do
requires :slug, type: String, values: SERVICES.keys, desc: 'The name of the service' requires :slug, type: String, values: INTEGRATIONS.keys, desc: 'The name of the service'
end end
delete ":id/services/:slug" do delete ":id/services/:slug" do
integration = user_project.find_or_initialize_integration(params[:slug].underscore) integration = user_project.find_or_initialize_integration(params[:slug].underscore)
...@@ -114,11 +113,11 @@ module API ...@@ -114,11 +113,11 @@ module API
end end
end end
desc 'Get the service settings for project' do desc 'Get the integration settings for a project' do
success Entities::ProjectService success Entities::ProjectService
end end
params do params do
requires :slug, type: String, values: SERVICES.keys, desc: 'The name of the service' requires :slug, type: String, values: INTEGRATIONS.keys, desc: 'The name of the service'
end end
get ":id/services/:slug" do get ":id/services/:slug" do
integration = user_project.find_or_initialize_integration(params[:slug].underscore) integration = user_project.find_or_initialize_integration(params[:slug].underscore)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe ServicesHelper do RSpec.describe IntegrationsHelper do
describe '#integration_form_data' do describe '#integration_form_data' do
let(:fields) do let(:fields) do
[ [
......
# frozen_string_literal: true # frozen_string_literal: true
require_relative './after_next_helpers' # named as `get_executed` to avoid clashing
# with `be_executed === have_attributes(executed: true)`
module ServicesHelper RSpec::Matchers.define :get_executed do |args = []|
include AfterNextHelpers include AfterNextHelpers
def expect_execution_of(service_class, *args) match do |service_class|
expect_next(service_class, *args).to receive(:execute) expect_next(service_class, *args).to receive(:execute)
end end
end end
...@@ -4,7 +4,6 @@ require 'spec_helper' ...@@ -4,7 +4,6 @@ require 'spec_helper'
RSpec.describe ::JiraConnect::SyncBuildsWorker do RSpec.describe ::JiraConnect::SyncBuildsWorker do
include AfterNextHelpers include AfterNextHelpers
include ServicesHelper
describe '#perform' do describe '#perform' do
let_it_be(:pipeline) { create(:ci_pipeline) } let_it_be(:pipeline) { create(:ci_pipeline) }
......
...@@ -4,7 +4,6 @@ require 'spec_helper' ...@@ -4,7 +4,6 @@ require 'spec_helper'
RSpec.describe ::JiraConnect::SyncDeploymentsWorker do RSpec.describe ::JiraConnect::SyncDeploymentsWorker do
include AfterNextHelpers include AfterNextHelpers
include ServicesHelper
describe '#perform' do describe '#perform' do
let_it_be(:deployment) { create(:deployment) } let_it_be(:deployment) { create(:deployment) }
......
...@@ -4,7 +4,6 @@ require 'spec_helper' ...@@ -4,7 +4,6 @@ require 'spec_helper'
RSpec.describe ::JiraConnect::SyncFeatureFlagsWorker do RSpec.describe ::JiraConnect::SyncFeatureFlagsWorker do
include AfterNextHelpers include AfterNextHelpers
include ServicesHelper
describe '#perform' do describe '#perform' do
let_it_be(:feature_flag) { create(:operations_feature_flag) } let_it_be(:feature_flag) { create(:operations_feature_flag) }
......
...@@ -4,7 +4,6 @@ require 'spec_helper' ...@@ -4,7 +4,6 @@ require 'spec_helper'
RSpec.describe PostReceive do RSpec.describe PostReceive do
include AfterNextHelpers include AfterNextHelpers
include ServicesHelper
let(:changes) { "123456 789012 refs/heads/tést\n654321 210987 refs/tags/tag" } let(:changes) { "123456 789012 refs/heads/tést\n654321 210987 refs/tags/tag" }
let(:wrongly_encoded_changes) { changes.encode("ISO-8859-1").force_encoding("UTF-8") } let(:wrongly_encoded_changes) { changes.encode("ISO-8859-1").force_encoding("UTF-8") }
...@@ -234,7 +233,7 @@ RSpec.describe PostReceive do ...@@ -234,7 +233,7 @@ RSpec.describe PostReceive do
end end
it 'calls Git::ProcessRefChangesService' do it 'calls Git::ProcessRefChangesService' do
expect_execution_of(Git::ProcessRefChangesService) expect(Git::ProcessRefChangesService).to get_executed
perform perform
end end
...@@ -269,7 +268,7 @@ RSpec.describe PostReceive do ...@@ -269,7 +268,7 @@ RSpec.describe PostReceive do
allow(Gitlab::DataBuilder::Repository).to receive(:update).and_return(fake_hook_data) allow(Gitlab::DataBuilder::Repository).to receive(:update).and_return(fake_hook_data)
# silence hooks so we can isolate # silence hooks so we can isolate
allow_next(Key).to receive(:post_create_hook).and_return(true) allow_next(Key).to receive(:post_create_hook).and_return(true)
expect_execution_of(Git::ProcessRefChangesService) expect(Git::ProcessRefChangesService).to get_executed
end end
it 'calls SystemHooksService' do it 'calls SystemHooksService' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment