Merge pull request #971 from warpc/917-add_hook_to_online_update

[refs #917] add git hook to online update
This commit is contained in:
Vladimir Sharshov 2013-02-26 04:12:35 -08:00
commit 2ae2860a7e
3 changed files with 17 additions and 12 deletions

View File

@ -74,13 +74,15 @@ class ActivityFeedObserver < ActiveRecord::Observer
change_type = record.change_type
branch_name = record.refname.split('/').last
if record.user # online update
last_commits, first_commiter = [[record.newrev, record.message]], record.user
else
last_commits = record.project.repo.log(branch_name, nil).first(3)
first_commiter = User.find_by_email(last_commits[0].author.email) unless last_commits.blank?
last_commits = last_commits.collect do |commit| #:author => 'author'
[commit.sha, commit.message]
end
end
if change_type == 'delete'
kind = 'git_delete_branch_notification'
options = {:project_id => record.project.id, :project_name => record.project.name, :branch_name => branch_name,

View File

@ -1,12 +1,12 @@
# -*- encoding : utf-8 -*-
class GitHook
attr_reader :repo, :newrev, :oldrev, :newrev_type, :oldrev_type, :refname,
:change_type, :rev, :rev_type, :refname_type, :owner, :project
:change_type, :rev, :rev_type, :refname_type, :owner, :project, :user, :message
include Resque::Plugins::Status
def initialize(owner_uname, repo, newrev, oldrev, ref, newrev_type, oldrev_type = nil)
@repo, @newrev, @oldrev, @refname, @newrev_type, @oldrev_type = repo, newrev, oldrev, ref, newrev_type, oldrev_type
def initialize(owner_uname, repo, newrev, oldrev, ref, newrev_type, oldrev_type = nil, user = nil, message = nil)
@repo, @newrev, @oldrev, @refname, @newrev_type, @oldrev_type, @user, @message = repo, newrev, oldrev, ref, newrev_type, oldrev_type, user, message
if @owner = User.where(:uname => owner_uname).first || Group.where(:uname => owner_uname).first!
@project = @owner.own_projects.where(:name => repo).first!
end

View File

@ -56,7 +56,10 @@ module Modules
return false if (index.current_tree / path).nil?
index.add(path, data)
index.commit(message, :parents => [parent], :actor => actor, :last_tree => parent.tree.id, :head => head)
if sha1 = index.commit(message, :parents => [parent], :actor => actor, :last_tree => parent.tree.id, :head => head)
Project.process_hook(owner.uname, name, "refs/heads/#{sha1}", nil, head, 'commit', 'commit', options[:actor], message)
end
sha1
end
def paginate_commits(treeish, options = {})
@ -167,8 +170,8 @@ module Modules
end
module ClassMethods
def process_hook(owner_uname, repo, newrev, oldrev, ref, newrev_type, oldrev_type)
rec = GitHook.new(owner_uname, repo, newrev, oldrev, ref, newrev_type, oldrev_type)
def process_hook(owner_uname, repo, newrev, oldrev, ref, newrev_type, oldrev_type, user = nil, message = nil)
rec = GitHook.new(owner_uname, repo, newrev, oldrev, ref, newrev_type, oldrev_type, user, message)
ActivityFeedObserver.instance.after_create rec
end
end