Commit 8ee654d2 authored by Rubén Dávila's avatar Rubén Dávila

Add "Enable SSL verification" option to Group's web hooks form.

* Make comments webhooks available for Groups.
parent d95c0f5f
......@@ -53,6 +53,8 @@ class Groups::HooksController < Groups::ApplicationController
end
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
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
......@@ -16,5 +16,9 @@
#
class GroupHook < ProjectHook
include CustomModelNaming
self.singular_route_key = :hook
belongs_to :group
end
......@@ -19,6 +19,10 @@
#
class ProjectHook < WebHook
include CustomModelNaming
self.singular_route_key = :hook
belongs_to :project
scope :push_hooks, -> { where(push_events: true) }
......
- page_title "Web Hooks"
%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
= render 'shared/web_hooks/form', hook: @hook, hooks: @hooks, url_components: [@group]
- page_title "Webhooks"
%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"}
= render 'shared/web_hooks/form', hook: @hook, hooks: @hooks, url_components: [@project.namespace.becomes(Namespace), @project]
- 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"}
......@@ -34,7 +34,7 @@ class Spinach::Features::GroupHooks < Spinach::FeatureSteps
step 'I submit new hook' do
@url = FFaker::Internet.uri("http")
fill_in "hook_url", with: @url
expect { click_button "Add Web Hook" }.to change(GroupHook, :count).by(1)
expect { click_button "Add Webhook" }.to change(GroupHook, :count).by(1)
end
step 'I should see newly created hook' do
......
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
......@@ -37,6 +37,7 @@ RSpec.configure do |config|
config.include ActiveJob::TestHelper
config.include StubGitlabCalls
config.include StubGitlabData
config.include Rails.application.routes.url_helpers, type: :routing
config.infer_spec_type_from_file_location!
config.raise_errors_for_deprecations!
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment