summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/helpers/services_helper.rb18
-rw-r--r--app/models/project_services/asana_service.rb8
-rw-r--r--app/models/project_services/assembla_service.rb8
-rw-r--r--app/models/project_services/bamboo_service.rb4
-rw-r--r--app/models/project_services/bugzilla_service.rb10
-rw-r--r--app/models/project_services/buildkite_service.rb8
-rw-r--r--app/models/project_services/builds_email_service.rb8
-rw-r--r--app/models/project_services/campfire_service.rb8
-rw-r--r--app/models/project_services/chat_notification_service.rb2
-rw-r--r--app/models/project_services/chat_slash_commands_service.rb4
-rw-r--r--app/models/project_services/ci_service.rb5
-rw-r--r--app/models/project_services/custom_issue_tracker_service.rb10
-rw-r--r--app/models/project_services/deployment_service.rb4
-rw-r--r--app/models/project_services/drone_ci_service.rb4
-rw-r--r--app/models/project_services/emails_on_push_service.rb8
-rw-r--r--app/models/project_services/external_wiki_service.rb10
-rw-r--r--app/models/project_services/flowdock_service.rb8
-rw-r--r--app/models/project_services/gemnasium_service.rb8
-rw-r--r--app/models/project_services/gitlab_issue_tracker_service.rb2
-rw-r--r--app/models/project_services/hipchat_service.rb8
-rw-r--r--app/models/project_services/irker_service.rb8
-rw-r--r--app/models/project_services/issue_tracker_service.rb2
-rw-r--r--app/models/project_services/jira_service.rb8
-rw-r--r--app/models/project_services/kubernetes_service.rb10
-rw-r--r--app/models/project_services/mattermost_service.rb10
-rw-r--r--app/models/project_services/mattermost_slash_commands_service.rb10
-rw-r--r--app/models/project_services/pipelines_email_service.rb8
-rw-r--r--app/models/project_services/pivotaltracker_service.rb8
-rw-r--r--app/models/project_services/pushover_service.rb8
-rw-r--r--app/models/project_services/redmine_service.rb10
-rw-r--r--app/models/project_services/slack_service.rb10
-rw-r--r--app/models/project_services/slack_slash_commands_service.rb10
-rw-r--r--app/models/project_services/teamcity_service.rb8
-rw-r--r--app/models/service.rb6
-rw-r--r--changelogs/unreleased/22974-trigger-service-events-through-api.yml4
-rw-r--r--lib/api/services.rb49
-rw-r--r--spec/requests/api/services_spec.rb11
37 files changed, 259 insertions, 66 deletions
diff --git a/app/helpers/services_helper.rb b/app/helpers/services_helper.rb
index 9bab140e60a..790ea446e67 100644
--- a/app/helpers/services_helper.rb
+++ b/app/helpers/services_helper.rb
@@ -1,23 +1,23 @@
module ServicesHelper
def service_event_description(event)
case event
- when "push"
+ when "push", "push_events"
"Event will be triggered by a push to the repository"
- when "tag_push"
+ when "tag_push", "tag_push_events"
"Event will be triggered when a new tag is pushed to the repository"
- when "note"
+ when "note", "note_events"
"Event will be triggered when someone adds a comment"
- when "issue"
+ when "issue", "issue_events"
"Event will be triggered when an issue is created/updated/closed"
- when "confidential_issue"
+ when "confidential_issue", "confidential_issue_events"
"Event will be triggered when a confidential issue is created/updated/closed"
- when "merge_request"
+ when "merge_request", "merge_request_events"
"Event will be triggered when a merge request is created/updated/merged"
- when "build"
+ when "build", "build_events"
"Event will be triggered when a build status changes"
- when "wiki_page"
+ when "wiki_page", "wiki_page_events"
"Event will be triggered when a wiki page is created/updated"
- when "commit"
+ when "commit", "commit_events"
"Event will be triggered when a commit is created/updated"
end
end
diff --git a/app/models/project_services/asana_service.rb b/app/models/project_services/asana_service.rb
index 7c23b766763..20cf7dc4632 100644
--- a/app/models/project_services/asana_service.rb
+++ b/app/models/project_services/asana_service.rb
@@ -25,7 +25,7 @@ You can create a Personal Access Token here:
http://app.asana.com/-/account_api'
end
- def to_param
+ def self.to_param
'asana'
end
@@ -44,10 +44,14 @@ http://app.asana.com/-/account_api'
]
end
- def supported_events
+ def self.supported_events
%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 d839221d315..f18d2204e0e 100644
--- a/app/models/project_services/assembla_service.rb
+++ b/app/models/project_services/assembla_service.rb
@@ -12,7 +12,7 @@ class AssemblaService < Service
'Project Management Software (Source Commits Endpoint)'
end
- def to_param
+ def self.to_param
'assembla'
end
@@ -23,10 +23,14 @@ class AssemblaService < Service
]
end
- def supported_events
+ 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/bamboo_service.rb b/app/models/project_services/bamboo_service.rb
index 4819bdbef8c..fe95fc14525 100644
--- a/app/models/project_services/bamboo_service.rb
+++ b/app/models/project_services/bamboo_service.rb
@@ -40,7 +40,7 @@ class BambooService < CiService
'You must set up automatic revision labeling and a repository trigger in Bamboo.'
end
- def to_param
+ def self.to_param
'bamboo'
end
@@ -56,7 +56,7 @@ class BambooService < CiService
]
end
- def supported_events
+ def self.supported_events
%w(push)
end
diff --git a/app/models/project_services/bugzilla_service.rb b/app/models/project_services/bugzilla_service.rb
index 338e685339a..18c0cdf2db8 100644
--- a/app/models/project_services/bugzilla_service.rb
+++ b/app/models/project_services/bugzilla_service.rb
@@ -19,7 +19,15 @@ class BugzillaService < IssueTrackerService
end
end
- def to_param
+ 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 e77942d8f3c..94bc179deca 100644
--- a/app/models/project_services/buildkite_service.rb
+++ b/app/models/project_services/buildkite_service.rb
@@ -24,10 +24,14 @@ class BuildkiteService < CiService
hook.save
end
- def supported_events
+ 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])
@@ -54,7 +58,7 @@ class BuildkiteService < CiService
'Continuous integration and deployments'
end
- def to_param
+ def self.to_param
'buildkite'
end
diff --git a/app/models/project_services/builds_email_service.rb b/app/models/project_services/builds_email_service.rb
index 201b94b065b..51c07f731ff 100644
--- a/app/models/project_services/builds_email_service.rb
+++ b/app/models/project_services/builds_email_service.rb
@@ -19,14 +19,18 @@ class BuildsEmailService < Service
'Email the builds status to a list of recipients.'
end
- def to_param
+ def self.to_param
'builds_email'
end
- def supported_events
+ def self.supported_events
%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 5af93860d09..52371cde201 100644
--- a/app/models/project_services/campfire_service.rb
+++ b/app/models/project_services/campfire_service.rb
@@ -12,7 +12,7 @@ class CampfireService < Service
'Simple web-based real-time group chat'
end
- def to_param
+ def self.to_param
'campfire'
end
@@ -24,10 +24,14 @@ class CampfireService < Service
]
end
- def supported_events
+ 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/chat_notification_service.rb b/app/models/project_services/chat_notification_service.rb
index b7ef44c3054..c781c3fdb34 100644
--- a/app/models/project_services/chat_notification_service.rb
+++ b/app/models/project_services/chat_notification_service.rb
@@ -25,7 +25,7 @@ class ChatNotificationService < Service
valid?
end
- def supported_events
+ def self.supported_events
%w[push issue confidential_issue merge_request note tag_push
build pipeline wiki_page]
end
diff --git a/app/models/project_services/chat_slash_commands_service.rb b/app/models/project_services/chat_slash_commands_service.rb
index 0bc160af604..2bcff541cc0 100644
--- a/app/models/project_services/chat_slash_commands_service.rb
+++ b/app/models/project_services/chat_slash_commands_service.rb
@@ -13,8 +13,8 @@ class ChatSlashCommandsService < Service
ActiveSupport::SecurityUtils.variable_size_secure_compare(token, self.token)
end
- def supported_events
- []
+ def self.supported_events
+ %w()
end
def can_test?
diff --git a/app/models/project_services/ci_service.rb b/app/models/project_services/ci_service.rb
index 4de0106707e..9b470c3a078 100644
--- a/app/models/project_services/ci_service.rb
+++ b/app/models/project_services/ci_service.rb
@@ -8,10 +8,13 @@ class CiService < Service
self.respond_to?(:token) && self.token.present? && ActiveSupport::SecurityUtils.variable_size_secure_compare(token, self.token)
end
- def supported_events
+ def self.supported_events
%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 b2f426dc2ac..9c5c86b1cc9 100644
--- a/app/models/project_services/custom_issue_tracker_service.rb
+++ b/app/models/project_services/custom_issue_tracker_service.rb
@@ -23,7 +23,7 @@ class CustomIssueTrackerService < IssueTrackerService
end
end
- def to_param
+ def self.to_param
'custom_issue_tracker'
end
@@ -36,4 +36,12 @@ 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/deployment_service.rb b/app/models/project_services/deployment_service.rb
index ab353a1abe6..91a55514a9a 100644
--- a/app/models/project_services/deployment_service.rb
+++ b/app/models/project_services/deployment_service.rb
@@ -5,8 +5,8 @@
class DeploymentService < Service
default_value_for :category, 'deployment'
- def supported_events
- []
+ def self.supported_events
+ %w()
end
def predefined_variables
diff --git a/app/models/project_services/drone_ci_service.rb b/app/models/project_services/drone_ci_service.rb
index 4bbbebf54cb..0a217d8caba 100644
--- a/app/models/project_services/drone_ci_service.rb
+++ b/app/models/project_services/drone_ci_service.rb
@@ -32,7 +32,7 @@ class DroneCiService < CiService
true
end
- def supported_events
+ def self.supported_events
%w(push merge_request tag_push)
end
@@ -87,7 +87,7 @@ class DroneCiService < CiService
'Drone is a Continuous Integration platform built on Docker, written in Go'
end
- def to_param
+ def self.to_param
'drone_ci'
end
diff --git a/app/models/project_services/emails_on_push_service.rb b/app/models/project_services/emails_on_push_service.rb
index 79285cbd26d..23dc0bc3790 100644
--- a/app/models/project_services/emails_on_push_service.rb
+++ b/app/models/project_services/emails_on_push_service.rb
@@ -12,14 +12,18 @@ class EmailsOnPushService < Service
'Email the commits and diff of each push to a list of recipients.'
end
- def to_param
+ def self.to_param
'emails_on_push'
end
- def supported_events
+ def self.supported_events
%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 d7b6e505191..961b1c19a33 100644
--- a/app/models/project_services/external_wiki_service.rb
+++ b/app/models/project_services/external_wiki_service.rb
@@ -13,7 +13,7 @@ class ExternalWikiService < Service
'Replaces the link to the internal wiki with a link to an external wiki.'
end
- def to_param
+ def self.to_param
'external_wiki'
end
@@ -29,4 +29,12 @@ class ExternalWikiService < Service
nil
end
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/flowdock_service.rb b/app/models/project_services/flowdock_service.rb
index dd00275187f..00a15d12efa 100644
--- a/app/models/project_services/flowdock_service.rb
+++ b/app/models/project_services/flowdock_service.rb
@@ -12,7 +12,7 @@ class FlowdockService < Service
'Flowdock is a collaboration web app for technical teams.'
end
- def to_param
+ def self.to_param
'flowdock'
end
@@ -22,10 +22,14 @@ class FlowdockService < Service
]
end
- def supported_events
+ 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/gemnasium_service.rb b/app/models/project_services/gemnasium_service.rb
index 598aca5e06d..b70d74e75c1 100644
--- a/app/models/project_services/gemnasium_service.rb
+++ b/app/models/project_services/gemnasium_service.rb
@@ -12,7 +12,7 @@ class GemnasiumService < Service
'Gemnasium monitors your project dependencies and alerts you about updates and security vulnerabilities.'
end
- def to_param
+ def self.to_param
'gemnasium'
end
@@ -23,10 +23,14 @@ class GemnasiumService < Service
]
end
- def supported_events
+ 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/gitlab_issue_tracker_service.rb b/app/models/project_services/gitlab_issue_tracker_service.rb
index 6bd8d4ec568..ad4eb9536e1 100644
--- a/app/models/project_services/gitlab_issue_tracker_service.rb
+++ b/app/models/project_services/gitlab_issue_tracker_service.rb
@@ -7,7 +7,7 @@ class GitlabIssueTrackerService < IssueTrackerService
default_value_for :default, true
- def to_param
+ def self.to_param
'gitlab'
end
diff --git a/app/models/project_services/hipchat_service.rb b/app/models/project_services/hipchat_service.rb
index 915f6fed74c..a675a857b06 100644
--- a/app/models/project_services/hipchat_service.rb
+++ b/app/models/project_services/hipchat_service.rb
@@ -27,7 +27,7 @@ class HipchatService < Service
'Private group chat and IM'
end
- def to_param
+ def self.to_param
'hipchat'
end
@@ -45,10 +45,14 @@ class HipchatService < Service
]
end
- def supported_events
+ def self.supported_events
%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 7355918feab..9a0cbcbca2d 100644
--- a/app/models/project_services/irker_service.rb
+++ b/app/models/project_services/irker_service.rb
@@ -17,14 +17,18 @@ class IrkerService < Service
'gateway.'
end
- def to_param
+ def self.to_param
'irker'
end
- def supported_events
+ 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/issue_tracker_service.rb b/app/models/project_services/issue_tracker_service.rb
index bce2cdd5516..9e65fdbf9d6 100644
--- a/app/models/project_services/issue_tracker_service.rb
+++ b/app/models/project_services/issue_tracker_service.rb
@@ -57,7 +57,7 @@ class IssueTrackerService < Service
end
end
- def supported_events
+ def self.supported_events
%w(push)
end
diff --git a/app/models/project_services/jira_service.rb b/app/models/project_services/jira_service.rb
index 2d969d2fcb6..46291f2dcc0 100644
--- a/app/models/project_services/jira_service.rb
+++ b/app/models/project_services/jira_service.rb
@@ -12,10 +12,14 @@ class JiraService < IssueTrackerService
# This is confusing, but JiraService does not really support these events.
# The values here are required to display correct options in the service
# configuration screen.
- def supported_events
+ def self.supported_events
%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+)}
@@ -81,7 +85,7 @@ class JiraService < IssueTrackerService
end
end
- def to_param
+ def self.to_param
'jira'
end
diff --git a/app/models/project_services/kubernetes_service.rb b/app/models/project_services/kubernetes_service.rb
index 085125ca9dc..e4d5f04d1fd 100644
--- a/app/models/project_services/kubernetes_service.rb
+++ b/app/models/project_services/kubernetes_service.rb
@@ -52,7 +52,7 @@ class KubernetesService < DeploymentService
'deployments with `app=$CI_ENVIRONMENT_SLUG`'
end
- def to_param
+ def self.to_param
'kubernetes'
end
@@ -158,6 +158,14 @@ 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 ee8a0b55275..939dfea0988 100644
--- a/app/models/project_services/mattermost_service.rb
+++ b/app/models/project_services/mattermost_service.rb
@@ -7,7 +7,7 @@ class MattermostService < ChatNotificationService
'Receive event notifications in Mattermost'
end
- def to_param
+ def self.to_param
'mattermost'
end
@@ -38,4 +38,12 @@ 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 2cb481182d7..f25de22e67f 100644
--- a/app/models/project_services/mattermost_slash_commands_service.rb
+++ b/app/models/project_services/mattermost_slash_commands_service.rb
@@ -15,7 +15,7 @@ class MattermostSlashCommandsService < ChatSlashCommandsService
"Perform common operations on GitLab in Mattermost"
end
- def to_param
+ def self.to_param
'mattermost_slash_commands'
end
@@ -48,4 +48,12 @@ 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 745f9bd1b43..fdfd0119228 100644
--- a/app/models/project_services/pipelines_email_service.rb
+++ b/app/models/project_services/pipelines_email_service.rb
@@ -15,14 +15,18 @@ class PipelinesEmailService < Service
'Email the pipelines status to a list of recipients.'
end
- def to_param
+ def self.to_param
'pipelines_email'
end
- def supported_events
+ def self.supported_events
%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 5301f9fa0ff..6e19cd8ddd3 100644
--- a/app/models/project_services/pivotaltracker_service.rb
+++ b/app/models/project_services/pivotaltracker_service.rb
@@ -14,7 +14,7 @@ class PivotaltrackerService < Service
'Project Management Software (Source Commits Endpoint)'
end
- def to_param
+ def self.to_param
'pivotaltracker'
end
@@ -34,10 +34,14 @@ class PivotaltrackerService < Service
]
end
- def supported_events
+ 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])
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 3dd878e4c7d..223054c1d55 100644
--- a/app/models/project_services/pushover_service.rb
+++ b/app/models/project_services/pushover_service.rb
@@ -13,7 +13,7 @@ class PushoverService < Service
'Pushover makes it easy to get real-time notifications on your Android device, iPhone, iPad, and Desktop.'
end
- def to_param
+ def self.to_param
'pushover'
end
@@ -61,10 +61,14 @@ class PushoverService < Service
]
end
- def supported_events
+ 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/redmine_service.rb b/app/models/project_services/redmine_service.rb
index f9da273cf08..1b835afc678 100644
--- a/app/models/project_services/redmine_service.rb
+++ b/app/models/project_services/redmine_service.rb
@@ -19,7 +19,15 @@ class RedmineService < IssueTrackerService
end
end
- def to_param
+ 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 76d233a3cca..a7a7390ac93 100644
--- a/app/models/project_services/slack_service.rb
+++ b/app/models/project_services/slack_service.rb
@@ -7,7 +7,7 @@ class SlackService < ChatNotificationService
'Receive event notifications in Slack'
end
- def to_param
+ def self.to_param
'slack'
end
@@ -37,4 +37,12 @@ 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 5a7cc0fb329..b66570c2ece 100644
--- a/app/models/project_services/slack_slash_commands_service.rb
+++ b/app/models/project_services/slack_slash_commands_service.rb
@@ -9,7 +9,7 @@ class SlackSlashCommandsService < ChatSlashCommandsService
"Perform common operations on GitLab in Slack"
end
- def to_param
+ def self.to_param
'slack_slash_commands'
end
@@ -25,4 +25,12 @@ 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 6726082048f..b958333ca45 100644
--- a/app/models/project_services/teamcity_service.rb
+++ b/app/models/project_services/teamcity_service.rb
@@ -43,14 +43,18 @@ class TeamcityService < CiService
'requests build, that setting is in the vsc root advanced settings.'
end
- def to_param
+ def self.to_param
'teamcity'
end
- def supported_events
+ 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 19ef3ba9c23..df8d9a85041 100644
--- a/app/models/service.rb
+++ b/app/models/service.rb
@@ -76,6 +76,7 @@ class Service < ActiveRecord::Base
def to_param
# implement inside child
+ self.class.to_param
end
def fields
@@ -92,7 +93,8 @@ class Service < ActiveRecord::Base
end
def event_names
- supported_events.map { |event| "#{event}_events" }
+ # implement inside child
+ self.class.event_names
end
def event_field(event)
@@ -104,7 +106,7 @@ class Service < ActiveRecord::Base
end
def supported_events
- %w(push tag_push issue confidential_issue merge_request wiki_page)
+ self.class.supported_events
end
def execute(data)
diff --git a/changelogs/unreleased/22974-trigger-service-events-through-api.yml b/changelogs/unreleased/22974-trigger-service-events-through-api.yml
new file mode 100644
index 00000000000..57106e8c676
--- /dev/null
+++ b/changelogs/unreleased/22974-trigger-service-events-through-api.yml
@@ -0,0 +1,4 @@
+---
+title: Adds service trigger events to api
+merge_request: 8324
+author:
diff --git a/lib/api/services.rb b/lib/api/services.rb
index 3a9dfbb237c..907f80db438 100644
--- a/lib/api/services.rb
+++ b/lib/api/services.rb
@@ -145,7 +145,7 @@ module API
name: :room,
type: String,
desc: 'Campfire room'
- },
+ }
],
'custom-issue-tracker' => [
{
@@ -534,7 +534,36 @@ module API
desc: 'The password of the user'
}
]
- }.freeze
+ }
+
+ service_classes = [
+ AsanaService,
+ AssemblaService,
+ BambooService,
+ BugzillaService,
+ BuildkiteService,
+ BuildsEmailService,
+ CampfireService,
+ CustomIssueTrackerService,
+ DroneCiService,
+ EmailsOnPushService,
+ ExternalWikiService,
+ FlowdockService,
+ GemnasiumService,
+ HipchatService,
+ IrkerService,
+ JiraService,
+ KubernetesService,
+ MattermostSlashCommandsService,
+ SlackSlashCommandsService,
+ PipelinesEmailService,
+ PivotaltrackerService,
+ PushoverService,
+ RedmineService,
+ SlackService,
+ MattermostService,
+ TeamcityService,
+ ].freeze
trigger_services = {
'mattermost-slash-commands' => [
@@ -568,6 +597,20 @@ module API
services.each do |service_slug, settings|
desc "Set #{service_slug} service for project"
params do
+ service_classes.each do |service|
+ event_names = service.try(:event_names) || []
+ event_names.each do |event_name|
+ services[service.to_param.gsub("_", "-")] << {
+ required: false,
+ name: event_name.to_sym,
+ type: String,
+ desc: ServicesHelper.instance_method(:service_event_description)
+ .bind(self).call(event_name)
+ }
+ end
+ end
+ services.freeze
+
settings.each do |setting|
if setting[:required]
requires setting[:name], type: setting[:type], desc: setting[:desc]
@@ -581,7 +624,7 @@ module API
service_params = declared_params(include_missing: false).merge(active: true)
if service.update_attributes(service_params)
- true
+ present service, with: Entities::ProjectService, include_passwords: current_user.is_admin?
else
render_api_error!('400 Bad Request', 400)
end
diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb
index 39c9e0505d1..776dc655650 100644
--- a/spec/requests/api/services_spec.rb
+++ b/spec/requests/api/services_spec.rb
@@ -6,7 +6,7 @@ describe API::Services, api: true do
let(:user) { create(:user) }
let(:admin) { create(:admin) }
let(:user2) { create(:user) }
- let(:project) {create(:empty_project, creator_id: user.id, namespace: user.namespace) }
+ let(:project) { create(:empty_project, creator_id: user.id, namespace: user.namespace) }
Service.available_services_names.each do |service|
describe "PUT /projects/:id/services/#{service.dasherize}" do
@@ -16,6 +16,15 @@ describe API::Services, api: true do
put api("/projects/#{project.id}/services/#{dashed_service}", user), service_attrs
expect(response).to have_http_status(200)
+
+ current_service = project.services.first
+ event = current_service.event_names.empty? ? "foo" : current_service.event_names.first
+ state = current_service[event] || false
+
+ put api("/projects/#{project.id}/services/#{dashed_service}?#{event}=#{!state}", user), service_attrs
+
+ expect(response).to have_http_status(200)
+ expect(project.services.first[event]).not_to eq(state) unless event == "foo"
end
it "returns if required fields missing" do