Commit d57e809c authored by Douwe Maan's avatar Douwe Maan

Set supported events per project service.

parent 85fa334e
...@@ -65,9 +65,12 @@ automatically inspected. Leave blank to include all branches.' ...@@ -65,9 +65,12 @@ automatically inspected. Leave blank to include all branches.'
] ]
end end
def supported_events
%w(push)
end
def execute(data) def execute(data)
object_kind = data[:object_kind] return unless supported_events.include?(data[:object_kind])
return unless object_kind == "push"
Asana.configure do |client| Asana.configure do |client|
client.api_key = api_key client.api_key = api_key
......
...@@ -42,9 +42,12 @@ class AssemblaService < Service ...@@ -42,9 +42,12 @@ class AssemblaService < Service
] ]
end end
def supported_events
%w(push)
end
def execute(data) def execute(data)
object_kind = data[:object_kind] return unless supported_events.include?(data[:object_kind])
return unless object_kind == "push"
url = "https://atlas.assembla.com/spaces/#{subdomain}/github_tool?secret_key=#{token}" url = "https://atlas.assembla.com/spaces/#{subdomain}/github_tool?secret_key=#{token}"
AssemblaService.post(url, body: { payload: data }.to_json, headers: { 'Content-Type' => 'application/json' }) AssemblaService.post(url, body: { payload: data }.to_json, headers: { 'Content-Type' => 'application/json' })
......
...@@ -73,6 +73,10 @@ class BambooService < CiService ...@@ -73,6 +73,10 @@ class BambooService < CiService
] ]
end end
def supported_events
%w(push)
end
def build_info(sha) def build_info(sha)
url = URI.parse("#{bamboo_url}/rest/api/latest/result?label=#{sha}") url = URI.parse("#{bamboo_url}/rest/api/latest/result?label=#{sha}")
...@@ -123,8 +127,7 @@ class BambooService < CiService ...@@ -123,8 +127,7 @@ class BambooService < CiService
end end
def execute(data) def execute(data)
object_kind = data[:object_kind] return unless supported_events.include?(data[:object_kind])
return unless object_kind == "push"
# Bamboo requires a GET and does not take any data. # Bamboo requires a GET and does not take any data.
self.class.get("#{bamboo_url}/updateAndBuild.action?buildKey=#{build_key}", self.class.get("#{bamboo_url}/updateAndBuild.action?buildKey=#{build_key}",
......
...@@ -36,9 +36,12 @@ class BuildboxService < CiService ...@@ -36,9 +36,12 @@ class BuildboxService < CiService
hook.save hook.save
end end
def supported_events
%w(push)
end
def execute(data) def execute(data)
object_kind = data[:object_kind] return unless supported_events.include?(data[:object_kind])
return unless object_kind == "push"
service_hook.execute(data) service_hook.execute(data)
end end
......
...@@ -41,9 +41,12 @@ class CampfireService < Service ...@@ -41,9 +41,12 @@ class CampfireService < Service
] ]
end end
def supported_events
%w(push)
end
def execute(data) def execute(data)
object_kind = data[:object_kind] return unless supported_events.include?(data[:object_kind])
return unless object_kind == "push"
room = gate.find_room_by_name(self.room) room = gate.find_room_by_name(self.room)
return true unless room return true unless room
......
...@@ -25,6 +25,10 @@ class CiService < Service ...@@ -25,6 +25,10 @@ class CiService < Service
:ci :ci
end end
def supported_events
%w(push)
end
# Return complete url to build page # Return complete url to build page
# #
# Ex. # Ex.
......
...@@ -33,9 +33,12 @@ class EmailsOnPushService < Service ...@@ -33,9 +33,12 @@ class EmailsOnPushService < Service
'emails_on_push' 'emails_on_push'
end end
def supported_events
%w(push)
end
def execute(data) def execute(data)
object_kind = data[:object_kind] return unless supported_events.include?(data[:object_kind])
return unless object_kind == "push"
EmailsOnPushWorker.perform_async(project_id, recipients, data) EmailsOnPushWorker.perform_async(project_id, recipients, data)
end end
......
...@@ -41,9 +41,12 @@ class FlowdockService < Service ...@@ -41,9 +41,12 @@ class FlowdockService < Service
] ]
end end
def supported_events
%w(push)
end
def execute(data) def execute(data)
object_kind = data[:object_kind] return unless supported_events.include?(data[:object_kind])
return unless object_kind == "push"
Flowdock::Git.post( Flowdock::Git.post(
data[:ref], data[:ref],
......
...@@ -42,9 +42,12 @@ class GemnasiumService < Service ...@@ -42,9 +42,12 @@ class GemnasiumService < Service
] ]
end end
def supported_events
%w(push)
end
def execute(data) def execute(data)
object_kind = data[:object_kind] return unless supported_events.include?(data[:object_kind])
return unless object_kind == "push"
Gemnasium::GitlabService.execute( Gemnasium::GitlabService.execute(
ref: data[:ref], ref: data[:ref],
......
...@@ -30,9 +30,12 @@ class GitlabCiService < CiService ...@@ -30,9 +30,12 @@ class GitlabCiService < CiService
hook.save hook.save
end end
def supported_events
%w(push tag_push)
end
def execute(data) def execute(data)
object_kind = data[:object_kind] return unless supported_events.include?(data[:object_kind])
return unless %w(push tag_push).include?(object_kind)
service_hook.execute(data) service_hook.execute(data)
end end
......
...@@ -44,9 +44,12 @@ class HipchatService < Service ...@@ -44,9 +44,12 @@ class HipchatService < Service
] ]
end end
def supported_events
%w(push)
end
def execute(data) def execute(data)
object_kind = data[:object_kind] return unless supported_events.include?(data[:object_kind])
return unless object_kind == "push"
gate[room].send('GitLab', create_message(data)) gate[room].send('GitLab', create_message(data))
end end
......
...@@ -69,9 +69,12 @@ class IssueTrackerService < Service ...@@ -69,9 +69,12 @@ class IssueTrackerService < Service
end end
end end
def supported_events
%w(push)
end
def execute(data) def execute(data)
object_kind = data[:object_kind] return unless supported_events.include?(data[:object_kind])
return unless object_kind == "push"
message = "#{self.type} was unable to reach #{self.project_url}. Check the url and try again." message = "#{self.type} was unable to reach #{self.project_url}. Check the url and try again."
result = false result = false
......
...@@ -41,9 +41,12 @@ class PivotaltrackerService < Service ...@@ -41,9 +41,12 @@ class PivotaltrackerService < Service
] ]
end end
def supported_events
%w(push)
end
def execute(data) def execute(data)
object_kind = data[:object_kind] return unless supported_events.include?(data[:object_kind])
return unless object_kind == "push"
url = 'https://www.pivotaltracker.com/services/v5/source_commits' url = 'https://www.pivotaltracker.com/services/v5/source_commits'
data[:commits].each do |commit| data[:commits].each do |commit|
......
...@@ -80,9 +80,12 @@ class PushoverService < Service ...@@ -80,9 +80,12 @@ class PushoverService < Service
] ]
end end
def supported_events
%w(push)
end
def execute(data) def execute(data)
object_kind = data[:object_kind] return unless supported_events.include?(data[:object_kind])
return unless object_kind == "push"
ref = data[:ref].gsub('refs/heads/', '') ref = data[:ref].gsub('refs/heads/', '')
before = data[:before] before = data[:before]
......
...@@ -42,7 +42,12 @@ class SlackService < Service ...@@ -42,7 +42,12 @@ class SlackService < Service
] ]
end end
def supported_events
%w(push issue merge_request)
end
def execute(data) def execute(data)
return unless supported_events.include?(data[:object_kind])
return unless webhook.present? return unless webhook.present?
object_kind = data[:object_kind] object_kind = data[:object_kind]
......
...@@ -61,6 +61,10 @@ class TeamcityService < CiService ...@@ -61,6 +61,10 @@ class TeamcityService < CiService
'teamcity' 'teamcity'
end end
def supported_events
%w(push)
end
def fields def fields
[ [
{ type: 'text', name: 'teamcity_url', { type: 'text', name: 'teamcity_url',
...@@ -120,8 +124,7 @@ class TeamcityService < CiService ...@@ -120,8 +124,7 @@ class TeamcityService < CiService
end end
def execute(data) def execute(data)
object_kind = data[:object_kind] return unless supported_events.include?(data[:object_kind])
return unless object_kind == "push"
auth = { auth = {
username: username, username: username,
......
...@@ -80,6 +80,10 @@ class Service < ActiveRecord::Base ...@@ -80,6 +80,10 @@ class Service < ActiveRecord::Base
[] []
end end
def supported_events
%w(push tag_push issue merge_request)
end
def execute def execute
# implement inside child # implement inside child
end end
...@@ -105,6 +109,8 @@ class Service < ActiveRecord::Base ...@@ -105,6 +109,8 @@ class Service < ActiveRecord::Base
end end
def async_execute(data) def async_execute(data)
return unless supported_events.include?(data[:object_kind])
Sidekiq::Client.enqueue(ProjectServiceWorker, id, data) Sidekiq::Client.enqueue(ProjectServiceWorker, id, data)
end end
......
...@@ -14,6 +14,43 @@ ...@@ -14,6 +14,43 @@
= preserve do = preserve do
= markdown @service.help = markdown @service.help
.form-group
= f.label :url, "Trigger", class: 'control-label'
- if @service.supported_events.length > 1
.col-sm-10
- if @service.supported_events.include?("push")
%div
= f.check_box :push_events, class: 'pull-left'
.prepend-left-20
= f.label :push_events, class: 'list-label' do
%strong Push events
%p.light
This url will be triggered by a push to the repository
- if @service.supported_events.include?("tag_push")
%div
= f.check_box :tag_push_events, class: 'pull-left'
.prepend-left-20
= f.label :tag_push_events, class: 'list-label' do
%strong Tag push events
%p.light
This url will be triggered when a new tag is pushed to the repository
- if @service.supported_events.include?("issue")
%div
= f.check_box :issues_events, class: 'pull-left'
.prepend-left-20
= f.label :issues_events, class: 'list-label' do
%strong Issues events
%p.light
This url will be triggered when an issue is created
- if @service.supported_events.include?("merge_request")
%div
= f.check_box :merge_requests_events, class: 'pull-left'
.prepend-left-20
= f.label :merge_requests_events, class: 'list-label' do
%strong Merge Request events
%p.light
This url will be triggered when a merge request is created
- @service.fields.each do |field| - @service.fields.each do |field|
- name = field[:name] - name = field[:name]
- value = @service.send(name) unless field[:type] == 'password' - value = @service.send(name) unless field[:type] == 'password'
......
...@@ -29,7 +29,9 @@ ...@@ -29,7 +29,9 @@
.form-group .form-group
= f.label :url, "Trigger", class: 'control-label' = f.label :url, "Trigger", class: 'control-label'
- if @service.supported_events.length > 1
.col-sm-10 .col-sm-10
- if @service.supported_events.include?("push")
%div %div
= f.check_box :push_events, class: 'pull-left' = f.check_box :push_events, class: 'pull-left'
.prepend-left-20 .prepend-left-20
...@@ -37,6 +39,7 @@ ...@@ -37,6 +39,7 @@
%strong Push events %strong Push events
%p.light %p.light
This url will be triggered by a push to the repository This url will be triggered by a push to the repository
- if @service.supported_events.include?("tag_push")
%div %div
= f.check_box :tag_push_events, class: 'pull-left' = f.check_box :tag_push_events, class: 'pull-left'
.prepend-left-20 .prepend-left-20
...@@ -44,6 +47,7 @@ ...@@ -44,6 +47,7 @@
%strong Tag push events %strong Tag push events
%p.light %p.light
This url will be triggered when a new tag is pushed to the repository This url will be triggered when a new tag is pushed to the repository
- if @service.supported_events.include?("issue")
%div %div
= f.check_box :issues_events, class: 'pull-left' = f.check_box :issues_events, class: 'pull-left'
.prepend-left-20 .prepend-left-20
...@@ -51,6 +55,7 @@ ...@@ -51,6 +55,7 @@
%strong Issues events %strong Issues events
%p.light %p.light
This url will be triggered when an issue is created This url will be triggered when an issue is created
- if @service.supported_events.include?("merge_request")
%div %div
= f.check_box :merge_requests_events, class: 'pull-left' = f.check_box :merge_requests_events, class: 'pull-left'
.prepend-left-20 .prepend-left-20
......
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