summaryrefslogtreecommitdiff
path: root/app/services/integrations
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 11:18:50 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 11:18:50 +0000
commit8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch)
treea77e7fe7a93de11213032ed4ab1f33a3db51b738 /app/services/integrations
parent00b35af3db1abfe813a778f643dad221aad51fca (diff)
downloadgitlab-ce-8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781.tar.gz
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'app/services/integrations')
-rw-r--r--app/services/integrations/test/base_service.rb36
-rw-r--r--app/services/integrations/test/project_service.rb47
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')