Refactoring of hook functionality & bootsrap system hooks

3-1-stable
Valeriy Sizov 2012-07-12 15:36:33 +03:00
parent 72a571724d
commit 65dc68b35c
9 changed files with 24 additions and 14 deletions

View File

@ -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 File

@ -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 @@ class HooksController < ApplicationController
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 File

@ -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 File

@ -0,0 +1,3 @@
class ProjectHook < WebHook
belongs_to :project
end

View File

@ -0,0 +1,3 @@
class SystemHook < WebHook
end

View File

@ -4,8 +4,6 @@ class WebHook < ActiveRecord::Base
# HTTParty timeout
default_timeout 10
belongs_to :project
validates :url,
presence: true,
format: {

View File

@ -35,7 +35,7 @@ module GitPush
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 File

@ -0,0 +1,5 @@
class AddTypeToWebHook < ActiveRecord::Migration
def change
add_column :web_hooks, :type, :string, :default => "ProjectHook"
end
end

View File

@ -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 @@ ActiveRecord::Schema.define(:version => 20120706065612) do
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|