forgeplus/app/models/message_template/project_issue.rb

58 lines
2.2 KiB
Ruby
Raw Normal View History

2021-09-09 16:32:13 +08:00
# == Schema Information
#
# Table name: message_templates
#
2021-09-14 17:39:58 +08:00
# id :integer not null, primary key
# type :string(255)
# sys_notice :text(65535)
# email :text(65535)
# created_at :datetime not null
# updated_at :datetime not null
# notification_url :string(255)
2021-09-24 15:37:55 +08:00
# email_title :string(255)
2021-09-09 16:32:13 +08:00
#
2021-09-14 23:04:33 +08:00
# TODO 我管理/关注的仓库有新的易修
2021-09-09 16:32:13 +08:00
class MessageTemplate::ProjectIssue < MessageTemplate
2021-09-14 23:04:33 +08:00
2021-09-16 16:54:49 +08:00
# MessageTemplate::ProjectIssue.get_message_content(User.where(login: 'yystopf'), User.where(login: 'forgetest1'), User.last, Issue.last)
def self.get_message_content(managers, followers, operator, issue)
project = issue&.project
owner = project&.owner
receivers = managers + followers
content = sys_notice.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name).gsub('{title}', issue&.subject)
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s)
2021-09-14 23:04:33 +08:00
return receivers_string(receivers), content, url
rescue => e
Rails.logger.info("MessageTemplate::ProjectIssue.get_message_content [ERROR] #{e}")
return '', '', ''
end
2021-09-22 14:25:56 +08:00
2021-09-24 15:37:55 +08:00
def self.get_email_message_content(receiver, is_manager, operator, issue)
2021-09-22 14:25:56 +08:00
project = issue&.project
owner = project&.owner
2021-09-24 15:37:55 +08:00
title = email_title
title.gsub!('{nickname1}', operator&.real_name)
title.gsub!('{nickname2}', owner&.real_name)
title.gsub!('{repository}', project&.name)
content = email
content.gsub!('{receiver}', receiver&.real_name)
content.gsub!('{baseurl}', base_url)
content.gsub!('{login1}', operator&.login)
content.gsub!('{nickname1}', operator&.real_name)
content.gsub!('{nickname2}', owner&.real_name)
content.gsub!('{repository}', project&.name)
content.gsub!('{login2}', owner&.login)
content.gsub!('{identifier}', project&.identifier)
content.gsub!('{id}', issue&.id.to_s)
content.gsub!('{title}', issue&.subject)
2021-09-22 14:25:56 +08:00
2021-09-24 15:37:55 +08:00
return receiver&.mail, title, content
2021-09-22 14:25:56 +08:00
rescue => e
Rails.logger.info("MessageTemplate::ProjectIssue.get_email_message_content [ERROR] #{e}")
return '', '', ''
end
2021-09-09 16:32:13 +08:00
end