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
Kazuhiko Shiozaki
gitlab-ce
Commits
38e2ae5a
Commit
38e2ae5a
authored
Apr 27, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8644 from Bugagazavr/hook-events
Add X-GitLab-Event header for web hooks
parents
7ee1d68e
548f1828
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
32 additions
and
21 deletions
+32
-21
CHANGELOG
CHANGELOG
+1
-0
app/controllers/admin/hooks_controller.rb
app/controllers/admin/hooks_controller.rb
+1
-1
app/models/hooks/web_hook.rb
app/models/hooks/web_hook.rb
+11
-5
app/models/project.rb
app/models/project.rb
+1
-1
app/services/system_hooks_service.rb
app/services/system_hooks_service.rb
+3
-3
app/services/test_hook_service.rb
app/services/test_hook_service.rb
+1
-1
app/workers/project_web_hook_worker.rb
app/workers/project_web_hook_worker.rb
+2
-2
app/workers/system_hook_worker.rb
app/workers/system_hook_worker.rb
+2
-2
lib/api/system_hooks.rb
lib/api/system_hooks.rb
+1
-1
spec/models/hooks/web_hook_spec.rb
spec/models/hooks/web_hook_spec.rb
+9
-5
No files found.
CHANGELOG
View file @
38e2ae5a
...
...
@@ -10,6 +10,7 @@ v 7.11.0 (unreleased)
- Add "Reply quoting selected text" shortcut key (`r`)
- Fix bug causing `@whatever` inside an issue's first code block to be picked up as a user mention.
- Fix bug causing `@whatever` inside an inline code snippet (backtick-style) to be picked up as a user mention.
- Added GitLab Event header for project hooks
-
- Show Atom feed buttons everywhere where applicable.
- Add project activity atom feed.
...
...
app/controllers/admin/hooks_controller.rb
View file @
38e2ae5a
...
...
@@ -33,7 +33,7 @@ class Admin::HooksController < Admin::ApplicationController
owner_name:
"Someone"
,
owner_email:
"example@gitlabhq.com"
}
@hook
.
execute
(
data
)
@hook
.
execute
(
data
,
'system_hooks'
)
redirect_to
:back
end
...
...
app/models/hooks/web_hook.rb
View file @
38e2ae5a
...
...
@@ -30,12 +30,15 @@ class WebHook < ActiveRecord::Base
validates
:url
,
presence:
true
,
format:
{
with:
/\A
#{
URI
.
regexp
(
%w(http https)
)
}
\z/
,
message:
"should be a valid url"
}
def
execute
(
data
)
def
execute
(
data
,
hook_name
)
parsed_url
=
URI
.
parse
(
url
)
if
parsed_url
.
userinfo
.
blank?
WebHook
.
post
(
url
,
body:
data
.
to_json
,
headers:
{
"Content-Type"
=>
"application/json"
},
headers:
{
"Content-Type"
=>
"application/json"
,
"X-Gitlab-Event"
=>
hook_name
.
singularize
.
titleize
},
verify:
false
)
else
post_url
=
url
.
gsub
(
"
#{
parsed_url
.
userinfo
}
@"
,
""
)
...
...
@@ -45,7 +48,10 @@ class WebHook < ActiveRecord::Base
}
WebHook
.
post
(
post_url
,
body:
data
.
to_json
,
headers:
{
"Content-Type"
=>
"application/json"
},
headers:
{
"Content-Type"
=>
"application/json"
,
"X-Gitlab-Event"
=>
hook_name
.
singularize
.
titleize
},
verify:
false
,
basic_auth:
auth
)
end
...
...
@@ -54,7 +60,7 @@ class WebHook < ActiveRecord::Base
false
end
def
async_execute
(
data
)
Sidekiq
::
Client
.
enqueue
(
ProjectWebHookWorker
,
id
,
data
)
def
async_execute
(
data
,
hook_name
)
Sidekiq
::
Client
.
enqueue
(
ProjectWebHookWorker
,
id
,
data
,
hook_name
)
end
end
app/models/project.rb
View file @
38e2ae5a
...
...
@@ -483,7 +483,7 @@ class Project < ActiveRecord::Base
def
execute_hooks
(
data
,
hooks_scope
=
:push_hooks
)
hooks
.
send
(
hooks_scope
).
each
do
|
hook
|
hook
.
async_execute
(
data
)
hook
.
async_execute
(
data
,
hooks_scope
.
to_s
)
end
end
...
...
app/services/system_hooks_service.rb
View file @
38e2ae5a
...
...
@@ -7,12 +7,12 @@ class SystemHooksService
def
execute_hooks
(
data
)
SystemHook
.
all
.
each
do
|
sh
|
async_execute_hook
sh
,
data
async_execute_hook
(
sh
,
data
,
'system_hooks'
)
end
end
def
async_execute_hook
(
hook
,
data
)
Sidekiq
::
Client
.
enqueue
(
SystemHookWorker
,
hook
.
id
,
data
)
def
async_execute_hook
(
hook
,
data
,
hook_name
)
Sidekiq
::
Client
.
enqueue
(
SystemHookWorker
,
hook
.
id
,
data
,
hook_name
)
end
def
build_event_data
(
model
,
event
)
...
...
app/services/test_hook_service.rb
View file @
38e2ae5a
class
TestHookService
def
execute
(
hook
,
current_user
)
data
=
Gitlab
::
PushDataBuilder
.
build_sample
(
hook
.
project
,
current_user
)
hook
.
execute
(
data
)
hook
.
execute
(
data
,
'push_hooks'
)
end
end
app/workers/project_web_hook_worker.rb
View file @
38e2ae5a
...
...
@@ -3,8 +3,8 @@ class ProjectWebHookWorker
sidekiq_options
queue: :project_web_hook
def
perform
(
hook_id
,
data
)
def
perform
(
hook_id
,
data
,
hook_name
)
data
=
data
.
with_indifferent_access
WebHook
.
find
(
hook_id
).
execute
(
data
)
WebHook
.
find
(
hook_id
).
execute
(
data
,
hook_name
)
end
end
app/workers/system_hook_worker.rb
View file @
38e2ae5a
...
...
@@ -3,7 +3,7 @@ class SystemHookWorker
sidekiq_options
queue: :system_hook
def
perform
(
hook_id
,
data
)
SystemHook
.
find
(
hook_id
).
execute
data
def
perform
(
hook_id
,
data
,
hook_name
)
SystemHook
.
find
(
hook_id
).
execute
(
data
,
hook_name
)
end
end
lib/api/system_hooks.rb
View file @
38e2ae5a
...
...
@@ -47,7 +47,7 @@ module API
owner_name:
"Someone"
,
owner_email:
"example@gitlabhq.com"
}
@hook
.
execute
(
data
)
@hook
.
execute
(
data
,
'system_hooks'
)
data
end
...
...
spec/models/hooks/web_hook_spec.rb
View file @
38e2ae5a
...
...
@@ -52,22 +52,26 @@ describe ProjectHook do
end
it
"POSTs to the web hook URL"
do
@project_hook
.
execute
(
@data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
@project_hook
.
url
).
once
@project_hook
.
execute
(
@data
,
'push_hooks'
)
expect
(
WebMock
).
to
have_requested
(
:post
,
@project_hook
.
url
).
with
(
headers:
{
'Content-Type'
=>
'application/json'
,
'X-Gitlab-Event'
=>
'Push Hook'
}).
once
end
it
"POSTs the data as JSON"
do
json
=
@data
.
to_json
@project_hook
.
execute
(
@data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
@project_hook
.
url
).
with
(
body:
json
).
once
@project_hook
.
execute
(
@data
,
'push_hooks'
)
expect
(
WebMock
).
to
have_requested
(
:post
,
@project_hook
.
url
).
with
(
headers:
{
'Content-Type'
=>
'application/json'
,
'X-Gitlab-Event'
=>
'Push Hook'
}).
once
end
it
"catches exceptions"
do
expect
(
WebHook
).
to
receive
(
:post
).
and_raise
(
"Some HTTP Post error"
)
expect
{
@project_hook
.
execute
(
@data
)
@project_hook
.
execute
(
@data
,
'push_hooks'
)
}.
to
raise_error
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