From 67e0226b24ee1cdd176972751957744cafaacd0e Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 25 Apr 2013 19:27:48 +0400 Subject: [PATCH] #34: updated Hook model --- app/models/activity_feed_observer.rb | 2 +- app/models/hook.rb | 29 ++++++++++++++-------------- config/locales/models/hook.en.yml | 1 - config/locales/models/hook.ru.yml | 1 - lib/modules/models/web_hooks.rb | 4 ---- 5 files changed, 16 insertions(+), 21 deletions(-) diff --git a/app/models/activity_feed_observer.rb b/app/models/activity_feed_observer.rb index b1625eaef..9168d22ab 100644 --- a/app/models/activity_feed_observer.rb +++ b/app/models/activity_feed_observer.rb @@ -83,7 +83,7 @@ class ActivityFeedObserver < ActiveRecord::Observer when 'GitHook' return unless record.project PullRequest.where("from_project_id = ? OR to_project_id = ?", record.project, record.project).needed_checking.each {|pull| pull.check} - record.project.hooks.each{ |h| h.receive_issues(record) } if /^[tracking ]*branch$/ =~ record.refname_type + record.project.hooks.each{ |h| h.receive_push(record) } change_type = record.change_type branch_name = record.refname.split('/').last diff --git a/app/models/hook.rb b/app/models/hook.rb index a73b2cff9..420bb2238 100644 --- a/app/models/hook.rb +++ b/app/models/hook.rb @@ -52,34 +52,35 @@ class Hook < ActiveRecord::Base later :receive_issues, :queue => :clone_build def receive_push(git_hook) - payload = meta(git_hook.project, git_hook.user) + project = Project.find(git_hook['project']['project']['id']) + user = User.find(git_hook['user']['user']['id']) + payload = meta(project, user) + oldrev = git_hook['oldrev'] + newrev = git_hook['newrev'] + change_type = git_hook['change_type'] + commits = [] - oldrev, newrev = git_hook.oldrev, git_hook.newrev - if git_hook.change_type == 'delete' - payload.merge!(:before => oldrev, :after => nil, :compare => nil) - elsif git_hook.change_type == 'create' - payload.merge!(:before => nil, :after => newrev, :compare => nil) - else + payload.merge!(:before => oldrev, :after => newrev) + if %w(delete create).exclude? change_type payload.merge!( - :before => oldrev, :after => newrev, - :compare => "#{git_hook.project.html_url}/compare/#{oldrev[0..6]}...#{newrev[0..6]}" + :compare => "#{project.html_url}/diff/#{oldrev[0..6]}...#{newrev[0..6]}" ) - if git_hook.message # online update - commits = [[git_hook.newrev, git_hook.message]] + if oldrev == newrev + commits = [project.repo.commit(newrev)] else - commits = git_hook.project.repo.commits_between(git_hook.oldrev, git_hook.newrev) + commits = project.repo.commits_between(oldrev, newrev) end end post 'push', { :payload => payload.merge( - :ref => git_hook.refname, + :ref => git_hook['refname'], :commits => commits.map{ |c| { :id => c.id, :message => c.message, :distinct => true, - :url => "#{git_hook.project.html_url}/commit/#{c.id}", + :url => "#{project.html_url}/commit/#{c.id}", :removed => [], :added => [], :modified => c.stats.files.map{|f| f[0]}, diff --git a/config/locales/models/hook.en.yml b/config/locales/models/hook.en.yml index dca43e6aa..db154d105 100644 --- a/config/locales/models/hook.en.yml +++ b/config/locales/models/hook.en.yml @@ -6,7 +6,6 @@ en: hipchat: HipChat irc: IRC jabber: Jabber - twitter: Twitter flash: hook: diff --git a/config/locales/models/hook.ru.yml b/config/locales/models/hook.ru.yml index b0cec78ca..f29c162b3 100644 --- a/config/locales/models/hook.ru.yml +++ b/config/locales/models/hook.ru.yml @@ -6,7 +6,6 @@ ru: hipchat: HipChat irc: IRC jabber: Jabber - twitter: Twitter flash: hook: diff --git a/lib/modules/models/web_hooks.rb b/lib/modules/models/web_hooks.rb index 4f22e272d..2eaa450b7 100644 --- a/lib/modules/models/web_hooks.rb +++ b/lib/modules/models/web_hooks.rb @@ -49,10 +49,6 @@ module Modules::Models::WebHooks add_hook :jabber do string :user end - add_hook :twitter do - string :token, :secret - boolean :digest, :short_format - end SCHEMA.freeze NAMES.freeze