rosa-build/lib/modules/observers/activity_feed/git.rb

66 lines
2.7 KiB
Ruby
Raw Normal View History

2013-06-27 15:40:19 +01:00
module Modules::Observers::ActivityFeed::Git
def self.create_notifications(record)
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
branch_name = record.refname.split('/').last
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'
2014-01-21 04:51:49 +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
if record.message # online update
2013-06-20 11:37:05 +01:00
last_commits, commits = [[record.newrev, record.message]], []
all_commits = last_commits
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
end
2012-02-14 16:46:08 +00:00
kind = 'git_new_push_notification'
2014-01-21 04:51:49 +00:00
options = {project_id: record.project.id, project_name: record.project.name, last_commits: last_commits,
branch_name: branch_name, change_type: change_type, project_owner: record.project.owner.uname}
if commits.count > 3
commits = commits[0...-3]
2014-01-21 04:51:49 +00:00
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
2014-01-21 04:51:49 +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
record.project.admins.each do |recipient|
next if record.user && record.user.id == recipient.id
ActivityFeed.create!(
2014-01-21 04:51:49 +00:00
user: recipient,
kind: kind,
data: options
2012-02-10 17:33:05 +00:00
)
if recipient.notifier.can_notify && recipient.notifier.update_code
2013-11-26 17:21:50 +00:00
UserMailer.send(kind, recipient, options).deliver
end
2012-02-10 17:33:05 +00:00
end
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
project.admins.each do |recipient|
ActivityFeed.create!(
2014-01-21 04:51:49 +00:00
user: recipient,
kind: 'wiki_new_commit_notification',
data: {user_id: actor.id, user_name: actor.name, user_email: actor.email, project_id: project.id,
project_name: project.name, commit_sha: record[:commit_sha], project_owner: project.owner.uname}
2012-02-14 16:09:41 +00:00
)
end
end
end
2014-01-21 04:51:49 +00:00
end