From c293cc91522544f5a45fc00b842fc23fa228cdf9 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 5 Oct 2015 10:47:23 +0200 Subject: Move CI web hooks page to project settings area Signed-off-by: Dmitriy Zaporozhets --- CHANGELOG | 1 + app/controllers/ci/web_hooks_controller.rb | 53 ------------- .../projects/ci_web_hooks_controller.rb | 45 +++++++++++ app/views/ci/web_hooks/index.html.haml | 92 ---------------------- app/views/layouts/ci/_nav_project.html.haml | 5 -- app/views/layouts/nav/_project_settings.html.haml | 5 ++ app/views/projects/ci_web_hooks/index.html.haml | 92 ++++++++++++++++++++++ config/routes.rb | 11 ++- spec/features/ci_web_hooks_spec.rb | 27 +++++++ 9 files changed, 175 insertions(+), 156 deletions(-) delete mode 100644 app/controllers/ci/web_hooks_controller.rb create mode 100644 app/controllers/projects/ci_web_hooks_controller.rb delete mode 100644 app/views/ci/web_hooks/index.html.haml create mode 100644 app/views/projects/ci_web_hooks/index.html.haml create mode 100644 spec/features/ci_web_hooks_spec.rb diff --git a/CHANGELOG b/CHANGELOG index ec23d0f1172..4a2dbdbaac3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -29,6 +29,7 @@ v 8.1.0 (unreleased) - Ensure code blocks are properly highlighted after a note is updated - Fix wrong access level badge on MR comments - Hide password in the service settings form + - Move CI web hooks page to project settings area v 8.0.3 - Fix URL shown in Slack notifications diff --git a/app/controllers/ci/web_hooks_controller.rb b/app/controllers/ci/web_hooks_controller.rb deleted file mode 100644 index 24074a6d9ac..00000000000 --- a/app/controllers/ci/web_hooks_controller.rb +++ /dev/null @@ -1,53 +0,0 @@ -module Ci - class WebHooksController < Ci::ApplicationController - before_action :authenticate_user! - before_action :project - before_action :authorize_access_project! - before_action :authorize_manage_project! - - layout 'ci/project' - - def index - @web_hooks = @project.web_hooks - @web_hook = Ci::WebHook.new - end - - def create - @web_hook = @project.web_hooks.new(web_hook_params) - @web_hook.save - - if @web_hook.valid? - redirect_to ci_project_web_hooks_path(@project) - else - @web_hooks = @project.web_hooks.select(&:persisted?) - render :index - end - end - - def test - Ci::TestHookService.new.execute(hook, current_user) - - redirect_to :back - end - - def destroy - hook.destroy - - redirect_to ci_project_web_hooks_path(@project) - end - - private - - def hook - @web_hook ||= @project.web_hooks.find(params[:id]) - end - - def project - @project = Ci::Project.find(params[:project_id]) - end - - def web_hook_params - params.require(:web_hook).permit(:url) - end - end -end diff --git a/app/controllers/projects/ci_web_hooks_controller.rb b/app/controllers/projects/ci_web_hooks_controller.rb new file mode 100644 index 00000000000..7f40ddcb3f3 --- /dev/null +++ b/app/controllers/projects/ci_web_hooks_controller.rb @@ -0,0 +1,45 @@ +class Projects::CiWebHooksController < Projects::ApplicationController + before_action :ci_project + before_action :authorize_admin_project! + + layout "project_settings" + + def index + @web_hooks = @ci_project.web_hooks + @web_hook = Ci::WebHook.new + end + + def create + @web_hook = @ci_project.web_hooks.new(web_hook_params) + @web_hook.save + + if @web_hook.valid? + redirect_to namespace_project_ci_web_hooks_path(@project.namespace, @project) + else + @web_hooks = @ci_project.web_hooks.select(&:persisted?) + render :index + end + end + + def test + Ci::TestHookService.new.execute(hook, current_user) + + redirect_to :back + end + + def destroy + hook.destroy + + redirect_to namespace_project_ci_web_hooks_path(@project.namespace, @project) + end + + private + + def hook + @web_hook ||= @ci_project.web_hooks.find(params[:id]) + end + + def web_hook_params + params.require(:web_hook).permit(:url) + end +end diff --git a/app/views/ci/web_hooks/index.html.haml b/app/views/ci/web_hooks/index.html.haml deleted file mode 100644 index 78e8203b25e..00000000000 --- a/app/views/ci/web_hooks/index.html.haml +++ /dev/null @@ -1,92 +0,0 @@ -%h3.page-title - 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| - -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 - - 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" - -%h4 Web Hook data example - -:erb -
-    
-      {
-        "build_id": 2,
-        "build_name":"rspec_linux"
-        "build_status": "failed",
-        "build_started_at": "2014-05-05T18:01:02.563Z",
-        "build_finished_at": "2014-05-05T18:01:07.611Z",
-        "project_id": 1,
-        "project_name": "Brightbox \/ Brightbox Cli",
-        "gitlab_url": "http:\/\/localhost:3000\/brightbox\/brightbox-cli",
-        "ref": "master",
-        "sha": "a26cf5de9ed9827746d4970872376b10d9325f40",
-        "before_sha": "34f57f6ba3ed0c21c5e361bbb041c3591411176c",
-        "push_data": {
-          "before": "34f57f6ba3ed0c21c5e361bbb041c3591411176c",
-          "after": "a26cf5de9ed9827746d4970872376b10d9325f40",
-          "ref": "refs\/heads\/master",
-          "user_id": 1,
-          "user_name": "Administrator",
-          "project_id": 5,
-          "repository": {
-            "name": "Brightbox Cli",
-            "url": "dzaporozhets@localhost:brightbox\/brightbox-cli.git",
-            "description": "Voluptatibus quae error consectetur voluptas dolores vel excepturi possimus.",
-            "homepage": "http:\/\/localhost:3000\/brightbox\/brightbox-cli"
-          },
-          "commits": [
-            {
-              "id": "a26cf5de9ed9827746d4970872376b10d9325f40",
-              "message": "Release v1.2.2",
-              "timestamp": "2014-04-22T16:46:42+03:00",
-              "url": "http:\/\/localhost:3000\/brightbox\/brightbox-cli\/commit\/a26cf5de9ed9827746d4970872376b10d9325f40",
-              "author": {
-                "name": "Paul Thornthwaite",
-                "email": "tokengeek@gmail.com"
-              }
-            },
-            {
-              "id": "34f57f6ba3ed0c21c5e361bbb041c3591411176c",
-              "message": "Fix server user data update\n\nIncorrect condition was being used so Base64 encoding option was having\nopposite effect from desired.",
-              "timestamp": "2014-04-11T18:17:26+03:00",
-              "url": "http:\/\/localhost:3000\/brightbox\/brightbox-cli\/commit\/34f57f6ba3ed0c21c5e361bbb041c3591411176c",
-              "author": {
-                "name": "Paul Thornthwaite",
-                "email": "tokengeek@gmail.com"
-              }
-            }
-          ],
-          "total_commits_count": 2,
-          "ci_yaml_file":"rspec_linux:\r\n  script: ls\r\n"
-        }
-      }
-    
-  
diff --git a/app/views/layouts/ci/_nav_project.html.haml b/app/views/layouts/ci/_nav_project.html.haml index 3a2741367c1..545abc23d99 100644 --- a/app/views/layouts/ci/_nav_project.html.haml +++ b/app/views/layouts/ci/_nav_project.html.haml @@ -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') diff --git a/app/views/layouts/nav/_project_settings.html.haml b/app/views/layouts/nav/_project_settings.html.haml index 26cccb48f68..abee5e1b3f3 100644 --- a/app/views/layouts/nav/_project_settings.html.haml +++ b/app/views/layouts/nav/_project_settings.html.haml @@ -50,6 +50,11 @@ = icon('retweet fw') %span Triggers + = nav_link path: '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') diff --git a/app/views/projects/ci_web_hooks/index.html.haml b/app/views/projects/ci_web_hooks/index.html.haml new file mode 100644 index 00000000000..c3fe4db8149 --- /dev/null +++ b/app/views/projects/ci_web_hooks/index.html.haml @@ -0,0 +1,92 @@ +%h3.page-title + Web hooks + +%p.light + Web Hooks can be used for binding events when build completed. + +%hr.clearfix + += 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| + %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 + - 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 + +:erb +
+    
+      {
+        "build_id": 2,
+        "build_name":"rspec_linux"
+        "build_status": "failed",
+        "build_started_at": "2014-05-05T18:01:02.563Z",
+        "build_finished_at": "2014-05-05T18:01:07.611Z",
+        "project_id": 1,
+        "project_name": "Brightbox \/ Brightbox Cli",
+        "gitlab_url": "http:\/\/localhost:3000\/brightbox\/brightbox-cli",
+        "ref": "master",
+        "sha": "a26cf5de9ed9827746d4970872376b10d9325f40",
+        "before_sha": "34f57f6ba3ed0c21c5e361bbb041c3591411176c",
+        "push_data": {
+          "before": "34f57f6ba3ed0c21c5e361bbb041c3591411176c",
+          "after": "a26cf5de9ed9827746d4970872376b10d9325f40",
+          "ref": "refs\/heads\/master",
+          "user_id": 1,
+          "user_name": "Administrator",
+          "project_id": 5,
+          "repository": {
+            "name": "Brightbox Cli",
+            "url": "dzaporozhets@localhost:brightbox\/brightbox-cli.git",
+            "description": "Voluptatibus quae error consectetur voluptas dolores vel excepturi possimus.",
+            "homepage": "http:\/\/localhost:3000\/brightbox\/brightbox-cli"
+          },
+          "commits": [
+            {
+              "id": "a26cf5de9ed9827746d4970872376b10d9325f40",
+              "message": "Release v1.2.2",
+              "timestamp": "2014-04-22T16:46:42+03:00",
+              "url": "http:\/\/localhost:3000\/brightbox\/brightbox-cli\/commit\/a26cf5de9ed9827746d4970872376b10d9325f40",
+              "author": {
+                "name": "Paul Thornthwaite",
+                "email": "tokengeek@gmail.com"
+              }
+            },
+            {
+              "id": "34f57f6ba3ed0c21c5e361bbb041c3591411176c",
+              "message": "Fix server user data update\n\nIncorrect condition was being used so Base64 encoding option was having\nopposite effect from desired.",
+              "timestamp": "2014-04-11T18:17:26+03:00",
+              "url": "http:\/\/localhost:3000\/brightbox\/brightbox-cli\/commit\/34f57f6ba3ed0c21c5e361bbb041c3591411176c",
+              "author": {
+                "name": "Paul Thornthwaite",
+                "email": "tokengeek@gmail.com"
+              }
+            }
+          ],
+          "total_commits_count": 2,
+          "ci_yaml_file":"rspec_linux:\r\n  script: ls\r\n"
+        }
+      }
+    
+  
diff --git a/config/routes.rb b/config/routes.rb index 6d96d8801cd..7bda7ade817 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/spec/features/ci_web_hooks_spec.rb b/spec/features/ci_web_hooks_spec.rb new file mode 100644 index 00000000000..efae0a42c1e --- /dev/null +++ b/spec/features/ci_web_hooks_spec.rb @@ -0,0 +1,27 @@ +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 -- cgit v1.2.1