2012-03-22 17:11:12 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2013-06-27 15:40:19 +01:00
|
|
|
module Modules::Observers::ActivityFeed::Git
|
|
|
|
|
|
|
|
def self.create_notifications(record)
|
2012-01-25 08:31:49 +00:00
|
|
|
|
|
|
|
case record.class.to_s
|
2012-02-10 17:33:05 +00:00
|
|
|
when 'GitHook'
|
2012-04-02 20:27:36 +01:00
|
|
|
return unless record.project
|
2012-10-05 18:32:29 +01:00
|
|
|
PullRequest.where("from_project_id = ? OR to_project_id = ?", record.project, record.project).needed_checking.each {|pull| pull.check}
|
2013-04-25 16:27:48 +01:00
|
|
|
record.project.hooks.each{ |h| h.receive_push(record) }
|
2012-08-06 19:13:07 +01:00
|
|
|
|
2012-02-10 17:33:05 +00:00
|
|
|
change_type = record.change_type
|
2012-03-22 17:11:12 +00:00
|
|
|
branch_name = record.refname.split('/').last
|
2013-03-07 08:06:34 +00:00
|
|
|
|
2012-02-10 17:33:05 +00:00
|
|
|
if change_type == 'delete'
|
2012-02-14 16:46:08 +00:00
|
|
|
kind = 'git_delete_branch_notification'
|
2012-03-14 17:00:26 +00:00
|
|
|
options = {:project_id => record.project.id, :project_name => record.project.name, :branch_name => branch_name,
|
|
|
|
:change_type => change_type, :project_owner => record.project.owner.uname}
|
2012-02-10 17:33:05 +00:00
|
|
|
else
|
2013-03-07 08:06:34 +00:00
|
|
|
if record.message # online update
|
2013-06-20 11:37:05 +01:00
|
|
|
last_commits, commits = [[record.newrev, record.message]], []
|
|
|
|
all_commits = last_commits
|
2013-03-07 08:06:34 +00:00
|
|
|
else
|
|
|
|
commits = record.project.repo.commits_between(record.oldrev, record.newrev)
|
2013-06-19 22:13:04 +01:00
|
|
|
all_commits = commits.collect { |commit| [commit.sha, commit.message] }
|
|
|
|
last_commits = all_commits.last(3).reverse
|
2013-03-07 08:06:34 +00:00
|
|
|
end
|
|
|
|
|
2012-02-14 16:46:08 +00:00
|
|
|
kind = 'git_new_push_notification'
|
2013-06-19 22:13:04 +01:00
|
|
|
options = {:project_id => record.project.id, :project_name => record.project.name, :last_commits => last_commits,
|
2013-03-07 08:06:34 +00:00
|
|
|
:branch_name => branch_name, :change_type => change_type, :project_owner => record.project.owner.uname}
|
|
|
|
if commits.count > 3
|
|
|
|
commits = commits[0...-3]
|
|
|
|
options.merge!({:other_commits_count => commits.count, :other_commits => "#{commits[0].sha[0..9]}...#{commits[-1].sha[0..9]}"})
|
|
|
|
end
|
2013-06-19 22:13:04 +01:00
|
|
|
Comment.create_link_on_issues_from_item(record, all_commits) if all_commits.count > 0
|
2012-02-14 16:46:08 +00:00
|
|
|
end
|
2013-03-07 08:06:34 +00:00
|
|
|
options.merge!({:user_id => record.user.id, :user_name => record.user.name, :user_email => record.user.email}) if record.user
|
2012-02-14 16:46:08 +00:00
|
|
|
|
2012-12-13 18:18:22 +00:00
|
|
|
record.project.admins.each do |recipient|
|
2013-03-07 08:06:34 +00:00
|
|
|
next if record.user && record.user.id == recipient.id
|
2012-06-16 19:27:46 +01:00
|
|
|
ActivityFeed.create!(
|
2012-12-13 18:18:22 +00:00
|
|
|
:user => recipient,
|
2012-02-14 16:46:08 +00:00
|
|
|
:kind => kind,
|
|
|
|
:data => options
|
2012-02-10 17:33:05 +00:00
|
|
|
)
|
|
|
|
end
|
2012-03-05 09:11:50 +00:00
|
|
|
|
2012-06-16 19:27:46 +01:00
|
|
|
when 'Hash' # 'Gollum::Committer'
|
|
|
|
actor = User.find_by_uname! record[:actor_name]
|
|
|
|
project = Project.find record[:project_id]
|
2012-02-14 16:09:41 +00:00
|
|
|
|
2012-12-13 18:18:22 +00:00
|
|
|
project.admins.each do |recipient|
|
2012-06-16 19:27:46 +01:00
|
|
|
ActivityFeed.create!(
|
2012-12-13 18:18:22 +00:00
|
|
|
:user => recipient,
|
2012-02-14 16:09:41 +00:00
|
|
|
:kind => 'wiki_new_commit_notification',
|
2012-03-14 17:00:26 +00:00
|
|
|
:data => {:user_id => actor.id, :user_name => actor.name, :user_email => actor.email, :project_id => project.id,
|
2012-06-16 19:27:46 +01:00
|
|
|
:project_name => project.name, :commit_sha => record[:commit_sha], :project_owner => project.owner.uname}
|
2012-02-14 16:09:41 +00:00
|
|
|
)
|
|
|
|
end
|
2012-01-25 08:31:49 +00:00
|
|
|
end
|
2013-06-27 15:40:19 +01:00
|
|
|
|
2012-01-25 08:31:49 +00:00
|
|
|
end
|
|
|
|
|
2013-06-27 15:40:19 +01:00
|
|
|
end
|