Browse files

Refactoring of hook functionality & bootsrap system hooks

  • Loading branch information...
1 parent 72a5717 commit 65dc68b35c0ad455336abf33def5d920166f7c83 @vsizov vsizov committed Jul 12, 2012
View
2 Gemfile
@@ -71,7 +71,6 @@ group :development, :test do
gem "awesome_print"
gem "database_cleaner"
gem "launchy"
- gem "webmock"
end
group :test do
@@ -82,4 +81,5 @@ group :test do
gem "shoulda-matchers"
gem 'email_spec'
gem 'resque_spec'
+ gem "webmock"
end
View
12 app/controllers/hooks_controller.rb
@@ -11,24 +11,24 @@ class HooksController < ApplicationController
respond_to :html
def index
- @hooks = @project.web_hooks.all
- @hook = WebHook.new
+ @hooks = @project.hooks.all
+ @hook = ProjectHook.new
end
def create
- @hook = @project.web_hooks.new(params[:hook])
+ @hook = @project.hooks.new(params[:hook])
@hook.save
if @hook.valid?
redirect_to project_hooks_path(@project)
else
- @hooks = @project.web_hooks.all
+ @hooks = @project.hooks.all
render :index
end
end
def test
- @hook = @project.web_hooks.find(params[:id])
+ @hook = @project.hooks.find(params[:id])
commits = @project.commits(@project.default_branch, nil, 3)
data = @project.post_receive_data(commits.last.id, commits.first.id, "refs/heads/#{@project.default_branch}", current_user)
@hook.execute(data)
@@ -37,7 +37,7 @@ def test
end
def destroy
- @hook = @project.web_hooks.find(params[:id])
+ @hook = @project.hooks.find(params[:id])
@hook.destroy
redirect_to project_hooks_path(@project)
View
2 app/models/project.rb
@@ -19,7 +19,7 @@ class Project < ActiveRecord::Base
has_many :notes, :dependent => :destroy
has_many :snippets, :dependent => :destroy
has_many :deploy_keys, :dependent => :destroy, :foreign_key => "project_id", :class_name => "Key"
- has_many :web_hooks, :dependent => :destroy
+ has_many :hooks, :dependent => :destroy, :class_name => "ProjectHook"
has_many :wikis, :dependent => :destroy
has_many :protected_branches, :dependent => :destroy
View
3 app/models/project_hook.rb
@@ -0,0 +1,3 @@
+class ProjectHook < WebHook
+ belongs_to :project
+end
View
3 app/models/system_hook.rb
@@ -0,0 +1,3 @@
+class SystemHook < WebHook
+
+end
View
2 app/models/web_hook.rb
@@ -4,8 +4,6 @@ class WebHook < ActiveRecord::Base
# HTTParty timeout
default_timeout 10
- belongs_to :project
-
validates :url,
presence: true,
format: {
View
2 app/roles/git_push.rb
@@ -35,7 +35,7 @@ def execute_web_hooks(oldrev, newrev, ref, user)
data = post_receive_data(oldrev, newrev, ref, user)
- web_hooks.each { |web_hook| web_hook.execute(data) }
+ hooks.each { |web_hook| web_hook.execute(data) }
end
def post_receive_data(oldrev, newrev, ref, user)
View
5 db/migrate/20120712080407_add_type_to_web_hook.rb
@@ -0,0 +1,5 @@
+class AddTypeToWebHook < ActiveRecord::Migration
+ def change
+ add_column :web_hooks, :type, :string, :default => "ProjectHook"
+ end
+end
View
7 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120706065612) do
+ActiveRecord::Schema.define(:version => 20120712080407) do
create_table "events", :force => true do |t|
t.string "target_type"
@@ -187,8 +187,9 @@
create_table "web_hooks", :force => true do |t|
t.string "url"
t.integer "project_id"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.string "type", :default => "ProjectHook"
end
create_table "wikis", :force => true do |t|

0 comments on commit 65dc68b

Please sign in to comment.