BigW Consortium Gitlab

Commit 39772f01 by Dmitriy Zaporozhets

Merge branch 'ci-web-hooks'

parents b6808f43 ecbe393b
......@@ -30,6 +30,7 @@ v 8.1.0 (unreleased)
- Fix wrong access level badge on MR comments
- Hide password in the service settings form
- Fix anchors to comments in diffs
- Move CI web hooks page to project settings area
v 8.0.3
- Fix URL shown in Slack notifications
......
module Ci
class WebHooksController < Ci::ApplicationController
before_action :authenticate_user!
before_action :project
before_action :authorize_access_project!
before_action :authorize_manage_project!
class Projects::CiWebHooksController < Projects::ApplicationController
before_action :ci_project
before_action :authorize_admin_project!
layout 'ci/project'
layout "project_settings"
def index
@web_hooks = @project.web_hooks
@web_hooks = @ci_project.web_hooks
@web_hook = Ci::WebHook.new
end
def create
@web_hook = @project.web_hooks.new(web_hook_params)
@web_hook = @ci_project.web_hooks.new(web_hook_params)
@web_hook.save
if @web_hook.valid?
redirect_to ci_project_web_hooks_path(@project)
redirect_to namespace_project_ci_web_hooks_path(@project.namespace, @project)
else
@web_hooks = @project.web_hooks.select(&:persisted?)
@web_hooks = @ci_project.web_hooks.select(&:persisted?)
render :index
end
end
......@@ -33,21 +30,16 @@ module Ci
def destroy
hook.destroy
redirect_to ci_project_web_hooks_path(@project)
redirect_to namespace_project_ci_web_hooks_path(@project.namespace, @project)
end
private
def hook
@web_hook ||= @project.web_hooks.find(params[:id])
end
def project
@project = Ci::Project.find(params[:project_id])
@web_hook ||= @ci_project.web_hooks.find(params[:id])
end
def web_hook_params
params.require(:web_hook).permit(:url)
end
end
end
......@@ -11,11 +11,6 @@
%span
Commits
%span.count= @project.commits.count
= nav_link path: 'web_hooks#index' do
= link_to ci_project_web_hooks_path(@project) do
= icon('link fw')
%span
Web Hooks
= nav_link path: ['services#index', 'services#edit'] do
= link_to ci_project_services_path(@project) do
= icon('share fw')
......
......@@ -50,6 +50,11 @@
= icon('retweet fw')
%span
Triggers
= nav_link path: 'ci_web_hooks#index' do
= link_to namespace_project_ci_web_hooks_path(@project.namespace, @project) do
= icon('link fw')
%span
CI Web Hooks
= nav_link path: 'ci_settings#edit' do
= link_to edit_namespace_project_ci_settings_path(@project.namespace, @project) do
= icon('building fw')
......
%h3.page-title
Web hooks
CI Web hooks
%p.light
Web Hooks can be used for binding events when build completed.
%hr.clearfix
= form_for [:ci, @project, @web_hook], html: { class: 'form-horizontal' } do |f|
= form_for @web_hook, url: namespace_project_ci_web_hooks_path(@project.namespace, @project), html: { class: 'form-horizontal' } do |f|
-if @web_hook.errors.any?
.alert.alert-danger
- @web_hook.errors.full_messages.each do |msg|
......@@ -28,9 +28,9 @@
%span.monospace= hook.url
%td
.pull-right
- if @project.commits.any?
= link_to 'Test Hook', test_ci_project_web_hook_path(@project, hook), class: "btn btn-sm btn-grouped"
= link_to 'Remove', ci_project_web_hook_path(@project, hook), data: { confirm: 'Are you sure?'}, method: :delete, class: "btn btn-remove btn-sm btn-grouped"
- if @ci_project.commits.any?
= link_to 'Test Hook', test_namespace_project_ci_web_hook_path(@project.namespace, @project, hook), class: "btn btn-sm btn-grouped"
= link_to 'Remove', namespace_project_ci_web_hook_path(@project.namespace, @project, hook), data: { confirm: 'Are you sure?'}, method: :delete, class: "btn btn-remove btn-sm btn-grouped"
%h4 Web Hook data example
......
......@@ -47,12 +47,6 @@ Gitlab::Application.routes.draw do
end
end
resources :web_hooks, only: [:index, :create, :destroy] do
member do
get :test
end
end
resources :runner_projects, only: [:create, :destroy]
resources :events, only: [:index]
......@@ -591,6 +585,11 @@ Gitlab::Application.routes.draw do
resource :variables, only: [:show, :update]
resources :triggers, only: [:index, :create, :destroy]
resource :ci_settings, only: [:edit, :update, :destroy]
resources :ci_web_hooks, only: [:index, :create, :destroy] do
member do
get :test
end
end
resources :hooks, only: [:index, :create, :destroy], constraints: { id: /\d+/ } do
member do
......
require 'spec_helper'
describe 'CI web hooks' do
let(:user) { create(:user) }
before { login_as(user) }
before do
@project = FactoryGirl.create :ci_project
@gl_project = @project.gl_project
@gl_project.team << [user, :master]
visit namespace_project_ci_web_hooks_path(@gl_project.namespace, @gl_project)
end
context 'create a trigger' do
before do
fill_in 'web_hook_url', with: 'http://example.com'
click_on 'Add Web Hook'
end
it { expect(@project.web_hooks.count).to eq(1) }
it 'revokes the trigger' do
click_on 'Remove'
expect(@project.web_hooks.count).to eq(0)
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