diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-02-28 17:33:18 +0100 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-03-03 11:14:32 +0100 |
commit | d57e809cbd56aea8a49c6595663fc4b7250c5a34 (patch) | |
tree | 495d73da8f7edad0852a856774ef907ca6bfac60 /app | |
parent | 85fa334eb6fd2069287a660e6ffa2295ea3a787f (diff) | |
download | gitlab-ce-d57e809cbd56aea8a49c6595663fc4b7250c5a34.tar.gz |
Set supported events per project service.
Diffstat (limited to 'app')
19 files changed, 156 insertions, 57 deletions
diff --git a/app/models/project_services/asana_service.rb b/app/models/project_services/asana_service.rb index a5686c48bc6..8ad1ad6267a 100644 --- a/app/models/project_services/asana_service.rb +++ b/app/models/project_services/asana_service.rb @@ -65,9 +65,12 @@ automatically inspected. Leave blank to include all branches.' ] end + def supported_events + %w(push) + end + def execute(data) - object_kind = data[:object_kind] - return unless object_kind == "push" + return unless supported_events.include?(data[:object_kind]) Asana.configure do |client| client.api_key = api_key diff --git a/app/models/project_services/assembla_service.rb b/app/models/project_services/assembla_service.rb index 01c647c1705..02aa7c972e7 100644 --- a/app/models/project_services/assembla_service.rb +++ b/app/models/project_services/assembla_service.rb @@ -42,9 +42,12 @@ class AssemblaService < Service ] end + def supported_events + %w(push) + end + def execute(data) - object_kind = data[:object_kind] - return unless object_kind == "push" + return unless supported_events.include?(data[:object_kind]) 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' }) diff --git a/app/models/project_services/bamboo_service.rb b/app/models/project_services/bamboo_service.rb index 6ff52af040d..6c6d74c615e 100644 --- a/app/models/project_services/bamboo_service.rb +++ b/app/models/project_services/bamboo_service.rb @@ -73,6 +73,10 @@ class BambooService < CiService ] end + def supported_events + %w(push) + end + def build_info(sha) url = URI.parse("#{bamboo_url}/rest/api/latest/result?label=#{sha}") @@ -123,8 +127,7 @@ class BambooService < CiService end def execute(data) - object_kind = data[:object_kind] - return unless object_kind == "push" + return unless supported_events.include?(data[:object_kind]) # Bamboo requires a GET and does not take any data. self.class.get("#{bamboo_url}/updateAndBuild.action?buildKey=#{build_key}", diff --git a/app/models/project_services/buildbox_service.rb b/app/models/project_services/buildbox_service.rb index 201bfc560a3..96428c91711 100644 --- a/app/models/project_services/buildbox_service.rb +++ b/app/models/project_services/buildbox_service.rb @@ -36,9 +36,12 @@ class BuildboxService < CiService hook.save end + def supported_events + %w(push) + end + def execute(data) - object_kind = data[:object_kind] - return unless object_kind == "push" + return unless supported_events.include?(data[:object_kind]) service_hook.execute(data) end diff --git a/app/models/project_services/campfire_service.rb b/app/models/project_services/campfire_service.rb index 7af6882329c..2f86fbe7a03 100644 --- a/app/models/project_services/campfire_service.rb +++ b/app/models/project_services/campfire_service.rb @@ -41,9 +41,12 @@ class CampfireService < Service ] end + def supported_events + %w(push) + end + def execute(data) - object_kind = data[:object_kind] - return unless object_kind == "push" + return unless supported_events.include?(data[:object_kind]) room = gate.find_room_by_name(self.room) return true unless room diff --git a/app/models/project_services/ci_service.rb b/app/models/project_services/ci_service.rb index e58d6d7a233..646783c8733 100644 --- a/app/models/project_services/ci_service.rb +++ b/app/models/project_services/ci_service.rb @@ -25,6 +25,10 @@ class CiService < Service :ci end + def supported_events + %w(push) + end + # Return complete url to build page # # Ex. diff --git a/app/models/project_services/emails_on_push_service.rb b/app/models/project_services/emails_on_push_service.rb index 1b7ce481c1f..21041e08a20 100644 --- a/app/models/project_services/emails_on_push_service.rb +++ b/app/models/project_services/emails_on_push_service.rb @@ -33,9 +33,12 @@ class EmailsOnPushService < Service 'emails_on_push' end + def supported_events + %w(push) + end + def execute(data) - object_kind = data[:object_kind] - return unless object_kind == "push" + return unless supported_events.include?(data[:object_kind]) EmailsOnPushWorker.perform_async(project_id, recipients, data) end diff --git a/app/models/project_services/flowdock_service.rb b/app/models/project_services/flowdock_service.rb index e4ea84cb617..443dca72a8c 100644 --- a/app/models/project_services/flowdock_service.rb +++ b/app/models/project_services/flowdock_service.rb @@ -41,9 +41,12 @@ class FlowdockService < Service ] end + def supported_events + %w(push) + end + def execute(data) - object_kind = data[:object_kind] - return unless object_kind == "push" + return unless supported_events.include?(data[:object_kind]) Flowdock::Git.post( data[:ref], diff --git a/app/models/project_services/gemnasium_service.rb b/app/models/project_services/gemnasium_service.rb index ada61b78047..41eedc215d5 100644 --- a/app/models/project_services/gemnasium_service.rb +++ b/app/models/project_services/gemnasium_service.rb @@ -42,9 +42,12 @@ class GemnasiumService < Service ] end + def supported_events + %w(push) + end + def execute(data) - object_kind = data[:object_kind] - return unless object_kind == "push" + return unless supported_events.include?(data[:object_kind]) Gemnasium::GitlabService.execute( ref: data[:ref], diff --git a/app/models/project_services/gitlab_ci_service.rb b/app/models/project_services/gitlab_ci_service.rb index bfc7a1fee32..02bf305f8f2 100644 --- a/app/models/project_services/gitlab_ci_service.rb +++ b/app/models/project_services/gitlab_ci_service.rb @@ -30,9 +30,12 @@ class GitlabCiService < CiService hook.save end + def supported_events + %w(push tag_push) + end + def execute(data) - object_kind = data[:object_kind] - return unless %w(push tag_push).include?(object_kind) + return unless supported_events.include?(data[:object_kind]) service_hook.execute(data) end diff --git a/app/models/project_services/hipchat_service.rb b/app/models/project_services/hipchat_service.rb index 965ecdc684b..b85863d2f0d 100644 --- a/app/models/project_services/hipchat_service.rb +++ b/app/models/project_services/hipchat_service.rb @@ -44,9 +44,12 @@ class HipchatService < Service ] end + def supported_events + %w(push) + end + def execute(data) - object_kind = data[:object_kind] - return unless object_kind == "push" + return unless supported_events.include?(data[:object_kind]) gate[room].send('GitLab', create_message(data)) end diff --git a/app/models/project_services/issue_tracker_service.rb b/app/models/project_services/issue_tracker_service.rb index 0d9e5c13992..bfc65b5379f 100644 --- a/app/models/project_services/issue_tracker_service.rb +++ b/app/models/project_services/issue_tracker_service.rb @@ -69,9 +69,12 @@ class IssueTrackerService < Service end end + def supported_events + %w(push) + end + def execute(data) - object_kind = data[:object_kind] - return unless object_kind == "push" + return unless supported_events.include?(data[:object_kind]) message = "#{self.type} was unable to reach #{self.project_url}. Check the url and try again." result = false diff --git a/app/models/project_services/pivotaltracker_service.rb b/app/models/project_services/pivotaltracker_service.rb index dd9e7f35c17..a2fa9788f10 100644 --- a/app/models/project_services/pivotaltracker_service.rb +++ b/app/models/project_services/pivotaltracker_service.rb @@ -41,9 +41,12 @@ class PivotaltrackerService < Service ] end + def supported_events + %w(push) + end + def execute(data) - object_kind = data[:object_kind] - return unless object_kind == "push" + return unless supported_events.include?(data[:object_kind]) url = 'https://www.pivotaltracker.com/services/v5/source_commits' data[:commits].each do |commit| diff --git a/app/models/project_services/pushover_service.rb b/app/models/project_services/pushover_service.rb index a715e7b2cc5..586d9e94a95 100644 --- a/app/models/project_services/pushover_service.rb +++ b/app/models/project_services/pushover_service.rb @@ -80,9 +80,12 @@ class PushoverService < Service ] end + def supported_events + %w(push) + end + def execute(data) - object_kind = data[:object_kind] - return unless object_kind == "push" + return unless supported_events.include?(data[:object_kind]) ref = data[:ref].gsub('refs/heads/', '') before = data[:before] diff --git a/app/models/project_services/slack_service.rb b/app/models/project_services/slack_service.rb index 279abad8081..64d6f4327b8 100644 --- a/app/models/project_services/slack_service.rb +++ b/app/models/project_services/slack_service.rb @@ -42,7 +42,12 @@ class SlackService < Service ] end + def supported_events + %w(push issue merge_request) + end + def execute(data) + return unless supported_events.include?(data[:object_kind]) return unless webhook.present? object_kind = data[:object_kind] diff --git a/app/models/project_services/teamcity_service.rb b/app/models/project_services/teamcity_service.rb index 07facfb6d06..686e6225a2e 100644 --- a/app/models/project_services/teamcity_service.rb +++ b/app/models/project_services/teamcity_service.rb @@ -61,6 +61,10 @@ class TeamcityService < CiService 'teamcity' end + def supported_events + %w(push) + end + def fields [ { type: 'text', name: 'teamcity_url', @@ -120,8 +124,7 @@ class TeamcityService < CiService end def execute(data) - object_kind = data[:object_kind] - return unless object_kind == "push" + return unless supported_events.include?(data[:object_kind]) auth = { username: username, diff --git a/app/models/service.rb b/app/models/service.rb index 9d6866f26d0..98bd40ae95e 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -80,6 +80,10 @@ class Service < ActiveRecord::Base [] end + def supported_events + %w(push tag_push issue merge_request) + end + def execute # implement inside child end @@ -105,6 +109,8 @@ class Service < ActiveRecord::Base end def async_execute(data) + return unless supported_events.include?(data[:object_kind]) + Sidekiq::Client.enqueue(ProjectServiceWorker, id, data) end diff --git a/app/views/admin/services/_form.html.haml b/app/views/admin/services/_form.html.haml index 5df8849317b..62f4001ca66 100644 --- a/app/views/admin/services/_form.html.haml +++ b/app/views/admin/services/_form.html.haml @@ -14,6 +14,43 @@ = preserve do = 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| - name = field[:name] - value = @service.send(name) unless field[:type] == 'password' diff --git a/app/views/projects/services/_form.html.haml b/app/views/projects/services/_form.html.haml index 0519c8150e9..55ac85c32b9 100644 --- a/app/views/projects/services/_form.html.haml +++ b/app/views/projects/services/_form.html.haml @@ -29,35 +29,40 @@ .form-group = f.label :url, "Trigger", class: 'control-label' - .col-sm-10 - %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 - %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 - %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 - %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 + - 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| - name = field[:name] |