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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
8ee654d2
Commit
8ee654d2
authored
Mar 15, 2016
by
Rubén Dávila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add "Enable SSL verification" option to Group's web hooks form.
* Make comments webhooks available for Groups.
parent
d95c0f5f
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
196 additions
and
162 deletions
+196
-162
app/controllers/groups/hooks_controller.rb
app/controllers/groups/hooks_controller.rb
+3
-1
app/models/concerns/custom_model_naming.rb
app/models/concerns/custom_model_naming.rb
+34
-0
app/models/hooks/group_hook.rb
app/models/hooks/group_hook.rb
+4
-0
app/models/hooks/project_hook.rb
app/models/hooks/project_hook.rb
+4
-0
app/views/groups/hooks/index.html.haml
app/views/groups/hooks/index.html.haml
+1
-69
app/views/projects/hooks/index.html.haml
app/views/projects/hooks/index.html.haml
+1
-91
app/views/shared/web_hooks/_form.html.haml
app/views/shared/web_hooks/_form.html.haml
+96
-0
features/steps/group_hooks.rb
features/steps/group_hooks.rb
+1
-1
spec/routing/webhook_routes_spec.rb
spec/routing/webhook_routes_spec.rb
+51
-0
spec/spec_helper.rb
spec/spec_helper.rb
+1
-0
No files found.
app/controllers/groups/hooks_controller.rb
View file @
8ee654d2
...
@@ -53,6 +53,8 @@ class Groups::HooksController < Groups::ApplicationController
...
@@ -53,6 +53,8 @@ class Groups::HooksController < Groups::ApplicationController
end
end
def
hook_params
def
hook_params
params
.
require
(
:hook
).
permit
(
:url
,
:push_events
,
:issues_events
,
:merge_requests_events
,
:tag_push_events
)
params
.
require
(
:hook
).
permit
(
:url
,
:push_events
,
:issues_events
,
:merge_requests_events
,
:tag_push_events
,
:note_events
,
:build_events
,
:enable_ssl_verification
)
end
end
end
end
app/models/concerns/custom_model_naming.rb
0 → 100644
View file @
8ee654d2
module
CustomModelNaming
# Extracted from: https://github.com/stevenbarragan/spree_random_subscriptions/blob/5426ccaf8a2084c495b2cac9dfbd27e30ade0cec/lib/custom_model_naming.rb
extend
ActiveSupport
::
Concern
included
do
self
.
class_attribute
:singular_route_key
,
:route_key
,
:param_key
end
module
ClassMethods
def
model_name
@_model_name
||=
begin
namespace
=
self
.
parents
.
detect
do
|
n
|
n
.
respond_to?
(
:use_relative_model_naming?
)
&&
n
.
use_relative_model_naming?
end
Name
.
new
(
self
,
namespace
)
end
end
end
class
Name
<
::
ActiveModel
::
Name
def
param_key
@klass
.
param_key
||
super
end
def
singular_route_key
@klass
.
singular_route_key
||
(
@klass
.
route_key
&&
ActiveSupport
::
Inflector
.
singularize
(
@klass
.
route_key
))
||
super
end
def
route_key
@klass
.
route_key
||
super
end
end
end
app/models/hooks/group_hook.rb
View file @
8ee654d2
...
@@ -16,5 +16,9 @@
...
@@ -16,5 +16,9 @@
#
#
class
GroupHook
<
ProjectHook
class
GroupHook
<
ProjectHook
include
CustomModelNaming
self
.
singular_route_key
=
:hook
belongs_to
:group
belongs_to
:group
end
end
app/models/hooks/project_hook.rb
View file @
8ee654d2
...
@@ -19,6 +19,10 @@
...
@@ -19,6 +19,10 @@
#
#
class
ProjectHook
<
WebHook
class
ProjectHook
<
WebHook
include
CustomModelNaming
self
.
singular_route_key
=
:hook
belongs_to
:project
belongs_to
:project
scope
:push_hooks
,
->
{
where
(
push_events:
true
)
}
scope
:push_hooks
,
->
{
where
(
push_events:
true
)
}
...
...
app/views/groups/hooks/index.html.haml
View file @
8ee654d2
-
page_title
"Web Hooks"
=
render
'shared/web_hooks/form'
,
hook:
@hook
,
hooks:
@hooks
,
url_components:
[
@group
]
%h3
.page-title
Web hooks
%p
.light
#{
link_to
"Web hooks "
,
help_page_path
(
"web_hooks"
,
"web_hooks"
),
class:
"vlink"
}
can be
used for binding events when something is happening within any project inside this group.
%hr
.clearfix
=
form_for
[
@group
,
@hook
],
as: :hook
,
url:
group_hooks_path
(
@group
),
html:
{
class:
'form-horizontal'
}
do
|
f
|
-
if
@hook
.
errors
.
any?
.alert.alert-danger
-
@hook
.
errors
.
full_messages
.
each
do
|
msg
|
%p
=
msg
.form-group
=
f
.
label
:url
,
"URL"
,
class:
'control-label'
.col-sm-10
=
f
.
text_field
:url
,
class:
"form-control"
,
placeholder:
'http://example.com/trigger-ci.json'
.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
.form-actions
=
f
.
submit
"Add Web Hook"
,
class:
"btn btn-create"
-
if
@hooks
.
any?
.panel.panel-default
.panel-heading
Web hooks (
#{
@hooks
.
count
}
)
%ul
.well-list
-
@hooks
.
each
do
|
hook
|
%li
.pull-right
=
link_to
'Test Hook'
,
test_group_hook_path
(
@group
,
hook
),
class:
"btn btn-small btn-grouped"
=
link_to
'Remove'
,
group_hook_path
(
@group
,
hook
),
data:
{
confirm:
'Are you sure?'
},
method: :delete
,
class:
"btn btn-remove btn-small btn-grouped"
.clearfix
%span
.monospace
=
hook
.
url
%p
-
%w(push_events tag_push_events issues_events merge_requests_events)
.
each
do
|
trigger
|
-
if
hook
.
send
(
trigger
)
%span
.label.label-gray
=
trigger
.
titleize
app/views/projects/hooks/index.html.haml
View file @
8ee654d2
-
page_title
"Webhooks"
=
render
'shared/web_hooks/form'
,
hook:
@hook
,
hooks:
@hooks
,
url_components:
[
@project
.
namespace
.
becomes
(
Namespace
),
@project
]
%h3
.page-title
Webhooks
%p
.light
#{
link_to
"Webhooks "
,
help_page_path
(
"web_hooks"
,
"web_hooks"
),
class:
"vlink"
}
can be
used for binding events when something is happening within the project.
%hr
.clearfix
=
form_for
[
@project
.
namespace
.
becomes
(
Namespace
),
@project
,
@hook
],
as: :hook
,
url:
namespace_project_hooks_path
(
@project
.
namespace
,
@project
),
html:
{
class:
'form-horizontal'
}
do
|
f
|
-
if
@hook
.
errors
.
any?
.alert.alert-danger
-
@hook
.
errors
.
full_messages
.
each
do
|
msg
|
%p
=
msg
.form-group
=
f
.
label
:url
,
"URL"
,
class:
'control-label'
.col-sm-10
=
f
.
text_field
:url
,
class:
"form-control"
,
placeholder:
'http://example.com/trigger-ci.json'
.form-group
=
f
.
label
:url
,
"Trigger"
,
class:
'control-label'
.col-sm-10.prepend-top-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
:note_events
,
class:
'pull-left'
.prepend-left-20
=
f
.
label
:note_events
,
class:
'list-label'
do
%strong
Comments
%p
.light
This url will be triggered when someone adds a comment
%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/updated/merged
%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/updated/merged
%div
=
f
.
check_box
:build_events
,
class:
'pull-left'
.prepend-left-20
=
f
.
label
:build_events
,
class:
'list-label'
do
%strong
Build events
%p
.light
This url will be triggered when the build status changes
.form-group
=
f
.
label
:enable_ssl_verification
,
"SSL verification"
,
class:
'control-label checkbox'
.col-sm-10
.checkbox
=
f
.
label
:enable_ssl_verification
do
=
f
.
check_box
:enable_ssl_verification
%strong
Enable SSL verification
.form-actions
=
f
.
submit
"Add Webhook"
,
class:
"btn btn-create"
-
if
@hooks
.
any?
.panel.panel-default
.panel-heading
Webhooks (
#{
@hooks
.
count
}
)
%ul
.well-list
-
@hooks
.
each
do
|
hook
|
%li
.pull-right
=
link_to
'Test Hook'
,
test_namespace_project_hook_path
(
@project
.
namespace
,
@project
,
hook
),
class:
"btn btn-sm btn-grouped"
=
link_to
'Remove'
,
namespace_project_hook_path
(
@project
.
namespace
,
@project
,
hook
),
data:
{
confirm:
'Are you sure?'
},
method: :delete
,
class:
"btn btn-remove btn-sm btn-grouped"
.clearfix
%span
.monospace
=
hook
.
url
%p
-
%w(push_events tag_push_events issues_events note_events merge_requests_events build_events)
.
each
do
|
trigger
|
-
if
hook
.
send
(
trigger
)
%span
.label.label-gray
=
trigger
.
titleize
SSL Verification:
#{
hook
.
enable_ssl_verification
?
"enabled"
:
"disabled"
}
app/views/shared/web_hooks/_form.html.haml
0 → 100644
View file @
8ee654d2
-
page_title
"Webhooks"
-
context_title
=
@project
?
'project'
:
'group'
%h3
.page-title
Webhooks
%p
.light
#{
link_to
"Webhooks "
,
help_page_path
(
"web_hooks"
,
"web_hooks"
),
class:
"vlink"
}
can be
used for binding events when something is happening within the
#{
context_title
}
.
%hr
.clearfix
=
form_for
hook
,
as: :hook
,
url:
polymorphic_path
(
url_components
+
[
:hooks
]),
html:
{
class:
'form-horizontal'
}
do
|
f
|
-
if
hook
.
errors
.
any?
.alert.alert-danger
-
hook
.
errors
.
full_messages
.
each
do
|
msg
|
%p
=
msg
.form-group
=
f
.
label
:url
,
"URL"
,
class:
'control-label'
.col-sm-10
=
f
.
text_field
:url
,
class:
"form-control"
,
placeholder:
'http://example.com/trigger-ci.json'
.form-group
=
f
.
label
:url
,
"Trigger"
,
class:
'control-label'
.col-sm-10.prepend-top-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
:note_events
,
class:
'pull-left'
.prepend-left-20
=
f
.
label
:note_events
,
class:
'list-label'
do
%strong
Comments
%p
.light
This url will be triggered when someone adds a comment
%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/updated/merged
%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/updated/merged
%div
=
f
.
check_box
:build_events
,
class:
'pull-left'
.prepend-left-20
=
f
.
label
:build_events
,
class:
'list-label'
do
%strong
Build events
%p
.light
This url will be triggered when the build status changes
.form-group
=
f
.
label
:enable_ssl_verification
,
"SSL verification"
,
class:
'control-label checkbox'
.col-sm-10
.checkbox
=
f
.
label
:enable_ssl_verification
do
=
f
.
check_box
:enable_ssl_verification
%strong
Enable SSL verification
.form-actions
=
f
.
submit
"Add Webhook"
,
class:
"btn btn-create"
-
if
hooks
.
any?
.panel.panel-default
.panel-heading
Webhooks (
#{
hooks
.
count
}
)
%ul
.well-list
-
hook_types
=
%w(push_events tag_push_events note_events issues_events merge_requests_events build_events)
-
hooks
.
each
do
|
hook
|
%li
.pull-right
=
link_to
'Test Hook'
,
polymorphic_path
(
url_components
+
[
hook
],
action: :test
),
class:
"btn btn-sm btn-grouped"
=
link_to
'Remove'
,
polymorphic_path
(
url_components
+
[
hook
]),
data:
{
confirm:
'Are you sure?'
},
method: :delete
,
class:
"btn btn-remove btn-sm btn-grouped"
.clearfix
%span
.monospace
=
hook
.
url
%p
-
hook_types
.
each
do
|
hook_type
|
-
if
hook
.
send
(
hook_type
)
%span
.label.label-gray
=
hook_type
.
titleize
SSL Verification:
#{
hook
.
enable_ssl_verification
?
"enabled"
:
"disabled"
}
features/steps/group_hooks.rb
View file @
8ee654d2
...
@@ -34,7 +34,7 @@ class Spinach::Features::GroupHooks < Spinach::FeatureSteps
...
@@ -34,7 +34,7 @@ class Spinach::Features::GroupHooks < Spinach::FeatureSteps
step
'I submit new hook'
do
step
'I submit new hook'
do
@url
=
FFaker
::
Internet
.
uri
(
"http"
)
@url
=
FFaker
::
Internet
.
uri
(
"http"
)
fill_in
"hook_url"
,
with:
@url
fill_in
"hook_url"
,
with:
@url
expect
{
click_button
"Add Web
H
ook"
}.
to
change
(
GroupHook
,
:count
).
by
(
1
)
expect
{
click_button
"Add Web
h
ook"
}.
to
change
(
GroupHook
,
:count
).
by
(
1
)
end
end
step
'I should see newly created hook'
do
step
'I should see newly created hook'
do
...
...
spec/routing/webhook_routes_spec.rb
0 → 100644
View file @
8ee654d2
require
"spec_helper"
describe
"routes to the proper webhooks controller"
,
type: :routing
do
context
'with a project context'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project_hook
)
{
create
(
:project_hook
)
}
it
"routes the test action"
do
expect
(
get:
polymorphic_path
([
project
.
namespace
.
becomes
(
Namespace
),
project
,
project_hook
],
action: :test
)
).
to
route_to
(
controller:
'projects/hooks'
,
action:
'test'
,
namespace_id:
project
.
namespace
.
name
,
project_id:
project
.
path
,
id:
project_hook
.
id
.
to_s
)
end
it
"routes a single record"
do
expect
(
delete:
polymorphic_path
([
project
.
namespace
.
becomes
(
Namespace
),
project
,
project_hook
])
).
to
route_to
(
controller:
'projects/hooks'
,
action:
'destroy'
,
namespace_id:
project
.
namespace
.
name
,
project_id:
project
.
path
,
id:
project_hook
.
id
.
to_s
)
end
end
context
'with a group context'
do
let
(
:group
)
{
create
(
:group
,
name:
'gitlab'
)
}
let
(
:group_hook
)
{
create
(
:group_hook
)
}
it
"routes the test action"
do
expect
(
get:
polymorphic_path
([
group
,
group_hook
],
action: :test
)
).
to
route_to
(
controller:
'groups/hooks'
,
action:
'test'
,
group_id:
group
.
name
,
id:
group_hook
.
id
.
to_s
)
end
it
"routes a single record"
do
expect
(
delete:
polymorphic_path
([
group
,
group_hook
])
).
to
route_to
(
controller:
'groups/hooks'
,
action:
'destroy'
,
group_id:
group
.
name
,
id:
group_hook
.
id
.
to_s
)
end
end
end
spec/spec_helper.rb
View file @
8ee654d2
...
@@ -37,6 +37,7 @@ RSpec.configure do |config|
...
@@ -37,6 +37,7 @@ RSpec.configure do |config|
config
.
include
ActiveJob
::
TestHelper
config
.
include
ActiveJob
::
TestHelper
config
.
include
StubGitlabCalls
config
.
include
StubGitlabCalls
config
.
include
StubGitlabData
config
.
include
StubGitlabData
config
.
include
Rails
.
application
.
routes
.
url_helpers
,
type: :routing
config
.
infer_spec_type_from_file_location!
config
.
infer_spec_type_from_file_location!
config
.
raise_errors_for_deprecations!
config
.
raise_errors_for_deprecations!
...
...
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