Commit 65dc68b35c0ad455336abf33def5d920166f7c83
1 parent
72a57172
Exists in
master
and in
4 other branches
Refactoring of hook functionality & bootsrap system hooks
Showing
9 changed files
with
24 additions
and
14 deletions
Show diff stats
Gemfile
| @@ -71,7 +71,6 @@ group :development, :test do | @@ -71,7 +71,6 @@ group :development, :test do | ||
| 71 | gem "awesome_print" | 71 | gem "awesome_print" |
| 72 | gem "database_cleaner" | 72 | gem "database_cleaner" |
| 73 | gem "launchy" | 73 | gem "launchy" |
| 74 | - gem "webmock" | ||
| 75 | end | 74 | end |
| 76 | 75 | ||
| 77 | group :test do | 76 | group :test do |
| @@ -82,4 +81,5 @@ group :test do | @@ -82,4 +81,5 @@ group :test do | ||
| 82 | gem "shoulda-matchers" | 81 | gem "shoulda-matchers" |
| 83 | gem 'email_spec' | 82 | gem 'email_spec' |
| 84 | gem 'resque_spec' | 83 | gem 'resque_spec' |
| 84 | + gem "webmock" | ||
| 85 | end | 85 | end |
app/controllers/hooks_controller.rb
| @@ -11,24 +11,24 @@ class HooksController < ApplicationController | @@ -11,24 +11,24 @@ class HooksController < ApplicationController | ||
| 11 | respond_to :html | 11 | respond_to :html |
| 12 | 12 | ||
| 13 | def index | 13 | def index |
| 14 | - @hooks = @project.web_hooks.all | ||
| 15 | - @hook = WebHook.new | 14 | + @hooks = @project.hooks.all |
| 15 | + @hook = ProjectHook.new | ||
| 16 | end | 16 | end |
| 17 | 17 | ||
| 18 | def create | 18 | def create |
| 19 | - @hook = @project.web_hooks.new(params[:hook]) | 19 | + @hook = @project.hooks.new(params[:hook]) |
| 20 | @hook.save | 20 | @hook.save |
| 21 | 21 | ||
| 22 | if @hook.valid? | 22 | if @hook.valid? |
| 23 | redirect_to project_hooks_path(@project) | 23 | redirect_to project_hooks_path(@project) |
| 24 | else | 24 | else |
| 25 | - @hooks = @project.web_hooks.all | 25 | + @hooks = @project.hooks.all |
| 26 | render :index | 26 | render :index |
| 27 | end | 27 | end |
| 28 | end | 28 | end |
| 29 | 29 | ||
| 30 | def test | 30 | def test |
| 31 | - @hook = @project.web_hooks.find(params[:id]) | 31 | + @hook = @project.hooks.find(params[:id]) |
| 32 | commits = @project.commits(@project.default_branch, nil, 3) | 32 | commits = @project.commits(@project.default_branch, nil, 3) |
| 33 | data = @project.post_receive_data(commits.last.id, commits.first.id, "refs/heads/#{@project.default_branch}", current_user) | 33 | data = @project.post_receive_data(commits.last.id, commits.first.id, "refs/heads/#{@project.default_branch}", current_user) |
| 34 | @hook.execute(data) | 34 | @hook.execute(data) |
| @@ -37,7 +37,7 @@ class HooksController < ApplicationController | @@ -37,7 +37,7 @@ class HooksController < ApplicationController | ||
| 37 | end | 37 | end |
| 38 | 38 | ||
| 39 | def destroy | 39 | def destroy |
| 40 | - @hook = @project.web_hooks.find(params[:id]) | 40 | + @hook = @project.hooks.find(params[:id]) |
| 41 | @hook.destroy | 41 | @hook.destroy |
| 42 | 42 | ||
| 43 | redirect_to project_hooks_path(@project) | 43 | redirect_to project_hooks_path(@project) |
app/models/project.rb
| @@ -19,7 +19,7 @@ class Project < ActiveRecord::Base | @@ -19,7 +19,7 @@ class Project < ActiveRecord::Base | ||
| 19 | has_many :notes, :dependent => :destroy | 19 | has_many :notes, :dependent => :destroy |
| 20 | has_many :snippets, :dependent => :destroy | 20 | has_many :snippets, :dependent => :destroy |
| 21 | has_many :deploy_keys, :dependent => :destroy, :foreign_key => "project_id", :class_name => "Key" | 21 | has_many :deploy_keys, :dependent => :destroy, :foreign_key => "project_id", :class_name => "Key" |
| 22 | - has_many :web_hooks, :dependent => :destroy | 22 | + has_many :hooks, :dependent => :destroy, :class_name => "ProjectHook" |
| 23 | has_many :wikis, :dependent => :destroy | 23 | has_many :wikis, :dependent => :destroy |
| 24 | has_many :protected_branches, :dependent => :destroy | 24 | has_many :protected_branches, :dependent => :destroy |
| 25 | 25 |
app/models/web_hook.rb
| @@ -4,8 +4,6 @@ class WebHook < ActiveRecord::Base | @@ -4,8 +4,6 @@ class WebHook < ActiveRecord::Base | ||
| 4 | # HTTParty timeout | 4 | # HTTParty timeout |
| 5 | default_timeout 10 | 5 | default_timeout 10 |
| 6 | 6 | ||
| 7 | - belongs_to :project | ||
| 8 | - | ||
| 9 | validates :url, | 7 | validates :url, |
| 10 | presence: true, | 8 | presence: true, |
| 11 | format: { | 9 | format: { |
app/roles/git_push.rb
| @@ -35,7 +35,7 @@ module GitPush | @@ -35,7 +35,7 @@ module GitPush | ||
| 35 | 35 | ||
| 36 | data = post_receive_data(oldrev, newrev, ref, user) | 36 | data = post_receive_data(oldrev, newrev, ref, user) |
| 37 | 37 | ||
| 38 | - web_hooks.each { |web_hook| web_hook.execute(data) } | 38 | + hooks.each { |web_hook| web_hook.execute(data) } |
| 39 | end | 39 | end |
| 40 | 40 | ||
| 41 | def post_receive_data(oldrev, newrev, ref, user) | 41 | def post_receive_data(oldrev, newrev, ref, user) |
db/schema.rb
| @@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
| 11 | # | 11 | # |
| 12 | # It's strongly recommended to check this file into your version control system. | 12 | # It's strongly recommended to check this file into your version control system. |
| 13 | 13 | ||
| 14 | -ActiveRecord::Schema.define(:version => 20120706065612) do | 14 | +ActiveRecord::Schema.define(:version => 20120712080407) do |
| 15 | 15 | ||
| 16 | create_table "events", :force => true do |t| | 16 | create_table "events", :force => true do |t| |
| 17 | t.string "target_type" | 17 | t.string "target_type" |
| @@ -187,8 +187,9 @@ ActiveRecord::Schema.define(:version => 20120706065612) do | @@ -187,8 +187,9 @@ ActiveRecord::Schema.define(:version => 20120706065612) do | ||
| 187 | create_table "web_hooks", :force => true do |t| | 187 | create_table "web_hooks", :force => true do |t| |
| 188 | t.string "url" | 188 | t.string "url" |
| 189 | t.integer "project_id" | 189 | t.integer "project_id" |
| 190 | - t.datetime "created_at", :null => false | ||
| 191 | - t.datetime "updated_at", :null => false | 190 | + t.datetime "created_at", :null => false |
| 191 | + t.datetime "updated_at", :null => false | ||
| 192 | + t.string "type", :default => "ProjectHook" | ||
| 192 | end | 193 | end |
| 193 | 194 | ||
| 194 | create_table "wikis", :force => true do |t| | 195 | create_table "wikis", :force => true do |t| |