Commit 28cb43135ce7691a7b0022cb8fcb719d0e46c810

Authored by Dmitriy Zaporozhets
1 parent 7b7547aa

Hooks UI improved, Request tests added

1 source "http://rubygems.org" 1 source "http://rubygems.org"
2 2
3 -gem "rails", "3.2.1" 3 +gem "rails", "3.2.3"
4 4
5 gem "sqlite3" 5 gem "sqlite3"
6 gem "mysql2" 6 gem "mysql2"
@@ -39,7 +39,7 @@ gem 'modularity' @@ -39,7 +39,7 @@ gem 'modularity'
39 39
40 group :assets do 40 group :assets do
41 gem "sass-rails", "3.2.3" 41 gem "sass-rails", "3.2.3"
42 - gem "coffee-rails", "3.2.1" 42 + gem "coffee-rails", "3.2.2"
43 gem "uglifier", "1.0.3" 43 gem "uglifier", "1.0.3"
44 end 44 end
45 45
@@ -41,31 +41,31 @@ GEM @@ -41,31 +41,31 @@ GEM
41 remote: http://rubygems.org/ 41 remote: http://rubygems.org/
42 specs: 42 specs:
43 ZenTest (4.5.0) 43 ZenTest (4.5.0)
44 - actionmailer (3.2.1)  
45 - actionpack (= 3.2.1)  
46 - mail (~> 2.4.0)  
47 - actionpack (3.2.1)  
48 - activemodel (= 3.2.1)  
49 - activesupport (= 3.2.1) 44 + actionmailer (3.2.3)
  45 + actionpack (= 3.2.3)
  46 + mail (~> 2.4.4)
  47 + actionpack (3.2.3)
  48 + activemodel (= 3.2.3)
  49 + activesupport (= 3.2.3)
50 builder (~> 3.0.0) 50 builder (~> 3.0.0)
51 erubis (~> 2.7.0) 51 erubis (~> 2.7.0)
52 journey (~> 1.0.1) 52 journey (~> 1.0.1)
53 rack (~> 1.4.0) 53 rack (~> 1.4.0)
54 - rack-cache (~> 1.1) 54 + rack-cache (~> 1.2)
55 rack-test (~> 0.6.1) 55 rack-test (~> 0.6.1)
56 sprockets (~> 2.1.2) 56 sprockets (~> 2.1.2)
57 - activemodel (3.2.1)  
58 - activesupport (= 3.2.1) 57 + activemodel (3.2.3)
  58 + activesupport (= 3.2.3)
59 builder (~> 3.0.0) 59 builder (~> 3.0.0)
60 - activerecord (3.2.1)  
61 - activemodel (= 3.2.1)  
62 - activesupport (= 3.2.1)  
63 - arel (~> 3.0.0) 60 + activerecord (3.2.3)
  61 + activemodel (= 3.2.3)
  62 + activesupport (= 3.2.3)
  63 + arel (~> 3.0.2)
64 tzinfo (~> 0.3.29) 64 tzinfo (~> 0.3.29)
65 - activeresource (3.2.1)  
66 - activemodel (= 3.2.1)  
67 - activesupport (= 3.2.1)  
68 - activesupport (3.2.1) 65 + activeresource (3.2.3)
  66 + activemodel (= 3.2.3)
  67 + activesupport (= 3.2.3)
  68 + activesupport (3.2.3)
69 i18n (~> 0.6) 69 i18n (~> 0.6)
70 multi_json (~> 1.0) 70 multi_json (~> 1.0)
71 acts-as-taggable-on (2.1.1) 71 acts-as-taggable-on (2.1.1)
@@ -73,7 +73,7 @@ GEM @@ -73,7 +73,7 @@ GEM
73 acts_as_list (0.1.4) 73 acts_as_list (0.1.4)
74 addressable (2.2.6) 74 addressable (2.2.6)
75 ansi (1.4.2) 75 ansi (1.4.2)
76 - arel (3.0.0) 76 + arel (3.0.2)
77 autotest (4.4.6) 77 autotest (4.4.6)
78 ZenTest (>= 4.4.1) 78 ZenTest (>= 4.4.1)
79 autotest-rails (4.1.1) 79 autotest-rails (4.1.1)
@@ -96,13 +96,13 @@ GEM @@ -96,13 +96,13 @@ GEM
96 childprocess (0.3.1) 96 childprocess (0.3.1)
97 ffi (~> 1.0.6) 97 ffi (~> 1.0.6)
98 coderay (1.0.5) 98 coderay (1.0.5)
99 - coffee-rails (3.2.1) 99 + coffee-rails (3.2.2)
100 coffee-script (>= 2.2.0) 100 coffee-script (>= 2.2.0)
101 - railties (~> 3.2.0.beta) 101 + railties (~> 3.2.0)
102 coffee-script (2.2.0) 102 coffee-script (2.2.0)
103 coffee-script-source 103 coffee-script-source
104 execjs 104 execjs
105 - coffee-script-source (1.2.0) 105 + coffee-script-source (1.3.1)
106 colored (1.2) 106 colored (1.2)
107 crack (0.3.1) 107 crack (0.3.1)
108 daemons (1.1.8) 108 daemons (1.1.8)
@@ -138,11 +138,11 @@ GEM @@ -138,11 +138,11 @@ GEM
138 multi_json 138 multi_json
139 multi_xml 139 multi_xml
140 i18n (0.6.0) 140 i18n (0.6.0)
141 - journey (1.0.1) 141 + journey (1.0.3)
142 jquery-rails (2.0.0) 142 jquery-rails (2.0.0)
143 railties (>= 3.2.0.beta, < 5.0) 143 railties (>= 3.2.0.beta, < 5.0)
144 thor (~> 0.14) 144 thor (~> 0.14)
145 - json (1.6.5) 145 + json (1.6.6)
146 kaminari (0.13.0) 146 kaminari (0.13.0)
147 actionpack (>= 3.0.0) 147 actionpack (>= 3.0.0)
148 activesupport (>= 3.0.0) 148 activesupport (>= 3.0.0)
@@ -153,7 +153,7 @@ GEM @@ -153,7 +153,7 @@ GEM
153 letter_opener (0.0.2) 153 letter_opener (0.0.2)
154 launchy 154 launchy
155 libv8 (3.3.10.4) 155 libv8 (3.3.10.4)
156 - mail (2.4.1) 156 + mail (2.4.4)
157 i18n (>= 0.4.0) 157 i18n (>= 0.4.0)
158 mime-types (~> 1.16) 158 mime-types (~> 1.16)
159 treetop (~> 1.4.8) 159 treetop (~> 1.4.8)
@@ -184,7 +184,7 @@ GEM @@ -184,7 +184,7 @@ GEM
184 rubypython (~> 0.5.3) 184 rubypython (~> 0.5.3)
185 pyu-ruby-sasl (0.0.3.3) 185 pyu-ruby-sasl (0.0.3.3)
186 rack (1.4.1) 186 rack (1.4.1)
187 - rack-cache (1.1) 187 + rack-cache (1.2)
188 rack (>= 0.4) 188 rack (>= 0.4)
189 rack-protection (1.2.0) 189 rack-protection (1.2.0)
190 rack 190 rack
@@ -192,19 +192,19 @@ GEM @@ -192,19 +192,19 @@ GEM
192 rack 192 rack
193 rack-test (0.6.1) 193 rack-test (0.6.1)
194 rack (>= 1.0) 194 rack (>= 1.0)
195 - rails (3.2.1)  
196 - actionmailer (= 3.2.1)  
197 - actionpack (= 3.2.1)  
198 - activerecord (= 3.2.1)  
199 - activeresource (= 3.2.1)  
200 - activesupport (= 3.2.1) 195 + rails (3.2.3)
  196 + actionmailer (= 3.2.3)
  197 + actionpack (= 3.2.3)
  198 + activerecord (= 3.2.3)
  199 + activeresource (= 3.2.3)
  200 + activesupport (= 3.2.3)
201 bundler (~> 1.0) 201 bundler (~> 1.0)
202 - railties (= 3.2.1) 202 + railties (= 3.2.3)
203 rails-footnotes (3.7.5) 203 rails-footnotes (3.7.5)
204 rails (>= 3.0.0) 204 rails (>= 3.0.0)
205 - railties (3.2.1)  
206 - actionpack (= 3.2.1)  
207 - activesupport (= 3.2.1) 205 + railties (3.2.3)
  206 + actionpack (= 3.2.3)
  207 + activesupport (= 3.2.3)
208 rack-ssl (~> 1.3.2) 208 rack-ssl (~> 1.3.2)
209 rake (>= 0.8.7) 209 rake (>= 0.8.7)
210 rdoc (~> 3.4) 210 rdoc (~> 3.4)
@@ -288,7 +288,7 @@ GEM @@ -288,7 +288,7 @@ GEM
288 polyglot (>= 0.3.1) 288 polyglot (>= 0.3.1)
289 turn (0.9.2) 289 turn (0.9.2)
290 ansi 290 ansi
291 - tzinfo (0.3.31) 291 + tzinfo (0.3.33)
292 uglifier (1.0.3) 292 uglifier (1.0.3)
293 execjs (>= 0.3.0) 293 execjs (>= 0.3.0)
294 multi_json (>= 1.0.2) 294 multi_json (>= 1.0.2)
@@ -320,7 +320,7 @@ DEPENDENCIES @@ -320,7 +320,7 @@ DEPENDENCIES
320 capybara 320 capybara
321 carrierwave 321 carrierwave
322 charlock_holmes 322 charlock_holmes
323 - coffee-rails (= 3.2.1) 323 + coffee-rails (= 3.2.2)
324 colored 324 colored
325 database_cleaner 325 database_cleaner
326 devise 326 devise
@@ -343,7 +343,7 @@ DEPENDENCIES @@ -343,7 +343,7 @@ DEPENDENCIES
343 omniauth-ldap 343 omniauth-ldap
344 pry 344 pry
345 pygments.rb (= 0.2.11) 345 pygments.rb (= 0.2.11)
346 - rails (= 3.2.1) 346 + rails (= 3.2.3)
347 rails-footnotes 347 rails-footnotes
348 rake 348 rake
349 redcarpet (~> 2.1.1) 349 redcarpet (~> 2.1.1)
app/assets/stylesheets/gitlab_bootstrap.scss
@@ -465,3 +465,8 @@ table.admin-table { @@ -465,3 +465,8 @@ table.admin-table {
465 background-image: -o-linear-gradient(#eee 6.6%, #dfdfdf); 465 background-image: -o-linear-gradient(#eee 6.6%, #dfdfdf);
466 } 466 }
467 } 467 }
  468 +
  469 +.field_with_errors {
  470 + display:inline;
  471 +}
  472 +
app/assets/stylesheets/sections/projects.scss
@@ -32,9 +32,3 @@ @@ -32,9 +32,3 @@
32 } 32 }
33 } 33 }
34 } 34 }
35 -  
36 -.new_project {  
37 - .field_with_errors {  
38 - display:inline;  
39 - }  
40 -}  
app/controllers/hooks_controller.rb
@@ -11,11 +11,8 @@ class HooksController &lt; ApplicationController @@ -11,11 +11,8 @@ class HooksController &lt; ApplicationController
11 respond_to :html 11 respond_to :html
12 12
13 def index 13 def index
14 - @hooks = @project.web_hooks  
15 - end  
16 -  
17 - def new  
18 - @hook = @project.web_hooks.new 14 + @hooks = @project.web_hooks.all
  15 + @hook = WebHook.new
19 end 16 end
20 17
21 def create 18 def create
@@ -23,25 +20,22 @@ class HooksController &lt; ApplicationController @@ -23,25 +20,22 @@ class HooksController &lt; ApplicationController
23 @hook.save 20 @hook.save
24 21
25 if @hook.valid? 22 if @hook.valid?
26 - redirect_to project_hook_path(@project, @hook) 23 + redirect_to project_hooks_path(@project)
27 else 24 else
28 - render :new 25 + @hooks = @project.web_hooks.all
  26 + render :index
29 end 27 end
30 end 28 end
31 29
32 def test 30 def test
33 @hook = @project.web_hooks.find(params[:id]) 31 @hook = @project.web_hooks.find(params[:id])
34 commits = @project.commits(@project.default_branch, nil, 3) 32 commits = @project.commits(@project.default_branch, nil, 3)
35 - data = @project.web_hook_data(commits.last.id, commits.first.id, "refs/heads/#{@project.default_branch}", current_user.keys.first.identifier) 33 + data = @project.post_receive_data(commits.last.id, commits.first.id, "refs/heads/#{@project.default_branch}", current_user)
36 @hook.execute(data) 34 @hook.execute(data)
37 35
38 redirect_to :back 36 redirect_to :back
39 end 37 end
40 38
41 - def show  
42 - @hook = @project.web_hooks.find(params[:id])  
43 - end  
44 -  
45 def destroy 39 def destroy
46 @hook = @project.web_hooks.find(params[:id]) 40 @hook = @project.web_hooks.find(params[:id])
47 @hook.destroy 41 @hook.destroy
app/views/hooks/index.html.haml
1 = render "projects/project_head" 1 = render "projects/project_head"
2 2
3 - if can? current_user, :admin_project, @project 3 - if can? current_user, :admin_project, @project
4 - .alert-message.block-message  
5 - Post receive hooks for binding events when someone push to repository.  
6 - = link_to new_project_hook_path(@project), :class => "btn small", :title => "New Web Hook" do  
7 - Add Post Receive Hook 4 + .alert.alert-info
  5 + %span
  6 + Post receive hooks for binding events when someone push to repository.
  7 + %br
  8 + Read more about web hooks
  9 + %strong #{link_to "here", help_web_hooks_path, :class => "vlink"}
8 10
9 - %p Read more about web hooks #{link_to "here", help_web_hooks_path, :class => "vlink"} 11 += form_for [@project, @hook], :as => :hook, :url => project_hooks_path(@project) do |f|
  12 + -if @hook.errors.any?
  13 + .alert-message.block-message.error
  14 + - @hook.errors.full_messages.each do |msg|
  15 + %p= msg
  16 + .clearfix
  17 + = f.label :url, "URL:"
  18 + .input
  19 + = f.text_field :url, :class => "text_field xxlarge"
  20 + &nbsp;
  21 + = f.submit "Add Web Hook", :class => "btn primary"
  22 +%hr
10 23
11 -if @hooks.any? 24 -if @hooks.any?
12 - %table 25 + %h3
  26 + Hooks
  27 + %small (#{@hooks.count})
  28 + %br
  29 + %table.admin-table
  30 + %tr
  31 + %th URL
  32 + %th Method
  33 + %th
13 - @hooks.each do |hook| 34 - @hooks.each do |hook|
14 %tr 35 %tr
15 %td 36 %td
16 = link_to project_hook_path(@project, hook) do 37 = link_to project_hook_path(@project, hook) do
17 - = hook.url 38 + %strong= hook.url
  39 + = link_to 'Test Hook', test_project_hook_path(@project, hook), :class => "btn small right"
  40 + %td POST
18 %td 41 %td
19 = link_to 'Remove', project_hook_path(@project, hook), :confirm => 'Are you sure?', :method => :delete, :class => "danger btn small right" 42 = link_to 'Remove', project_hook_path(@project, hook), :confirm => 'Are you sure?', :method => :delete, :class => "danger btn small right"
  43 +
app/views/hooks/new.html.haml
@@ -1,12 +0,0 @@ @@ -1,12 +0,0 @@
1 -= render "repositories/head"  
2 -= form_for [@project, @hook], :as => :hook, :url => project_hooks_path(@project) do |f|  
3 - -if @hook.errors.any?  
4 - %ul  
5 - - @hook.errors.full_messages.each do |msg|  
6 - %li= msg  
7 - .clearfix  
8 - = f.label :url, "URL:"  
9 - .input= f.text_field :url, :class => "text_field"  
10 - .actions  
11 - = f.submit "Save", :class => "btn"  
12 -  
app/views/hooks/show.html.haml
@@ -1,7 +0,0 @@ @@ -1,7 +0,0 @@
1 -= render "repositories/head"  
2 -%pre= @hook.url  
3 -  
4 -- if can? current_user, :admin_project, @project  
5 - .actions  
6 - = link_to 'Test Hook', test_project_hook_path(@project, @hook), :class => "btn"  
7 - = link_to 'Remove', project_hook_path(@project, @hook), :confirm => 'Are you sure?', :method => :delete, :class => "danger btn"  
config/routes.rb
@@ -111,7 +111,7 @@ Gitlab::Application.routes.draw do @@ -111,7 +111,7 @@ Gitlab::Application.routes.draw do
111 end 111 end
112 112
113 resources :snippets 113 resources :snippets
114 - resources :hooks, :only => [:index, :new, :create, :destroy, :show] do 114 + resources :hooks, :only => [:index, :create, :destroy] do
115 member do 115 member do
116 get :test 116 get :test
117 end 117 end
spec/requests/hooks_spec.rb 0 → 100644
@@ -0,0 +1,42 @@ @@ -0,0 +1,42 @@
  1 +require 'spec_helper'
  2 +
  3 +describe "Hooks" do
  4 + before do
  5 + login_as :user
  6 + @project = Factory :project
  7 + @project.add_access(@user, :read, :admin)
  8 + end
  9 +
  10 + describe "GET index" do
  11 + it "should be available" do
  12 + @hook = Factory :web_hook, :project => @project
  13 + visit project_hooks_path(@project)
  14 + page.should have_content "Hooks"
  15 + page.should have_content @hook.url
  16 + end
  17 + end
  18 +
  19 + describe "New Hook" do
  20 + before do
  21 + @url = Faker::Internet.url
  22 + visit project_hooks_path(@project)
  23 + fill_in "hook_url", :with => @url
  24 + expect { click_button "Add Web Hook" }.to change(WebHook, :count).by(1)
  25 + end
  26 +
  27 + it "should open new team member popup" do
  28 + page.current_path.should == project_hooks_path(@project)
  29 + page.should have_content(@url)
  30 + end
  31 + end
  32 +
  33 + describe "Test" do
  34 + before do
  35 + @hook = Factory :web_hook, :project => @project
  36 + visit project_hooks_path(@project)
  37 + click_link "Test Hook"
  38 + end
  39 +
  40 + it { page.current_path.should == project_hooks_path(@project) }
  41 + end
  42 +end