BigW Consortium Gitlab

Commit 65dc68b3 by Valeriy Sizov

Refactoring of hook functionality & bootsrap system hooks

parent 72a57172
......@@ -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
......@@ -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)
......
......@@ -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
......
class ProjectHook < WebHook
belongs_to :project
end
class SystemHook < WebHook
end
......@@ -4,8 +4,6 @@ class WebHook < ActiveRecord::Base
# HTTParty timeout
default_timeout 10
belongs_to :project
validates :url,
presence: true,
format: {
......
......@@ -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)
......
class AddTypeToWebHook < ActiveRecord::Migration
def change
add_column :web_hooks, :type, :string, :default => "ProjectHook"
end
end
......@@ -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|
......
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