diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-09 15:08:55 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-09 15:08:55 +0300 |
commit | ea054ec1c398c2903820284df597ccbd14ec2319 (patch) | |
tree | c8fee7ccbc73ab07534b0a0c452019c805758d2d /app/services/integrations | |
parent | d9f331328ab89d8423cb43ee9103f2a39b473d7f (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/integrations')
-rw-r--r-- | app/services/integrations/test/base_service.rb | 36 | ||||
-rw-r--r-- | app/services/integrations/test/project_service.rb | 47 |
2 files changed, 83 insertions, 0 deletions
diff --git a/app/services/integrations/test/base_service.rb b/app/services/integrations/test/base_service.rb new file mode 100644 index 00000000000..a8a027092d5 --- /dev/null +++ b/app/services/integrations/test/base_service.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module Integrations + module Test + class BaseService + include BaseServiceUtility + + attr_accessor :integration, :current_user, :event + + # @param integration [Service] The external service that will be called + # @param current_user [User] The user calling the service + # @param event [String/nil] The event that triggered this + def initialize(integration, current_user, event = nil) + @integration = integration + @current_user = current_user + @event = event + end + + def execute + if event && (integration.supported_events.exclude?(event) || data.blank?) + return error('Testing not available for this event') + end + + return error(data[:error]) if data[:error].present? + + integration.test(data) + end + + private + + def data + raise NotImplementedError + end + end + end +end diff --git a/app/services/integrations/test/project_service.rb b/app/services/integrations/test/project_service.rb new file mode 100644 index 00000000000..941d70c2cc4 --- /dev/null +++ b/app/services/integrations/test/project_service.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +module Integrations + module Test + class ProjectService < Integrations::Test::BaseService + include Integrations::ProjectTestData + include Gitlab::Utils::StrongMemoize + + def project + strong_memoize(:project) do + integration.project + end + end + + private + + def data + strong_memoize(:data) do + next pipeline_events_data if integration.is_a?(::PipelinesEmailService) + + case event + when 'push', 'tag_push' + push_events_data + when 'note', 'confidential_note' + note_events_data + when 'issue', 'confidential_issue' + issues_events_data + when 'merge_request' + merge_requests_events_data + when 'job' + job_events_data + when 'pipeline' + pipeline_events_data + when 'wiki_page' + wiki_page_events_data + when 'deployment' + deployment_events_data + else + push_events_data + end + end + end + end + end +end + +Integrations::Test::ProjectService.prepend_if_ee('::EE::Integrations::Test::ProjectService') |