diff options
30 files changed, 17 insertions, 147 deletions
diff --git a/app/helpers/services_helper.rb b/app/helpers/services_helper.rb index 790ea446e67..715e5893a2c 100644 --- a/app/helpers/services_helper.rb +++ b/app/helpers/services_helper.rb @@ -26,4 +26,6 @@ module ServicesHelper event = event.pluralize if %w[merge_request issue confidential_issue].include?(event) "#{event}_events" end + + extend self end diff --git a/app/models/project_services/asana_service.rb b/app/models/project_services/asana_service.rb index 20cf7dc4632..3728f5642e4 100644 --- a/app/models/project_services/asana_service.rb +++ b/app/models/project_services/asana_service.rb @@ -48,10 +48,6 @@ http://app.asana.com/-/account_api' %w(push) end - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end - def client @_client ||= begin Asana::Client.new do |c| diff --git a/app/models/project_services/assembla_service.rb b/app/models/project_services/assembla_service.rb index f18d2204e0e..aeeff8917bf 100644 --- a/app/models/project_services/assembla_service.rb +++ b/app/models/project_services/assembla_service.rb @@ -27,10 +27,6 @@ class AssemblaService < Service %w(push) end - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end - def execute(data) return unless supported_events.include?(data[:object_kind]) diff --git a/app/models/project_services/bamboo_service.rb b/app/models/project_services/bamboo_service.rb index fe95fc14525..400020ee04a 100644 --- a/app/models/project_services/bamboo_service.rb +++ b/app/models/project_services/bamboo_service.rb @@ -56,10 +56,6 @@ class BambooService < CiService ] end - def self.supported_events - %w(push) - end - def build_page(sha, ref) with_reactive_cache(sha, ref) {|cached| cached[:build_page] } end diff --git a/app/models/project_services/bugzilla_service.rb b/app/models/project_services/bugzilla_service.rb index 18c0cdf2db8..046e2809f45 100644 --- a/app/models/project_services/bugzilla_service.rb +++ b/app/models/project_services/bugzilla_service.rb @@ -22,12 +22,4 @@ class BugzillaService < IssueTrackerService def self.to_param 'bugzilla' end - - def self.supported_events - %w() - end - - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end end diff --git a/app/models/project_services/buildkite_service.rb b/app/models/project_services/buildkite_service.rb index 94bc179deca..0956c4a4ede 100644 --- a/app/models/project_services/buildkite_service.rb +++ b/app/models/project_services/buildkite_service.rb @@ -24,14 +24,6 @@ class BuildkiteService < CiService hook.save end - def self.supported_events - %w(push) - end - - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end - def execute(data) return unless supported_events.include?(data[:object_kind]) diff --git a/app/models/project_services/builds_email_service.rb b/app/models/project_services/builds_email_service.rb index 51c07f731ff..ebd21e37189 100644 --- a/app/models/project_services/builds_email_service.rb +++ b/app/models/project_services/builds_email_service.rb @@ -27,10 +27,6 @@ class BuildsEmailService < Service %w(build) end - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end - def execute(push_data) return unless supported_events.include?(push_data[:object_kind]) return unless should_build_be_notified?(push_data) diff --git a/app/models/project_services/campfire_service.rb b/app/models/project_services/campfire_service.rb index 52371cde201..0de59af5652 100644 --- a/app/models/project_services/campfire_service.rb +++ b/app/models/project_services/campfire_service.rb @@ -28,10 +28,6 @@ class CampfireService < Service %w(push) end - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end - def execute(data) return unless supported_events.include?(data[:object_kind]) diff --git a/app/models/project_services/ci_service.rb b/app/models/project_services/ci_service.rb index 9b470c3a078..82979c8bd34 100644 --- a/app/models/project_services/ci_service.rb +++ b/app/models/project_services/ci_service.rb @@ -12,9 +12,6 @@ class CiService < Service %w(push) end - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end # Return complete url to build page # # Ex. diff --git a/app/models/project_services/custom_issue_tracker_service.rb b/app/models/project_services/custom_issue_tracker_service.rb index 9c5c86b1cc9..dea915a4d05 100644 --- a/app/models/project_services/custom_issue_tracker_service.rb +++ b/app/models/project_services/custom_issue_tracker_service.rb @@ -36,12 +36,4 @@ class CustomIssueTrackerService < IssueTrackerService { type: 'text', name: 'new_issue_url', placeholder: 'New Issue url' } ] end - - def self.supported_events - %w() - end - - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end end diff --git a/app/models/project_services/emails_on_push_service.rb b/app/models/project_services/emails_on_push_service.rb index 23dc0bc3790..f4f913ee0b6 100644 --- a/app/models/project_services/emails_on_push_service.rb +++ b/app/models/project_services/emails_on_push_service.rb @@ -20,10 +20,6 @@ class EmailsOnPushService < Service %w(push tag_push) end - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end - def execute(push_data) return unless supported_events.include?(push_data[:object_kind]) diff --git a/app/models/project_services/external_wiki_service.rb b/app/models/project_services/external_wiki_service.rb index 961b1c19a33..bdf6fa6a586 100644 --- a/app/models/project_services/external_wiki_service.rb +++ b/app/models/project_services/external_wiki_service.rb @@ -33,8 +33,4 @@ class ExternalWikiService < Service def self.supported_events %w() end - - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end end diff --git a/app/models/project_services/flowdock_service.rb b/app/models/project_services/flowdock_service.rb index 00a15d12efa..10a13c3fbdc 100644 --- a/app/models/project_services/flowdock_service.rb +++ b/app/models/project_services/flowdock_service.rb @@ -26,10 +26,6 @@ class FlowdockService < Service %w(push) end - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end - def execute(data) return unless supported_events.include?(data[:object_kind]) diff --git a/app/models/project_services/gemnasium_service.rb b/app/models/project_services/gemnasium_service.rb index b70d74e75c1..f271e1f1739 100644 --- a/app/models/project_services/gemnasium_service.rb +++ b/app/models/project_services/gemnasium_service.rb @@ -27,10 +27,6 @@ class GemnasiumService < Service %w(push) end - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end - def execute(data) return unless supported_events.include?(data[:object_kind]) diff --git a/app/models/project_services/hipchat_service.rb b/app/models/project_services/hipchat_service.rb index a675a857b06..72da219df28 100644 --- a/app/models/project_services/hipchat_service.rb +++ b/app/models/project_services/hipchat_service.rb @@ -49,10 +49,6 @@ class HipchatService < Service %w(push issue confidential_issue merge_request note tag_push build) end - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end - def execute(data) return unless supported_events.include?(data[:object_kind]) message = create_message(data) diff --git a/app/models/project_services/irker_service.rb b/app/models/project_services/irker_service.rb index 9a0cbcbca2d..5d93064f9b3 100644 --- a/app/models/project_services/irker_service.rb +++ b/app/models/project_services/irker_service.rb @@ -25,10 +25,6 @@ class IrkerService < Service %w(push) end - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end - def execute(data) return unless supported_events.include?(data[:object_kind]) diff --git a/app/models/project_services/jira_service.rb b/app/models/project_services/jira_service.rb index 46291f2dcc0..2ac76e97de0 100644 --- a/app/models/project_services/jira_service.rb +++ b/app/models/project_services/jira_service.rb @@ -16,10 +16,6 @@ class JiraService < IssueTrackerService %w(commit merge_request) end - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end - # {PROJECT-KEY}-{NUMBER} Examples: JIRA-1, PROJECT-1 def reference_pattern @reference_pattern ||= %r{(?<issue>\b([A-Z][A-Z0-9_]+-)\d+)} diff --git a/app/models/project_services/kubernetes_service.rb b/app/models/project_services/kubernetes_service.rb index e4d5f04d1fd..fa3cedc4354 100644 --- a/app/models/project_services/kubernetes_service.rb +++ b/app/models/project_services/kubernetes_service.rb @@ -158,14 +158,6 @@ class KubernetesService < DeploymentService opts end - def self.supported_events - %w() - end - - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end - def kubeclient_auth_options { bearer_token: token } end diff --git a/app/models/project_services/mattermost_service.rb b/app/models/project_services/mattermost_service.rb index 939dfea0988..c5c551b3ef5 100644 --- a/app/models/project_services/mattermost_service.rb +++ b/app/models/project_services/mattermost_service.rb @@ -38,12 +38,4 @@ class MattermostService < ChatNotificationService def default_channel_placeholder "#town-square" end - - def self.supported_events - %w() - end - - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end end diff --git a/app/models/project_services/mattermost_slash_commands_service.rb b/app/models/project_services/mattermost_slash_commands_service.rb index f25de22e67f..50a011db74e 100644 --- a/app/models/project_services/mattermost_slash_commands_service.rb +++ b/app/models/project_services/mattermost_slash_commands_service.rb @@ -48,12 +48,4 @@ class MattermostSlashCommandsService < ChatSlashCommandsService method: 'P', username: 'GitLab') end - - def self.supported_events - %w() - end - - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end end diff --git a/app/models/project_services/pipelines_email_service.rb b/app/models/project_services/pipelines_email_service.rb index fdfd0119228..ac617f409d9 100644 --- a/app/models/project_services/pipelines_email_service.rb +++ b/app/models/project_services/pipelines_email_service.rb @@ -23,10 +23,6 @@ class PipelinesEmailService < Service %w[pipeline] end - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end - def execute(data, force: false) return unless supported_events.include?(data[:object_kind]) return unless force || should_pipeline_be_notified?(data) diff --git a/app/models/project_services/pivotaltracker_service.rb b/app/models/project_services/pivotaltracker_service.rb index 6e19cd8ddd3..9cc642591f4 100644 --- a/app/models/project_services/pivotaltracker_service.rb +++ b/app/models/project_services/pivotaltracker_service.rb @@ -38,10 +38,6 @@ class PivotaltrackerService < Service %w(push) end - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end - def execute(data) return unless supported_events.include?(data[:object_kind]) return unless allowed_branch?(data[:ref]) diff --git a/app/models/project_services/pushover_service.rb b/app/models/project_services/pushover_service.rb index 223054c1d55..a963d27a376 100644 --- a/app/models/project_services/pushover_service.rb +++ b/app/models/project_services/pushover_service.rb @@ -65,10 +65,6 @@ class PushoverService < Service %w(push) end - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end - def execute(data) return unless supported_events.include?(data[:object_kind]) diff --git a/app/models/project_services/redmine_service.rb b/app/models/project_services/redmine_service.rb index 1b835afc678..6acf611eba5 100644 --- a/app/models/project_services/redmine_service.rb +++ b/app/models/project_services/redmine_service.rb @@ -22,12 +22,4 @@ class RedmineService < IssueTrackerService def self.to_param 'redmine' end - - def self.supported_events - %w() - end - - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end end diff --git a/app/models/project_services/slack_service.rb b/app/models/project_services/slack_service.rb index a7a7390ac93..f77d2d7c60b 100644 --- a/app/models/project_services/slack_service.rb +++ b/app/models/project_services/slack_service.rb @@ -37,12 +37,4 @@ class SlackService < ChatNotificationService def default_channel_placeholder "#general" end - - def self.supported_events - %w() - end - - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end end diff --git a/app/models/project_services/slack_slash_commands_service.rb b/app/models/project_services/slack_slash_commands_service.rb index b66570c2ece..c34991e4262 100644 --- a/app/models/project_services/slack_slash_commands_service.rb +++ b/app/models/project_services/slack_slash_commands_service.rb @@ -25,12 +25,4 @@ class SlackSlashCommandsService < ChatSlashCommandsService def format(text) Slack::Notifier::LinkFormatter.format(text) if text end - - def self.supported_events - %w() - end - - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end end diff --git a/app/models/project_services/teamcity_service.rb b/app/models/project_services/teamcity_service.rb index b958333ca45..cbaffb8ce48 100644 --- a/app/models/project_services/teamcity_service.rb +++ b/app/models/project_services/teamcity_service.rb @@ -47,14 +47,6 @@ class TeamcityService < CiService 'teamcity' end - def self.supported_events - %w(push) - end - - def self.event_names - self.supported_events.map { |event| "#{event}_events" } - end - def fields [ { type: 'text', name: 'teamcity_url', diff --git a/app/models/service.rb b/app/models/service.rb index df8d9a85041..043be222f3a 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -79,6 +79,10 @@ class Service < ActiveRecord::Base self.class.to_param end + def self.to_param + raise NotImplementedError + end + def fields # implement inside child [] @@ -93,10 +97,13 @@ class Service < ActiveRecord::Base end def event_names - # implement inside child self.class.event_names end + def self.event_names + self.supported_events.map { |event| "#{event}_events" } + end + def event_field(event) nil end @@ -109,6 +116,10 @@ class Service < ActiveRecord::Base self.class.supported_events end + def self.supported_events + %w(push tag_push issue confidential_issue merge_request wiki_page) + end + def execute(data) # implement inside child end diff --git a/lib/api/services.rb b/lib/api/services.rb index 907f80db438..a0abec49438 100644 --- a/lib/api/services.rb +++ b/lib/api/services.rb @@ -600,12 +600,11 @@ module API service_classes.each do |service| event_names = service.try(:event_names) || [] event_names.each do |event_name| - services[service.to_param.gsub("_", "-")] << { + services[service.to_param.tr("_", "-")] << { required: false, name: event_name.to_sym, type: String, - desc: ServicesHelper.instance_method(:service_event_description) - .bind(self).call(event_name) + desc: ServicesHelper.service_event_description(event_name) } end end diff --git a/spec/controllers/projects/services_controller_spec.rb b/spec/controllers/projects/services_controller_spec.rb index 2e44b5128b4..a6e708c01e4 100644 --- a/spec/controllers/projects/services_controller_spec.rb +++ b/spec/controllers/projects/services_controller_spec.rb @@ -54,6 +54,7 @@ describe Projects::ServicesController do context 'on successful update' do it 'sets the flash' do expect(service).to receive(:to_param).and_return('hipchat') + expect(service).to receive(:event_names).and_return(HipchatService.event_names) put :update, namespace_id: project.namespace.id, |