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