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 | 71 | gem "awesome_print" |
| 72 | 72 | gem "database_cleaner" |
| 73 | 73 | gem "launchy" |
| 74 | - gem "webmock" | |
| 75 | 74 | end |
| 76 | 75 | |
| 77 | 76 | group :test do |
| ... | ... | @@ -82,4 +81,5 @@ group :test do |
| 82 | 81 | gem "shoulda-matchers" |
| 83 | 82 | gem 'email_spec' |
| 84 | 83 | gem 'resque_spec' |
| 84 | + gem "webmock" | |
| 85 | 85 | end | ... | ... |
app/controllers/hooks_controller.rb
| ... | ... | @@ -11,24 +11,24 @@ class HooksController < ApplicationController |
| 11 | 11 | respond_to :html |
| 12 | 12 | |
| 13 | 13 | def index |
| 14 | - @hooks = @project.web_hooks.all | |
| 15 | - @hook = WebHook.new | |
| 14 | + @hooks = @project.hooks.all | |
| 15 | + @hook = ProjectHook.new | |
| 16 | 16 | end |
| 17 | 17 | |
| 18 | 18 | def create |
| 19 | - @hook = @project.web_hooks.new(params[:hook]) | |
| 19 | + @hook = @project.hooks.new(params[:hook]) | |
| 20 | 20 | @hook.save |
| 21 | 21 | |
| 22 | 22 | if @hook.valid? |
| 23 | 23 | redirect_to project_hooks_path(@project) |
| 24 | 24 | else |
| 25 | - @hooks = @project.web_hooks.all | |
| 25 | + @hooks = @project.hooks.all | |
| 26 | 26 | render :index |
| 27 | 27 | end |
| 28 | 28 | end |
| 29 | 29 | |
| 30 | 30 | def test |
| 31 | - @hook = @project.web_hooks.find(params[:id]) | |
| 31 | + @hook = @project.hooks.find(params[:id]) | |
| 32 | 32 | commits = @project.commits(@project.default_branch, nil, 3) |
| 33 | 33 | data = @project.post_receive_data(commits.last.id, commits.first.id, "refs/heads/#{@project.default_branch}", current_user) |
| 34 | 34 | @hook.execute(data) |
| ... | ... | @@ -37,7 +37,7 @@ class HooksController < ApplicationController |
| 37 | 37 | end |
| 38 | 38 | |
| 39 | 39 | def destroy |
| 40 | - @hook = @project.web_hooks.find(params[:id]) | |
| 40 | + @hook = @project.hooks.find(params[:id]) | |
| 41 | 41 | @hook.destroy |
| 42 | 42 | |
| 43 | 43 | redirect_to project_hooks_path(@project) | ... | ... |
app/models/project.rb
| ... | ... | @@ -19,7 +19,7 @@ class Project < ActiveRecord::Base |
| 19 | 19 | has_many :notes, :dependent => :destroy |
| 20 | 20 | has_many :snippets, :dependent => :destroy |
| 21 | 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 | 23 | has_many :wikis, :dependent => :destroy |
| 24 | 24 | has_many :protected_branches, :dependent => :destroy |
| 25 | 25 | ... | ... |
app/models/web_hook.rb
app/roles/git_push.rb
| ... | ... | @@ -35,7 +35,7 @@ module GitPush |
| 35 | 35 | |
| 36 | 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 | 39 | end |
| 40 | 40 | |
| 41 | 41 | def post_receive_data(oldrev, newrev, ref, user) | ... | ... |
db/schema.rb
| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | # |
| 12 | 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 | 16 | create_table "events", :force => true do |t| |
| 17 | 17 | t.string "target_type" |
| ... | ... | @@ -187,8 +187,9 @@ ActiveRecord::Schema.define(:version => 20120706065612) do |
| 187 | 187 | create_table "web_hooks", :force => true do |t| |
| 188 | 188 | t.string "url" |
| 189 | 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 | 193 | end |
| 193 | 194 | |
| 194 | 195 | create_table "wikis", :force => true do |t| | ... | ... |