Commit 82d791e5 authored by Martin Wortschack's avatar Martin Wortschack

Merge branch '10433-add-edit-button-to-group-webhooks' into 'master'

Add ability to edit Group Hooks

See merge request gitlab-org/gitlab!20898
parents 213fa449 4ed849ab
...@@ -411,6 +411,7 @@ linters: ...@@ -411,6 +411,7 @@ linters:
- 'app/views/shared/snippets/_snippet.html.haml' - 'app/views/shared/snippets/_snippet.html.haml'
- 'app/views/shared/tokens/_scopes_list.html.haml' - 'app/views/shared/tokens/_scopes_list.html.haml'
- 'app/views/shared/web_hooks/_form.html.haml' - 'app/views/shared/web_hooks/_form.html.haml'
- 'app/views/shared/web_hooks/_hook.html.haml'
- 'app/views/shared/web_hooks/_test_button.html.haml' - 'app/views/shared/web_hooks/_test_button.html.haml'
- 'app/views/u2f/_authenticate.html.haml' - 'app/views/u2f/_authenticate.html.haml'
- 'app/views/u2f/_register.html.haml' - 'app/views/u2f/_register.html.haml'
...@@ -442,7 +443,7 @@ linters: ...@@ -442,7 +443,7 @@ linters:
- 'ee/app/views/groups/epics/_epic.html.haml' - 'ee/app/views/groups/epics/_epic.html.haml'
- 'ee/app/views/groups/group_members/_ldap_sync.html.haml' - 'ee/app/views/groups/group_members/_ldap_sync.html.haml'
- 'ee/app/views/groups/group_members/_sync_button.html.haml' - 'ee/app/views/groups/group_members/_sync_button.html.haml'
- 'ee/app/views/groups/hooks/_project_hook.html.haml' - 'ee/app/views/groups/hooks/edit.html.haml'
- 'ee/app/views/groups/hooks/index.html.haml' - 'ee/app/views/groups/hooks/index.html.haml'
- 'ee/app/views/groups/ldap_group_links/index.html.haml' - 'ee/app/views/groups/ldap_group_links/index.html.haml'
- 'ee/app/views/groups/pipeline_quota/index.html.haml' - 'ee/app/views/groups/pipeline_quota/index.html.haml'
......
...@@ -645,6 +645,12 @@ h4 { ...@@ -645,6 +645,12 @@ h4 {
} }
} }
.text-right-md {
@include media-breakpoint-up(md) {
text-align: right;
}
}
.text-right-lg { .text-right-lg {
@include media-breakpoint-up(lg) { @include media-breakpoint-up(lg) {
text-align: right; text-align: right;
......
...@@ -2,18 +2,40 @@ ...@@ -2,18 +2,40 @@
module HooksHelper module HooksHelper
def link_to_test_hook(hook, trigger) def link_to_test_hook(hook, trigger)
path = case hook path = test_hook_path(hook, trigger)
when ProjectHook
project = hook.project
test_project_hook_path(project, hook, trigger: trigger)
when SystemHook
test_admin_hook_path(hook, trigger: trigger)
end
trigger_human_name = trigger.to_s.tr('_', ' ').camelize trigger_human_name = trigger.to_s.tr('_', ' ').camelize
link_to path, rel: 'nofollow', method: :post do link_to path, rel: 'nofollow', method: :post do
content_tag(:span, trigger_human_name) content_tag(:span, trigger_human_name)
end end
end end
def test_hook_path(hook, trigger)
case hook
when ProjectHook
test_project_hook_path(hook.project, hook, trigger: trigger)
when SystemHook
test_admin_hook_path(hook, trigger: trigger)
end
end
def edit_hook_path(hook)
case hook
when ProjectHook
edit_project_hook_path(hook.project, hook)
when SystemHook
edit_admin_hook_path(hook)
end
end
def destroy_hook_path(hook)
case hook
when ProjectHook
project_hook_path(hook.project, hook)
when SystemHook
admin_hook_path(hook)
end
end
end end
HooksHelper.prepend_if_ee('EE::HooksHelper')
...@@ -18,6 +18,10 @@ class ProjectHook < WebHook ...@@ -18,6 +18,10 @@ class ProjectHook < WebHook
belongs_to :project belongs_to :project
validates :project, presence: true validates :project, presence: true
def pluralized_name
_('Project Hooks')
end
end end
ProjectHook.prepend_if_ee('EE::ProjectHook') ProjectHook.prepend_if_ee('EE::ProjectHook')
...@@ -20,4 +20,12 @@ class SystemHook < WebHook ...@@ -20,4 +20,12 @@ class SystemHook < WebHook
def allow_local_requests? def allow_local_requests?
Gitlab::CurrentSettings.allow_local_requests_from_system_hooks? Gitlab::CurrentSettings.allow_local_requests_from_system_hooks?
end end
def pluralized_name
_('System Hooks')
end
def help_path
'system_hooks/system_hooks'
end
end end
...@@ -37,4 +37,8 @@ class WebHook < ApplicationRecord ...@@ -37,4 +37,8 @@ class WebHook < ApplicationRecord
def allow_local_requests? def allow_local_requests?
Gitlab::CurrentSettings.allow_local_requests_from_web_hooks_and_services? Gitlab::CurrentSettings.allow_local_requests_from_web_hooks_and_services?
end end
def help_path
'user/project/integrations/webhooks'
end
end end
- add_to_breadcrumbs "System Hooks", admin_hooks_path - add_to_breadcrumbs @hook.pluralized_name, admin_hooks_path
- page_title 'Edit System Hook' - page_title _('Edit System Hook')
%h3.page-title
Edit System Hook
%p.light .row.prepend-top-default
#{link_to 'System hooks ', help_page_path('system_hooks/system_hooks')} can be .col-lg-3
used for binding events when GitLab creates a User or Project. = render 'shared/web_hooks/title_and_docs', hook: @hook
%hr .col-lg-9.append-bottom-default
= form_for @hook, as: :hook, url: admin_hook_path do |f|
= render partial: 'form', locals: { form: f, hook: @hook }
.form-actions
%span>= f.submit _('Save changes'), class: 'btn btn-success append-right-8'
= render 'shared/web_hooks/test_button', hook: @hook
= link_to _('Delete'), admin_hook_path(@hook), method: :delete, class: 'btn btn-remove float-right', data: { confirm: _('Are you sure?') }
= form_for @hook, as: :hook, url: admin_hook_path do |f| %hr
= render partial: 'form', locals: { form: f, hook: @hook }
.form-actions
= f.submit 'Save changes', class: 'btn btn-success'
= render 'shared/web_hooks/test_button', triggers: SystemHook.triggers, hook: @hook
= link_to 'Remove', admin_hook_path(@hook), method: :delete, class: 'btn btn-remove float-right', data: { confirm: 'Are you sure?' }
%hr = render partial: 'admin/hook_logs/index', locals: { hook: @hook, hook_logs: @hook_logs }
= render partial: 'admin/hook_logs/index', locals: { hook: @hook, hook_logs: @hook_logs }
- page_title 'System Hooks' - page_title @hook.pluralized_name
.row.prepend-top-default .row.prepend-top-default
.col-lg-4 .col-lg-4
%h4.prepend-top-0 = render 'shared/web_hooks/title_and_docs', hook: @hook
= page_title
%p
#{link_to 'System hooks ', help_page_path('system_hooks/system_hooks')} can be
used for binding events when GitLab creates a User or Project.
.col-lg-8.append-bottom-default .col-lg-8.append-bottom-default
= form_for @hook, as: :hook, url: admin_hooks_path do |f| = form_for @hook, as: :hook, url: admin_hooks_path do |f|
= render partial: 'form', locals: { form: f, hook: @hook } = render partial: 'form', locals: { form: f, hook: @hook }
= f.submit 'Add system hook', class: 'btn btn-success' = f.submit _('Add system hook'), class: 'btn btn-success'
%hr
- if @hooks.any? = render 'shared/web_hooks/index', hooks: @hooks, hook_class: @hook.class
.card
.card-header
System hooks (#{@hooks.count})
%ul.content-list
- @hooks.each do |hook|
%li
.controls
= render 'shared/web_hooks/test_button', triggers: SystemHook.triggers, hook: hook, button_class: 'btn-sm'
= link_to 'Edit', edit_admin_hook_path(hook), class: 'btn btn-sm'
= link_to 'Remove', admin_hook_path(hook), data: { confirm: 'Are you sure?' }, method: :delete, class: 'btn btn-remove btn-sm'
.monospace= hook.url
%div
- SystemHook.triggers.each_value do |event|
- if hook.public_send(event)
%span.badge.badge-gray= event.to_s.titleize
%span.badge.badge-gray SSL Verification: #{hook.enable_ssl_verification ? 'enabled' : 'disabled'}
= render 'shared/plugins/index' = render 'shared/plugins/index'
.row.prepend-top-default .row.prepend-top-default
.col-lg-4 .col-lg-4
%h4.prepend-top-0 = render 'shared/web_hooks/title_and_docs', hook: @hook
= page_title
%p
#{link_to 'Webhooks', help_page_path('user/project/integrations/webhooks')} can be
used for binding events when something is happening within the project.
.col-lg-8.append-bottom-default .col-lg-8.append-bottom-default
= form_for @hook, as: :hook, url: polymorphic_path([@project.namespace.becomes(Namespace), @project, :hooks]) do |f| = form_for @hook, as: :hook, url: polymorphic_path([@project.namespace.becomes(Namespace), @project, :hooks]) do |f|
= render partial: 'shared/web_hooks/form', locals: { form: f, hook: @hook } = render partial: 'shared/web_hooks/form', locals: { form: f, hook: @hook }
= f.submit 'Add webhook', class: 'btn btn-success' = f.submit 'Add webhook', class: 'btn btn-success'
%hr = render 'shared/web_hooks/index', hooks: @hooks, hook_class: @hook.class
%h5.prepend-top-default
Webhooks (#{@hooks.count})
- if @hooks.any?
%ul.content-list
- @hooks.each do |hook|
= render 'project_hook', hook: hook
- else
%p.settings-message.text-center.append-bottom-0
No webhooks found, add one in the form above.
- page_title 'Integrations' - add_to_breadcrumbs _('ProjectService|Integrations'), namespace_project_settings_integrations_path
- page_title _('Edit Project Hook')
.row.prepend-top-default .row.prepend-top-default
.col-lg-3 .col-lg-3
%h4.prepend-top-0 = render 'shared/web_hooks/title_and_docs', hook: @hook
= page_title
%p
#{link_to 'Webhooks', help_page_path('user/project/integrations/webhooks')} can be
used for binding events when something is happening within the project.
.col-lg-9.append-bottom-default .col-lg-9.append-bottom-default
= form_for [@project.namespace.becomes(Namespace), @project, @hook], as: :hook, url: project_hook_path(@project, @hook) do |f| = form_for [@project.namespace.becomes(Namespace), @project, @hook], as: :hook, url: project_hook_path(@project, @hook) do |f|
= render partial: 'shared/web_hooks/form', locals: { form: f, hook: @hook } = render partial: 'shared/web_hooks/form', locals: { form: f, hook: @hook }
= f.submit 'Save changes', class: 'btn btn-success' %span>= f.submit 'Save changes', class: 'btn btn-success append-right-8'
= render 'shared/web_hooks/test_button', triggers: ProjectHook.triggers, hook: @hook = render 'shared/web_hooks/test_button', hook: @hook
= link_to 'Remove', project_hook_path(@project, @hook), method: :delete, class: 'btn btn-remove float-right', data: { confirm: 'Are you sure?' } = link_to _('Delete'), project_hook_path(@project, @hook), method: :delete, class: 'btn btn-remove float-right', data: { confirm: _('Are you sure?') }
%hr %hr
......
%li
.row
.col-md-8.col-lg-7
%strong.light-header= hook.url
%div
- ProjectHook.triggers.each_value do |event|
- if hook.public_send(event)
%span.badge.badge-gray.deploy-project-label= event.to_s.titleize
.col-md-4.col-lg-5.text-right-lg.prepend-top-5
%span.append-right-10.inline
#{_("SSL Verification")}: #{hook.enable_ssl_verification ? _('enabled') : _('disabled')}
= link_to _('Edit'), edit_project_hook_path(@project, hook), class: 'btn btn-sm'
= render 'shared/web_hooks/test_button', triggers: ProjectHook.triggers, hook: hook, button_class: 'btn-sm'
= link_to project_hook_path(@project, hook), data: { confirm: _('Are you sure?') }, method: :delete, class: 'btn btn-transparent' do
%span.sr-only= _("Remove")
= icon('trash')
%li
.row
.col-md-8.col-lg-7
%strong.light-header= hook.url
%div
- hook.class.triggers.each_value do |trigger|
- if hook.public_send(trigger)
%span.badge.badge-gray.deploy-project-label= trigger.to_s.titleize
%span.badge.badge-gray
= _('SSL Verification:')
= hook.enable_ssl_verification ? _('enabled') : _('disabled')
.col-md-4.col-lg-5.text-right-md.prepend-top-5
%span>= render 'shared/web_hooks/test_button', hook: hook, button_class: 'btn-sm append-right-8'
%span>= link_to _('Edit'), edit_hook_path(hook), class: 'btn btn-sm append-right-8'
= link_to _('Delete'), destroy_hook_path(hook), data: { confirm: _('Are you sure?') }, method: :delete, class: 'btn btn-sm'
%hr
.card
.card-header
%h5
= hook_class.underscore.humanize.titleize.pluralize
(#{hooks.count})
- if hooks.any?
%ul.content-list
- hooks.each do |hook|
= render 'shared/web_hooks/hook', hook: hook
- else
%p.text-center.prepend-top-default.append-bottom-default
= _('No webhooks found, add one in the form above.')
- triggers = local_assigns.fetch(:triggers)
- button_class = local_assigns.fetch(:button_class, '') - button_class = local_assigns.fetch(:button_class, '')
- hook = local_assigns.fetch(:hook) - hook = local_assigns.fetch(:hook)
- triggers = hook.class.triggers
.hook-test-button.dropdown.inline .hook-test-button.dropdown.inline>
%button.btn{ 'data-toggle' => 'dropdown', class: button_class } %button.btn{ 'data-toggle' => 'dropdown', class: button_class }
Test = _('Test')
= icon('caret-down') = icon('caret-down')
%ul.dropdown-menu.dropdown-menu-right{ role: 'menu' } %ul.dropdown-menu.dropdown-menu-right{ role: 'menu' }
- triggers.each_value do |event| - triggers.each_value do |event|
......
%h4.prepend-top-0
= page_title
%p
- link = link_to(hook.pluralized_name, help_page_path(hook.help_path))
= _('%{link} can be used for binding events when something is happening within the project.').html_safe % { link: link }
...@@ -7,6 +7,7 @@ class Groups::HooksController < Groups::ApplicationController ...@@ -7,6 +7,7 @@ class Groups::HooksController < Groups::ApplicationController
before_action :group before_action :group
before_action :authorize_admin_group! before_action :authorize_admin_group!
before_action :check_group_webhooks_available! before_action :check_group_webhooks_available!
before_action :set_hook, only: [:edit, :update, :test, :destroy]
respond_to :html respond_to :html
...@@ -29,9 +30,21 @@ class Groups::HooksController < Groups::ApplicationController ...@@ -29,9 +30,21 @@ class Groups::HooksController < Groups::ApplicationController
end end
end end
def edit
end
def update
if @hook.update(hook_params)
flash[:notice] = _('Hook was successfully updated.')
redirect_to group_hooks_path(@group)
else
render 'edit'
end
end
def test def test
if @group.first_non_empty_project if @group.first_non_empty_project
service = TestHooks::ProjectService.new(hook, current_user, 'push_events') service = TestHooks::ProjectService.new(@hook, current_user, params[:trigger] || 'push_events')
service.project = @group.first_non_empty_project service.project = @group.first_non_empty_project
result = service.execute result = service.execute
...@@ -44,14 +57,14 @@ class Groups::HooksController < Groups::ApplicationController ...@@ -44,14 +57,14 @@ class Groups::HooksController < Groups::ApplicationController
end end
def destroy def destroy
hook.destroy @hook.destroy
redirect_to group_hooks_path(@group), status: :found redirect_to group_hooks_path(@group), status: :found
end end
private private
def hook def set_hook
@hook ||= @group.hooks.find(params[:id]) @hook ||= @group.hooks.find(params[:id])
end end
......
# frozen_string_literal: true
module EE
module HooksHelper
extend ::Gitlab::Utils::Override
override :test_hook_path
def test_hook_path(hook, trigger)
if hook.is_a?(GroupHook)
test_group_hook_path(hook.group, hook, trigger: trigger)
else
super
end
end
override :edit_hook_path
def edit_hook_path(hook)
if hook.is_a?(GroupHook)
edit_group_hook_path(hook.group, hook)
else
super
end
end
override :destroy_hook_path
def destroy_hook_path(hook)
if hook.is_a?(GroupHook)
group_hook_path(hook.group, hook)
else
super
end
end
end
end
...@@ -22,4 +22,8 @@ class GroupHook < ProjectHook ...@@ -22,4 +22,8 @@ class GroupHook < ProjectHook
clear_validators! clear_validators!
validates :url, presence: true, addressable_url: true validates :url, presence: true, addressable_url: true
def pluralized_name
_('Group Hooks')
end
end end
%li
.row
.col-md-8.col-lg-7
%strong.light-header= hook.url
%div
- GroupHook.triggers.each_value do |trigger|
- if hook.public_send(trigger)
%span.badge.badge-gray.deploy-project-label= trigger.to_s.titleize
.col-md-4.col-lg-5.text-right-lg.prepend-top-5
%span.append-right-10.inline
SSL Verification: #{hook.enable_ssl_verification ? "enabled" : "disabled"}
= link_to "Test", test_group_hook_path(@group, hook), class: "btn btn-sm", method: :post
= link_to group_hook_path(@group, hook), data: { confirm: 'Are you sure?'}, method: :delete, class: "btn btn-transparent" do
%span.sr-only Remove
= icon('trash')
- add_to_breadcrumbs @hook.pluralized_name, group_hooks_path(@group)
- page_title _('Edit Group Hook')
.row.prepend-top-default
.col-lg-3
= render 'shared/web_hooks/title_and_docs', hook: @hook
.col-lg-9.append-bottom-default
= form_for [@group, @hook], as: :hook, url: group_hook_path(@group, @hook) do |f|
= render partial: 'shared/web_hooks/form', locals: { form: f, hook: @hook }
%span>= f.submit _('Save changes'), class: 'btn btn-success append-right-8'
= render 'shared/web_hooks/test_button', hook: @hook
= link_to _('Delete'), group_hook_path(@group, @hook), method: :delete, class: 'btn btn-remove float-right', data: { confirm: _('Are you sure?') }
- page_title @hook.pluralized_name
- if @group.feature_available?(:group_webhooks) - if @group.feature_available?(:group_webhooks)
.row.prepend-top-default .row.prepend-top-default
.col-lg-3 .col-lg-3
%h4.prepend-top-0 = render 'shared/web_hooks/title_and_docs', hook: @hook
= page_title
%p
#{link_to 'Webhooks', help_page_path('user/project/integrations/webhooks')} can be
used for binding events when something is happening within the project.
.col-lg-9.append-bottom-default .col-lg-9.append-bottom-default
= form_for @hook, as: :hook, url: polymorphic_path([@group, :hooks]) do |f| = form_for @hook, as: :hook, url: polymorphic_path([@group, :hooks]) do |f|
= render partial: 'shared/web_hooks/form', locals: { form: f, hook: @hook } = render partial: 'shared/web_hooks/form', locals: { form: f, hook: @hook }
= f.submit 'Add webhook', class: 'btn btn-success' = f.submit _('Add webhook'), class: 'btn btn-success'
%hr = render 'shared/web_hooks/index', hooks: @hooks, hook_class: @hook.class
%h5.prepend-top-default
Webhooks (#{@hooks.count})
- if @hooks.any?
%ul.content-list
- @hooks.each do |hook|
= render 'project_hook', hook: hook
- else
%p.settings-message.text-center.append-bottom-0
No webhooks found, add one in the form above.
- elsif show_promotions? - elsif show_promotions?
= render 'shared/promotions/promote_group_webhooks' = render 'shared/promotions/promote_group_webhooks'
---
title: Add ability to edit Group Hooks
merge_request: 20898
author:
type: changed
...@@ -51,7 +51,7 @@ constraints(::Constraints::GroupUrlConstrainer.new) do ...@@ -51,7 +51,7 @@ constraints(::Constraints::GroupUrlConstrainer.new) do
resources :audit_events, only: [:index] resources :audit_events, only: [:index]
resources :usage_quotas, only: [:index] resources :usage_quotas, only: [:index]
resources :hooks, only: [:index, :create, :destroy], constraints: { id: /\d+/ } do resources :hooks, only: [:index, :create, :edit, :update, :destroy], constraints: { id: /\d+/ } do
member do member do
post :test post :test
end end
......
...@@ -36,8 +36,8 @@ describe Groups::HooksController do ...@@ -36,8 +36,8 @@ describe Groups::HooksController do
pipeline_events: true, pipeline_events: true,
push_events: true, push_events: true,
tag_push_events: true, tag_push_events: true,
token: "TEST TOKEN", token: 'TEST TOKEN',
url: "http://example.com", url: 'http://example.com',
wiki_page_events: true wiki_page_events: true
} }
...@@ -48,6 +48,114 @@ describe Groups::HooksController do ...@@ -48,6 +48,114 @@ describe Groups::HooksController do
expect(group.hooks.first).to have_attributes(hook_params) expect(group.hooks.first).to have_attributes(hook_params)
end end
end end
describe 'GET #edit' do
let(:hook) { create(:group_hook, group: group) }
it 'is successfull' do
get :edit, params: { group_id: group.to_param, id: hook }
expect(response).to have_gitlab_http_status(200)
expect(response).to render_template(:edit)
expect(group.hooks.size).to eq(1)
end
end
describe 'PATCH #update' do
let(:hook) { create(:group_hook, group: group) }
context 'valid params' do
let(:hook_params) do
{
job_events: true,
confidential_issues_events: true,
enable_ssl_verification: true,
issues_events: true,
merge_requests_events: true,
note_events: true,
pipeline_events: true,
push_events: true,
tag_push_events: true,
token: 'TEST TOKEN',
url: 'http://example.com',
wiki_page_events: true
}
end
it 'is successfull' do
patch :update, params: { group_id: group.to_param, id: hook, hook: hook_params }
expect(response).to have_gitlab_http_status(302)
expect(response).to redirect_to(group_hooks_path(group))
expect(group.hooks.size).to eq(1)
expect(group.hooks.first).to have_attributes(hook_params)
end
end
context 'invalid params' do
let(:hook_params) do
{
url: ''
}
end
it 'renders "edit" template' do
patch :update, params: { group_id: group.to_param, id: hook, hook: hook_params }
expect(response).to have_gitlab_http_status(200)
expect(response).to render_template(:edit)
expect(group.hooks.size).to eq(1)
expect(group.hooks.first).not_to have_attributes(hook_params)
end
end
end
describe 'POST #test' do
let(:hook) { create(:group_hook, group: group) }
context 'when group does not have a project' do
it 'redirects back' do
expect(TestHooks::ProjectService).not_to receive(:new)
post :test, params: { group_id: group.to_param, id: hook }
expect(response).to have_gitlab_http_status(302)
expect(flash[:alert]).to eq('Hook execution failed. Ensure the group has a project with commits.')
end
end
context 'when group has a project' do
let!(:project) { create(:project, :repository, group: group) }
context 'when "trigger" params is empty' do
it 'defaults to "push_events"' do
expect_next_instance_of(TestHooks::ProjectService, hook, user, 'push_events') do |service|
expect(service).to receive(:execute).and_return(http_status: 200)
end
post :test, params: { group_id: group.to_param, id: hook }
expect(response).to have_gitlab_http_status(302)
expect(flash[:notice]).to eq('Hook executed successfully: HTTP 200')
end
end
context 'when "trigger" params is set' do
let(:trigger) { 'issue_hooks' }
it 'uses it' do
expect_next_instance_of(TestHooks::ProjectService, hook, user, trigger) do |service|
expect(service).to receive(:execute).and_return(http_status: 200)
end
post :test, params: { group_id: group.to_param, id: hook, trigger: trigger }
expect(response).to have_gitlab_http_status(302)
expect(flash[:notice]).to eq('Hook executed successfully: HTTP 200')
end
end
end
end
end end
context 'with group_webhooks disabled' do context 'with group_webhooks disabled' do
......
# frozen_string_literal: true
require 'spec_helper'
describe 'User edits hooks' do
set(:group) { create(:group) }
set(:hook) { create(:group_hook, group: group) }
set(:user) { create(:user) }
let(:url) { 'http://example.org/new' }
before do
group.add_owner(user)
sign_in(user)
visit(group_hooks_path(group))
end
it 'updates existing hook' do
click_link('Edit')
expect(current_path).to eq(edit_group_hook_path(group, hook))
fill_in('URL', with: url)
click_button('Save changes')
expect(hook.reload.url).to eq(url)
expect(current_path).to eq(group_hooks_path(group))
expect(page).to have_selector('.flash-notice', text: 'Hook was successfully updated.')
end
end
...@@ -35,7 +35,8 @@ describe "User tests hooks", :js do ...@@ -35,7 +35,8 @@ describe "User tests hooks", :js do
before do before do
stub_full_request(hook.url, method: :post).to_raise(SocketError.new("Failed to open")) stub_full_request(hook.url, method: :post).to_raise(SocketError.new("Failed to open"))
click_link("Test") click_button('Test')
click_link('Push events')
end end
it { expect(page).to have_selector(".flash-alert", text: "Hook execution failed: Failed to open") } it { expect(page).to have_selector(".flash-alert", text: "Hook execution failed: Failed to open") }
...@@ -57,6 +58,7 @@ describe "User tests hooks", :js do ...@@ -57,6 +58,7 @@ describe "User tests hooks", :js do
def trigger_hook def trigger_hook
stub_full_request(hook.url, method: :post).to_return(status: 200) stub_full_request(hook.url, method: :post).to_return(status: 200)
click_link("Test") click_button('Test')
click_link('Push events')
end end
end end
# frozen_string_literal: true
require 'spec_helper'
describe HooksHelper do
let(:group) { create(:group) }
let(:group_hook) { create(:group_hook, group: group) }
let(:trigger) { 'push_events' }
describe '#link_to_test_hook' do
it 'returns group namespaced link' do
expect(helper.link_to_test_hook(group_hook, trigger))
.to include("href=\"#{test_group_hook_path(group, group_hook, trigger: trigger)}\"")
end
end
end
...@@ -75,6 +75,14 @@ describe 'Group routing', "routing" do ...@@ -75,6 +75,14 @@ describe 'Group routing', "routing" do
end end
end end
describe 'hooks' do
it 'routes to hooks edit page' do
allow(Group).to receive(:find_by_full_path).with('gitlabhq', any_args).and_return(true)
expect(get('/groups/gitlabhq/-/hooks/2/edit')).to route_to('groups/hooks#edit', group_id: 'gitlabhq', id: '2')
end
end
describe 'packages' do describe 'packages' do
it 'routes to packages index page' do it 'routes to packages index page' do
allow(Group).to receive(:find_by_full_path).with('gitlabhq', any_args).and_return(true) allow(Group).to receive(:find_by_full_path).with('gitlabhq', any_args).and_return(true)
......
...@@ -299,6 +299,9 @@ msgstr "" ...@@ -299,6 +299,9 @@ msgstr ""
msgid "%{link_start}Read more%{link_end} about role permissions" msgid "%{link_start}Read more%{link_end} about role permissions"
msgstr "" msgstr ""
msgid "%{link} can be used for binding events when something is happening within the project."
msgstr ""
msgid "%{listToShow}, and %{awardsListLength} more." msgid "%{listToShow}, and %{awardsListLength} more."
msgstr "" msgstr ""
...@@ -1055,6 +1058,9 @@ msgstr "" ...@@ -1055,6 +1058,9 @@ msgstr ""
msgid "Add request manually" msgid "Add request manually"
msgstr "" msgstr ""
msgid "Add system hook"
msgstr ""
msgid "Add to Slack" msgid "Add to Slack"
msgstr "" msgstr ""
...@@ -1082,6 +1088,9 @@ msgstr "" ...@@ -1082,6 +1088,9 @@ msgstr ""
msgid "Add users to group" msgid "Add users to group"
msgstr "" msgstr ""
msgid "Add webhook"
msgstr ""
msgid "AddMember|No users specified." msgid "AddMember|No users specified."
msgstr "" msgstr ""
...@@ -6254,6 +6263,9 @@ msgstr "" ...@@ -6254,6 +6263,9 @@ msgstr ""
msgid "Edit Deploy Key" msgid "Edit Deploy Key"
msgstr "" msgstr ""
msgid "Edit Group Hook"
msgstr ""
msgid "Edit Label" msgid "Edit Label"
msgstr "" msgstr ""
...@@ -6266,12 +6278,18 @@ msgstr "" ...@@ -6266,12 +6278,18 @@ msgstr ""
msgid "Edit Pipeline Schedule %{id}" msgid "Edit Pipeline Schedule %{id}"
msgstr "" msgstr ""
msgid "Edit Project Hook"
msgstr ""
msgid "Edit Release" msgid "Edit Release"
msgstr "" msgstr ""
msgid "Edit Snippet" msgid "Edit Snippet"
msgstr "" msgstr ""
msgid "Edit System Hook"
msgstr ""
msgid "Edit application" msgid "Edit application"
msgstr "" msgstr ""
...@@ -8749,6 +8767,9 @@ msgstr "" ...@@ -8749,6 +8767,9 @@ msgstr ""
msgid "Group Git LFS status:" msgid "Group Git LFS status:"
msgstr "" msgstr ""
msgid "Group Hooks"
msgstr ""
msgid "Group ID" msgid "Group ID"
msgstr "" msgstr ""
...@@ -11850,6 +11871,9 @@ msgstr "" ...@@ -11850,6 +11871,9 @@ msgstr ""
msgid "No vulnerabilities present" msgid "No vulnerabilities present"
msgstr "" msgstr ""
msgid "No webhooks found, add one in the form above."
msgstr ""
msgid "No, directly import the existing email addresses and usernames." msgid "No, directly import the existing email addresses and usernames."
msgstr "" msgstr ""
...@@ -13550,6 +13574,9 @@ msgstr "" ...@@ -13550,6 +13574,9 @@ msgstr ""
msgid "Project Files" msgid "Project Files"
msgstr "" msgstr ""
msgid "Project Hooks"
msgstr ""
msgid "Project ID" msgid "Project ID"
msgstr "" msgstr ""
...@@ -15309,7 +15336,7 @@ msgstr "" ...@@ -15309,7 +15336,7 @@ msgstr ""
msgid "SSH public key" msgid "SSH public key"
msgstr "" msgstr ""
msgid "SSL Verification" msgid "SSL Verification:"
msgstr "" msgstr ""
msgid "Saturday" msgid "Saturday"
...@@ -17463,6 +17490,9 @@ msgstr "" ...@@ -17463,6 +17490,9 @@ msgstr ""
msgid "Terms of Service and Privacy Policy" msgid "Terms of Service and Privacy Policy"
msgstr "" msgstr ""
msgid "Test"
msgstr ""
msgid "Test coverage parsing" msgid "Test coverage parsing"
msgstr "" msgstr ""
......
...@@ -85,7 +85,7 @@ describe 'Admin::Hooks' do ...@@ -85,7 +85,7 @@ describe 'Admin::Hooks' do
it 'from hooks list page' do it 'from hooks list page' do
visit admin_hooks_path visit admin_hooks_path
accept_confirm { click_link 'Remove' } accept_confirm { click_link 'Delete' }
expect(page).not_to have_content(hook_url) expect(page).not_to have_content(hook_url)
end end
...@@ -93,7 +93,7 @@ describe 'Admin::Hooks' do ...@@ -93,7 +93,7 @@ describe 'Admin::Hooks' do
visit admin_hooks_path visit admin_hooks_path
click_link 'Edit' click_link 'Edit'
accept_confirm { click_link 'Remove' } accept_confirm { click_link 'Delete' }
expect(page).not_to have_content(hook_url) expect(page).not_to have_content(hook_url)
end end
end end
......
...@@ -89,12 +89,12 @@ describe 'Projects > Settings > Integration settings' do ...@@ -89,12 +89,12 @@ describe 'Projects > Settings > Integration settings' do
expect(current_path).to eq(integrations_path) expect(current_path).to eq(integrations_path)
end end
context 'remove existing webhook' do context 'delete existing webhook' do
it 'from webhooks list page' do it 'from webhooks list page' do
hook hook
visit integrations_path visit integrations_path
expect { click_link 'Remove' }.to change(ProjectHook, :count).by(-1) expect { click_link 'Delete' }.to change(ProjectHook, :count).by(-1)
end end
it 'from webhook edit page' do it 'from webhook edit page' do
...@@ -102,7 +102,7 @@ describe 'Projects > Settings > Integration settings' do ...@@ -102,7 +102,7 @@ describe 'Projects > Settings > Integration settings' do
visit integrations_path visit integrations_path
click_link 'Edit' click_link 'Edit'
expect { click_link 'Remove' }.to change(ProjectHook, :count).by(-1) expect { click_link 'Delete' }.to change(ProjectHook, :count).by(-1)
end end
end end
end end
......
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