#34: updated Hook model

This commit is contained in:
Vokhmin Alexey V 2013-04-25 19:27:48 +04:00
parent 4c96629a28
commit 67e0226b24
5 changed files with 16 additions and 21 deletions

View File

@ -83,7 +83,7 @@ class ActivityFeedObserver < ActiveRecord::Observer
when 'GitHook' when 'GitHook'
return unless record.project return unless record.project
PullRequest.where("from_project_id = ? OR to_project_id = ?", record.project, record.project).needed_checking.each {|pull| pull.check} 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 change_type = record.change_type
branch_name = record.refname.split('/').last branch_name = record.refname.split('/').last

View File

@ -52,34 +52,35 @@ class Hook < ActiveRecord::Base
later :receive_issues, :queue => :clone_build later :receive_issues, :queue => :clone_build
def receive_push(git_hook) 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 = [] commits = []
oldrev, newrev = git_hook.oldrev, git_hook.newrev payload.merge!(:before => oldrev, :after => newrev)
if git_hook.change_type == 'delete' if %w(delete create).exclude? change_type
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!( payload.merge!(
:before => oldrev, :after => newrev, :compare => "#{project.html_url}/diff/#{oldrev[0..6]}...#{newrev[0..6]}"
:compare => "#{git_hook.project.html_url}/compare/#{oldrev[0..6]}...#{newrev[0..6]}"
) )
if git_hook.message # online update if oldrev == newrev
commits = [[git_hook.newrev, git_hook.message]] commits = [project.repo.commit(newrev)]
else else
commits = git_hook.project.repo.commits_between(git_hook.oldrev, git_hook.newrev) commits = project.repo.commits_between(oldrev, newrev)
end end
end end
post 'push', { post 'push', {
:payload => payload.merge( :payload => payload.merge(
:ref => git_hook.refname, :ref => git_hook['refname'],
:commits => commits.map{ |c| :commits => commits.map{ |c|
{ {
:id => c.id, :id => c.id,
:message => c.message, :message => c.message,
:distinct => true, :distinct => true,
:url => "#{git_hook.project.html_url}/commit/#{c.id}", :url => "#{project.html_url}/commit/#{c.id}",
:removed => [], :removed => [],
:added => [], :added => [],
:modified => c.stats.files.map{|f| f[0]}, :modified => c.stats.files.map{|f| f[0]},

View File

@ -6,7 +6,6 @@ en:
hipchat: HipChat hipchat: HipChat
irc: IRC irc: IRC
jabber: Jabber jabber: Jabber
twitter: Twitter
flash: flash:
hook: hook:

View File

@ -6,7 +6,6 @@ ru:
hipchat: HipChat hipchat: HipChat
irc: IRC irc: IRC
jabber: Jabber jabber: Jabber
twitter: Twitter
flash: flash:
hook: hook:

View File

@ -49,10 +49,6 @@ module Modules::Models::WebHooks
add_hook :jabber do add_hook :jabber do
string :user string :user
end end
add_hook :twitter do
string :token, :secret
boolean :digest, :short_format
end
SCHEMA.freeze SCHEMA.freeze
NAMES.freeze NAMES.freeze