diff options
| author | Gabriel Mazetto <gabriel@gitlab.com> | 2016-04-15 08:08:22 -0300 |
|---|---|---|
| committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2016-04-19 11:00:30 +0200 |
| commit | ee1090e2b2bc7b3762f6e2775f3fd15e92ae212b (patch) | |
| tree | 9df863f27349ca2a95d0e6f16d99b85d4806d992 /app | |
| parent | 53a1d705fe536ad373faa77ba1ef5196ff49a98b (diff) | |
| download | gitlab-ce-ee1090e2b2bc7b3762f6e2775f3fd15e92ae212b.tar.gz | |
Added System Hooks for push and tag_push
Code is based on Project Webhooks, removing deprecations and without
commits listing.
Diffstat (limited to 'app')
| -rw-r--r-- | app/models/hooks/system_hook.rb | 6 | ||||
| -rw-r--r-- | app/models/project.rb | 21 | ||||
| -rw-r--r-- | app/services/git_push_service.rb | 6 | ||||
| -rw-r--r-- | app/services/git_tag_push_service.rb | 6 | ||||
| -rw-r--r-- | app/services/system_hooks_service.rb | 12 |
5 files changed, 36 insertions, 15 deletions
diff --git a/app/models/hooks/system_hook.rb b/app/models/hooks/system_hook.rb index c147d8762a9..bacd42ec60a 100644 --- a/app/models/hooks/system_hook.rb +++ b/app/models/hooks/system_hook.rb @@ -19,4 +19,10 @@ # class SystemHook < WebHook + scope :push_hooks, -> { where(push_events: true) } + scope :tag_push_hooks, -> { where(tag_push_events: true) } + + def async_execute(data, hook_name) + Sidekiq::Client.enqueue(SystemHookWorker, id, data, hook_name) + end end diff --git a/app/models/project.rb b/app/models/project.rb index 8f20922e3c5..e7dac23a122 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -831,8 +831,8 @@ class Project < ActiveRecord::Base end end - def hook_attrs - { + def hook_attrs(backward: true) + attrs = { name: name, description: description, web_url: web_url, @@ -843,12 +843,19 @@ class Project < ActiveRecord::Base visibility_level: visibility_level, path_with_namespace: path_with_namespace, default_branch: default_branch, - # Backward compatibility - homepage: web_url, - url: url_to_repo, - ssh_url: ssh_url_to_repo, - http_url: http_url_to_repo } + + # Backward compatibility + if backward + attrs.merge!({ + homepage: web_url, + url: url_to_repo, + ssh_url: ssh_url_to_repo, + http_url: http_url_to_repo + }) + end + + attrs end # Reset events cache related to this project diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb index dc74c02760b..25d8e2cf052 100644 --- a/app/services/git_push_service.rb +++ b/app/services/git_push_service.rb @@ -73,6 +73,7 @@ class GitPushService < BaseService @project.update_merge_requests(params[:oldrev], params[:newrev], params[:ref], current_user) EventCreateService.new.push(@project, current_user, build_push_data) + SystemHooksService.new.execute_hooks(build_push_data_system_hook.dup, :push_hooks) @project.execute_hooks(build_push_data.dup, :push_hooks) @project.execute_services(build_push_data.dup, :push_hooks) CreateCommitBuildsService.new.execute(@project, current_user, build_push_data) @@ -138,6 +139,11 @@ class GitPushService < BaseService build(@project, current_user, params[:oldrev], params[:newrev], params[:ref], push_commits) end + def build_push_data_system_hook + @push_data_system ||= Gitlab::PushDataBuilder. + build_system(@project, current_user, params[:oldrev], params[:newrev], params[:ref]) + end + def push_to_existing_branch? # Return if this is not a push to a branch (e.g. new commits) Gitlab::Git.branch_ref?(params[:ref]) && !Gitlab::Git.blank_ref?(params[:oldrev]) diff --git a/app/services/git_tag_push_service.rb b/app/services/git_tag_push_service.rb index c88c7672805..81ba68fa674 100644 --- a/app/services/git_tag_push_service.rb +++ b/app/services/git_tag_push_service.rb @@ -8,6 +8,7 @@ class GitTagPushService @push_data = build_push_data(oldrev, newrev, ref) EventCreateService.new.push(project, user, @push_data) + SystemHooksService.new.execute_hooks(build_system_push_data.dup, :tag_push_hooks) project.execute_hooks(@push_data.dup, :tag_push_hooks) project.execute_services(@push_data.dup, :tag_push_hooks) CreateCommitBuildsService.new.execute(project, @user, @push_data) @@ -35,4 +36,9 @@ class GitTagPushService Gitlab::PushDataBuilder. build(project, user, oldrev, newrev, ref, commits, message) end + + def build_system_push_data(oldrev, newrev, ref) + Gitlab::PushDataBuilder. + build_system(project, user, oldrev, newrev, ref) + end end diff --git a/app/services/system_hooks_service.rb b/app/services/system_hooks_service.rb index f0615ec7420..e43b5b51e5b 100644 --- a/app/services/system_hooks_service.rb +++ b/app/services/system_hooks_service.rb @@ -3,17 +3,13 @@ class SystemHooksService execute_hooks(build_event_data(model, event)) end - private - - def execute_hooks(data) - SystemHook.all.each do |sh| - async_execute_hook(sh, data, 'system_hooks') + def execute_hooks(data, hooks_scope = :all) + SystemHook.send(hooks_scope).each do |hook| + hook.async_execute(data, 'system_hooks') end end - def async_execute_hook(hook, data, hook_name) - Sidekiq::Client.enqueue(SystemHookWorker, hook.id, data, hook_name) - end + private def build_event_data(model, event) data = { |
