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:
commit
2ae2860a7e
|
@ -74,13 +74,15 @@ class ActivityFeedObserver < ActiveRecord::Observer
|
||||||
|
|
||||||
change_type = record.change_type
|
change_type = record.change_type
|
||||||
branch_name = record.refname.split('/').last
|
branch_name = record.refname.split('/').last
|
||||||
|
if record.user # online update
|
||||||
last_commits = record.project.repo.log(branch_name, nil).first(3)
|
last_commits, first_commiter = [[record.newrev, record.message]], record.user
|
||||||
first_commiter = User.find_by_email(last_commits[0].author.email) unless last_commits.blank?
|
else
|
||||||
last_commits = last_commits.collect do |commit| #:author => 'author'
|
last_commits = record.project.repo.log(branch_name, nil).first(3)
|
||||||
[commit.sha, commit.message]
|
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
|
end
|
||||||
|
|
||||||
if change_type == 'delete'
|
if change_type == 'delete'
|
||||||
kind = 'git_delete_branch_notification'
|
kind = 'git_delete_branch_notification'
|
||||||
options = {:project_id => record.project.id, :project_name => record.project.name, :branch_name => branch_name,
|
options = {:project_id => record.project.id, :project_name => record.project.name, :branch_name => branch_name,
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
# -*- encoding : utf-8 -*-
|
# -*- encoding : utf-8 -*-
|
||||||
class GitHook
|
class GitHook
|
||||||
attr_reader :repo, :newrev, :oldrev, :newrev_type, :oldrev_type, :refname,
|
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
|
include Resque::Plugins::Status
|
||||||
|
|
||||||
def initialize(owner_uname, repo, newrev, oldrev, ref, newrev_type, oldrev_type = nil)
|
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 = repo, newrev, oldrev, ref, newrev_type, oldrev_type
|
@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!
|
if @owner = User.where(:uname => owner_uname).first || Group.where(:uname => owner_uname).first!
|
||||||
@project = @owner.own_projects.where(:name => repo).first!
|
@project = @owner.own_projects.where(:name => repo).first!
|
||||||
end
|
end
|
||||||
|
|
|
@ -56,7 +56,10 @@ module Modules
|
||||||
return false if (index.current_tree / path).nil?
|
return false if (index.current_tree / path).nil?
|
||||||
|
|
||||||
index.add(path, data)
|
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
|
end
|
||||||
|
|
||||||
def paginate_commits(treeish, options = {})
|
def paginate_commits(treeish, options = {})
|
||||||
|
@ -167,8 +170,8 @@ module Modules
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
def process_hook(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)
|
rec = GitHook.new(owner_uname, repo, newrev, oldrev, ref, newrev_type, oldrev_type, user, message)
|
||||||
ActivityFeedObserver.instance.after_create rec
|
ActivityFeedObserver.instance.after_create rec
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue