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
f5908cef
Commit
f5908cef
authored
Jul 15, 2012
by
Valeriy Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
System Hook: implemented
parent
c3857842
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
100 additions
and
10 deletions
+100
-10
app/controllers/admin/hooks_controller.rb
app/controllers/admin/hooks_controller.rb
+5
-6
app/models/project.rb
app/models/project.rb
+27
-1
app/models/system_hook.rb
app/models/system_hook.rb
+10
-0
app/models/user.rb
app/models/user.rb
+19
-0
app/models/users_project.rb
app/models/users_project.rb
+29
-1
app/models/web_hook.rb
app/models/web_hook.rb
+1
-0
app/workers/system_hook_worker.rb
app/workers/system_hook_worker.rb
+7
-0
resque.sh
resque.sh
+1
-1
resque_dev.sh
resque_dev.sh
+1
-1
No files found.
app/controllers/admin/hooks_controller.rb
View file @
f5908cef
...
...
@@ -11,12 +11,11 @@ class Admin::HooksController < ApplicationController
def
create
@hook
=
SystemHook
.
new
(
params
[
:hook
])
respond_to
do
|
format
|
if
@hook
.
save
format
.
html
{
redirect_to
admin_hooks_path
,
notice:
'Hook was successfully created.'
}
else
format
.
html
{
render
:index
}
end
if
@hook
.
save
redirect_to
admin_hooks_path
,
notice:
'Hook was successfully created.'
else
@hooks
=
SystemHook
.
all
render
:index
end
end
...
...
app/models/project.rb
View file @
f5908cef
...
...
@@ -107,6 +107,32 @@ class Project < ActiveRecord::Base
validate
:check_limit
validate
:repo_name
after_create
:create_hooks
after_destroy
:destroy_hooks
def
create_hooks
SystemHook
.
all_hooks_fire
({
event_name:
"project_create"
,
name:
self
.
name
,
path:
self
.
path
,
project_id:
self
.
id
,
owner_name:
self
.
owner
.
name
,
owner_email:
self
.
owner
.
email
,
created_at:
self
.
created_at
})
end
def
destroy_hooks
SystemHook
.
all_hooks_fire
({
event_name:
"project_destroy"
,
name:
self
.
name
,
path:
self
.
path
,
project_id:
self
.
id
,
owner_name:
self
.
owner
.
name
,
owner_email:
self
.
owner
.
email
,
})
end
def
check_limit
unless
owner
.
can_create_project?
errors
[
:base
]
<<
(
"Your own projects limit is
#{
owner
.
projects_limit
}
! Please contact administrator to increase it"
)
...
...
@@ -120,7 +146,7 @@ class Project < ActiveRecord::Base
errors
.
add
(
:path
,
" like 'gitolite-admin' is not allowed"
)
end
end
def
self
.
access_options
UsersProject
.
access_roles
end
...
...
app/models/system_hook.rb
View file @
f5908cef
class
SystemHook
<
WebHook
def
async_execute
(
data
)
Resque
.
enqueue
(
SystemHookWorker
,
id
,
data
)
end
def
self
.
all_hooks_fire
(
data
)
SystemHook
.
all
.
each
do
|
sh
|
sh
.
async_execute
data
end
end
end
app/models/user.rb
View file @
f5908cef
...
...
@@ -57,6 +57,25 @@ class User < ActiveRecord::Base
scope
:active
,
where
(
:blocked
=>
false
)
before_validation
:generate_password
,
:on
=>
:create
after_create
:create_hooks
after_destroy
:destroy_hooks
def
create_hooks
SystemHook
.
all_hooks_fire
({
event_name:
"user_create"
,
name:
self
.
name
,
email:
self
.
email
,
created_at:
self
.
created_at
})
end
def
destroy_hooks
SystemHook
.
all_hooks_fire
({
event_name:
"user_destroy"
,
name:
self
.
name
,
email:
self
.
email
})
end
def
generate_password
if
self
.
force_random_password
...
...
app/models/users_project.rb
View file @
f5908cef
...
...
@@ -11,6 +11,9 @@ class UsersProject < ActiveRecord::Base
after_save
:update_repository
after_destroy
:update_repository
after_create
:add_to_team_hooks
after_destroy
:remove_from_team_hooks
validates_uniqueness_of
:user_id
,
:scope
=>
[
:project_id
]
validates_presence_of
:user_id
...
...
@@ -18,6 +21,31 @@ class UsersProject < ActiveRecord::Base
delegate
:name
,
:email
,
:to
=>
:user
,
:prefix
=>
true
def
add_to_team_hooks
SystemHook
.
all_hooks_fire
({
event_name:
"user_add_to_team"
,
project_name:
self
.
project
.
name
,
project_path:
self
.
project
.
path
,
project_id:
self
.
project_id
,
user_name:
self
.
user
.
name
,
user_email:
self
.
user
.
email
,
project_access:
self
.
repo_access_human
,
created_at:
self
.
created_at
})
end
def
remove_from_team_hooks
SystemHook
.
all_hooks_fire
({
event_name:
"user_remove_from_team"
,
project_name:
self
.
project
.
name
,
project_path:
self
.
project
.
path
,
project_id:
self
.
project_id
,
user_name:
self
.
user
.
name
,
user_email:
self
.
user
.
email
,
project_access:
self
.
repo_access_human
})
end
def
self
.
bulk_import
(
project
,
user_ids
,
project_access
)
UsersProject
.
transaction
do
user_ids
.
each
do
|
user_id
|
...
...
@@ -68,7 +96,7 @@ class UsersProject < ActiveRecord::Base
end
def
repo_access_human
""
self
.
class
.
access_roles
.
invert
[
self
.
project_access
]
end
end
# == Schema Information
...
...
app/models/web_hook.rb
View file @
f5908cef
...
...
@@ -13,6 +13,7 @@ class WebHook < ActiveRecord::Base
def
execute
(
data
)
WebHook
.
post
(
url
,
body:
data
.
to_json
,
headers:
{
"Content-Type"
=>
"application/json"
})
end
end
# == Schema Information
#
...
...
app/workers/system_hook_worker.rb
0 → 100644
View file @
f5908cef
class
SystemHookWorker
@queue
=
:system_hook
def
self
.
perform
(
hook_id
,
data
)
SystemHook
.
find
(
hook_id
).
execute
data
end
end
resque.sh
View file @
f5908cef
mkdir
-p
tmp/pids
bundle
exec
rake environment resque:work
QUEUE
=
post_receive,mailer
RAILS_ENV
=
production
PIDFILE
=
tmp/pids/resque_worker.pid
BACKGROUND
=
yes
bundle
exec
rake environment resque:work
QUEUE
=
post_receive,mailer
,system_hook
RAILS_ENV
=
production
PIDFILE
=
tmp/pids/resque_worker.pid
BACKGROUND
=
yes
resque_dev.sh
View file @
f5908cef
bundle
exec
rake environment resque:work
QUEUE
=
*
VVERBOSE
=
1
bundle
exec
rake environment resque:work
QUEUE
=
post_receive,mailer,system_hook
VVERBOSE
=
1
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