diff --git a/app/models/activity_feed_observer.rb b/app/models/activity_feed_observer.rb index 80b497721..771e23305 100644 --- a/app/models/activity_feed_observer.rb +++ b/app/models/activity_feed_observer.rb @@ -74,13 +74,15 @@ class ActivityFeedObserver < ActiveRecord::Observer change_type = record.change_type branch_name = record.refname.split('/').last - - 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] + 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, diff --git a/app/models/git_hook.rb b/app/models/git_hook.rb index cb7037619..6196abab7 100644 --- a/app/models/git_hook.rb +++ b/app/models/git_hook.rb @@ -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 diff --git a/lib/modules/models/git.rb b/lib/modules/models/git.rb index 9ba347403..6aa2c23da 100644 --- a/lib/modules/models/git.rb +++ b/lib/modules/models/git.rb @@ -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