Commit 65dc68b3 authored by Valeriy Sizov's avatar Valeriy Sizov

Refactoring of hook functionality & bootsrap system hooks

parent 72a57172
...@@ -71,7 +71,6 @@ group :development, :test do ...@@ -71,7 +71,6 @@ group :development, :test do
gem "awesome_print" gem "awesome_print"
gem "database_cleaner" gem "database_cleaner"
gem "launchy" gem "launchy"
gem "webmock"
end end
group :test do group :test do
...@@ -82,4 +81,5 @@ group :test do ...@@ -82,4 +81,5 @@ group :test do
gem "shoulda-matchers" gem "shoulda-matchers"
gem 'email_spec' gem 'email_spec'
gem 'resque_spec' gem 'resque_spec'
gem "webmock"
end end
...@@ -11,24 +11,24 @@ class HooksController < ApplicationController ...@@ -11,24 +11,24 @@ class HooksController < ApplicationController
respond_to :html respond_to :html
def index def index
@hooks = @project.web_hooks.all @hooks = @project.hooks.all
@hook = WebHook.new @hook = ProjectHook.new
end end
def create def create
@hook = @project.web_hooks.new(params[:hook]) @hook = @project.hooks.new(params[:hook])
@hook.save @hook.save
if @hook.valid? if @hook.valid?
redirect_to project_hooks_path(@project) redirect_to project_hooks_path(@project)
else else
@hooks = @project.web_hooks.all @hooks = @project.hooks.all
render :index render :index
end end
end end
def test def test
@hook = @project.web_hooks.find(params[:id]) @hook = @project.hooks.find(params[:id])
commits = @project.commits(@project.default_branch, nil, 3) 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) data = @project.post_receive_data(commits.last.id, commits.first.id, "refs/heads/#{@project.default_branch}", current_user)
@hook.execute(data) @hook.execute(data)
...@@ -37,7 +37,7 @@ class HooksController < ApplicationController ...@@ -37,7 +37,7 @@ class HooksController < ApplicationController
end end
def destroy def destroy
@hook = @project.web_hooks.find(params[:id]) @hook = @project.hooks.find(params[:id])
@hook.destroy @hook.destroy
redirect_to project_hooks_path(@project) redirect_to project_hooks_path(@project)
......
...@@ -19,7 +19,7 @@ class Project < ActiveRecord::Base ...@@ -19,7 +19,7 @@ class Project < ActiveRecord::Base
has_many :notes, :dependent => :destroy has_many :notes, :dependent => :destroy
has_many :snippets, :dependent => :destroy has_many :snippets, :dependent => :destroy
has_many :deploy_keys, :dependent => :destroy, :foreign_key => "project_id", :class_name => "Key" 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 :wikis, :dependent => :destroy
has_many :protected_branches, :dependent => :destroy has_many :protected_branches, :dependent => :destroy
......
class ProjectHook < WebHook
belongs_to :project
end
class SystemHook < WebHook
end
...@@ -4,8 +4,6 @@ class WebHook < ActiveRecord::Base ...@@ -4,8 +4,6 @@ class WebHook < ActiveRecord::Base
# HTTParty timeout # HTTParty timeout
default_timeout 10 default_timeout 10
belongs_to :project
validates :url, validates :url,
presence: true, presence: true,
format: { format: {
......
...@@ -35,7 +35,7 @@ module GitPush ...@@ -35,7 +35,7 @@ module GitPush
data = post_receive_data(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 end
def post_receive_data(oldrev, newrev, ref, user) def post_receive_data(oldrev, newrev, ref, user)
......
class AddTypeToWebHook < ActiveRecord::Migration
def change
add_column :web_hooks, :type, :string, :default => "ProjectHook"
end
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # 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| create_table "events", :force => true do |t|
t.string "target_type" t.string "target_type"
...@@ -187,8 +187,9 @@ ActiveRecord::Schema.define(:version => 20120706065612) do ...@@ -187,8 +187,9 @@ ActiveRecord::Schema.define(:version => 20120706065612) do
create_table "web_hooks", :force => true do |t| create_table "web_hooks", :force => true do |t|
t.string "url" t.string "url"
t.integer "project_id" t.integer "project_id"
t.datetime "created_at", :null => false t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
t.string "type", :default => "ProjectHook"
end end
create_table "wikis", :force => true do |t| create_table "wikis", :force => true do |t|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment