diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-05-05 20:35:42 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-05-05 20:35:42 +0300 |
commit | b7c133215ac98b74006ceaf9c1dcd39b03903ffc (patch) | |
tree | f897f9f3235d59f3e6165ff6c98de7f44d66825c | |
parent | 3e11a6b714e2da027f0869a984bcb1733276d332 (diff) | |
download | gitlab-ci-b7c133215ac98b74006ceaf9c1dcd39b03903ffc.tar.gz |
WebHook scaffold
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r-- | app/controllers/web_hooks_controller.rb | 46 | ||||
-rw-r--r-- | app/views/layouts/project.html.haml | 4 | ||||
-rw-r--r-- | app/views/web_hooks/index.html.haml | 32 | ||||
-rw-r--r-- | config/routes.rb | 6 |
4 files changed, 88 insertions, 0 deletions
diff --git a/app/controllers/web_hooks_controller.rb b/app/controllers/web_hooks_controller.rb new file mode 100644 index 0000000..f7906ff --- /dev/null +++ b/app/controllers/web_hooks_controller.rb @@ -0,0 +1,46 @@ +class WebHooksController < ApplicationController + before_filter :authenticate_user! + before_filter :project + before_filter :authorize_access_project! + + layout 'project' + + def index + @web_hooks = @project.web_hooks + @web_hook = WebHook.new + end + + def create + @web_hook = @project.web_hooks.new(params[:web_hook]) + @web_hook.save + + if @web_hook.valid? + redirect_to project_web_hooks_path(@project) + else + @web_hooks = @project.web_hooks.select(&:persisted?) + render :index + end + end + + def test + TestHookService.new.execute(hook, current_user) + + redirect_to :back + end + + def destroy + hook.destroy + + redirect_to project_web_hooks_path(@project) + end + + private + + def hook + @web_hook ||= @project.web_hooks.find(params[:id]) + end + + def project + @project = Project.find(params[:project_id]) + end +end diff --git a/app/views/layouts/project.html.haml b/app/views/layouts/project.html.haml index 6d27878..9b6355a 100644 --- a/app/views/layouts/project.html.haml +++ b/app/views/layouts/project.html.haml @@ -34,6 +34,10 @@ = link_to integration_project_path(@project) do %i.icon-wrench Integration + = nav_link path: 'web_hooks#index' do + = link_to project_web_hooks_path(@project) do + %i.icon-link + Web Hooks = nav_link path: 'projects#edit' do = link_to edit_project_path(@project) do %i.icon-edit diff --git a/app/views/web_hooks/index.html.haml b/app/views/web_hooks/index.html.haml new file mode 100644 index 0000000..dc91a98 --- /dev/null +++ b/app/views/web_hooks/index.html.haml @@ -0,0 +1,32 @@ +%h3 + Web hooks + +%p.light + Web Hooks can be used for binding events when build completed. + +%hr.clearfix + += form_for [@project, @web_hook], html: { class: 'form-horizontal' } do |f| + -if @web_hook.errors.any? + .alert.alert-danger + - @web_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-actions + = f.submit "Add Web Hook", class: "btn btn-create" + +-if @web_hooks.any? + %h4 Activated web hooks (#{@web_hooks.count}) + %table.table + - @web_hooks.each do |hook| + %tr + %td + .clearfix + %span.monospace= hook.url + %td + .pull-right + = link_to 'Test Hook', test_project_web_hook_path(@project, hook), class: "btn btn-small btn-grouped" + = link_to 'Remove', project_web_hook_path(@project, hook), data: { confirm: 'Are you sure?'}, method: :delete, class: "btn btn-remove btn-small btn-grouped" diff --git a/config/routes.rb b/config/routes.rb index ee1c998..6c333b7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -28,6 +28,12 @@ GitlabCi::Application.routes.draw do post :retry end end + + resources :web_hooks, only: [:index, :create, :destroy] do + member do + get :test + end + end end resource :user_sessions |