#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'
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

View File

@ -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]},

View File

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

View File

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

View File

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