Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
37ef33cb
Commit
37ef33cb
authored
Jan 15, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use instance methods for system_hooks_service
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
065d9c22
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
9 deletions
+15
-9
app/observers/system_hook_observer.rb
app/observers/system_hook_observer.rb
+8
-2
app/services/system_hooks_service.rb
app/services/system_hooks_service.rb
+5
-5
spec/services/system_hooks_service_spec.rb
spec/services/system_hooks_service_spec.rb
+2
-2
No files found.
app/observers/system_hook_observer.rb
View file @
37ef33cb
...
@@ -2,10 +2,16 @@ class SystemHookObserver < BaseObserver
...
@@ -2,10 +2,16 @@ class SystemHookObserver < BaseObserver
observe
:user
,
:project
,
:users_project
observe
:user
,
:project
,
:users_project
def
after_create
(
model
)
def
after_create
(
model
)
SystemHooksS
ervice
.
execute_hooks_for
(
model
,
:create
)
system_hook_s
ervice
.
execute_hooks_for
(
model
,
:create
)
end
end
def
after_destroy
(
model
)
def
after_destroy
(
model
)
SystemHooksService
.
execute_hooks_for
(
model
,
:destroy
)
system_hook_service
.
execute_hooks_for
(
model
,
:destroy
)
end
private
def
system_hook_service
SystemHooksService
.
new
end
end
end
end
app/services/system_hooks_service.rb
View file @
37ef33cb
class
SystemHooksService
class
SystemHooksService
def
self
.
execute_hooks_for
(
model
,
event
)
def
execute_hooks_for
(
model
,
event
)
execute_hooks
(
build_event_data
(
model
,
event
))
execute_hooks
(
build_event_data
(
model
,
event
))
end
end
private
private
def
self
.
execute_hooks
(
data
)
def
execute_hooks
(
data
)
SystemHook
.
all
.
each
do
|
sh
|
SystemHook
.
all
.
each
do
|
sh
|
async_execute_hook
sh
,
data
async_execute_hook
sh
,
data
end
end
end
end
def
self
.
async_execute_hook
(
hook
,
data
)
def
async_execute_hook
(
hook
,
data
)
Sidekiq
::
Client
.
enqueue
(
SystemHookWorker
,
hook
.
id
,
data
)
Sidekiq
::
Client
.
enqueue
(
SystemHookWorker
,
hook
.
id
,
data
)
end
end
def
self
.
build_event_data
(
model
,
event
)
def
build_event_data
(
model
,
event
)
data
=
{
data
=
{
event_name:
build_event_name
(
model
,
event
),
event_name:
build_event_name
(
model
,
event
),
created_at:
model
.
created_at
created_at:
model
.
created_at
...
@@ -51,7 +51,7 @@ class SystemHooksService
...
@@ -51,7 +51,7 @@ class SystemHooksService
end
end
end
end
def
self
.
build_event_name
(
model
,
event
)
def
build_event_name
(
model
,
event
)
case
model
case
model
when
UsersProject
when
UsersProject
return
"user_add_to_team"
if
event
==
:create
return
"user_add_to_team"
if
event
==
:create
...
...
spec/services/system_hooks_service_spec.rb
View file @
37ef33cb
...
@@ -24,10 +24,10 @@ describe SystemHooksService do
...
@@ -24,10 +24,10 @@ describe SystemHooksService do
end
end
def
event_data
(
*
args
)
def
event_data
(
*
args
)
SystemHooksService
.
build_event_data
(
*
args
)
SystemHooksService
.
new
.
send
:build_event_data
,
*
args
end
end
def
event_name
(
*
args
)
def
event_name
(
*
args
)
SystemHooksService
.
build_event_name
(
*
args
)
SystemHooksService
.
new
.
send
:build_event_name
,
*
args
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment