Working on zeitwerk support
This commit is contained in:
6
init.rb
6
init.rb
@@ -42,6 +42,8 @@ Redmine::Plugin.register :redmine_messenger do
|
||||
}, partial: 'settings/messenger_settings'
|
||||
end
|
||||
|
||||
Rails.configuration.to_prepare do
|
||||
RedmineMessenger.setup
|
||||
if Rails.version > '6.0'
|
||||
ActiveSupport.on_load(:active_record) { RedmineMessenger.setup }
|
||||
else
|
||||
Rails.configuration.to_prepare { RedmineMessenger.setup }
|
||||
end
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'redmine_messenger/version'
|
||||
|
||||
module RedmineMessenger
|
||||
VERSION = '1.0.10'
|
||||
REDMINE_CONTACTS_SUPPORT = Redmine::Plugin.installed? 'redmine_contacts'
|
||||
REDMINE_DB_SUPPORT = Redmine::Plugin.installed? 'redmine_db'
|
||||
|
||||
@@ -21,7 +20,7 @@ module RedmineMessenger
|
||||
ActionView::Base.include RedmineMessenger::Helpers
|
||||
|
||||
# Hooks
|
||||
require_dependency 'redmine_messenger/hooks'
|
||||
RedmineMessenger::Hooks
|
||||
end
|
||||
|
||||
def settings
|
||||
|
||||
@@ -1,57 +1,59 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module RedmineMessenger
|
||||
class MessengerListener < Redmine::Hook::Listener
|
||||
def model_changeset_scan_commit_for_issue_ids_pre_issue_update(context = {})
|
||||
issue = context[:issue]
|
||||
journal = issue.current_journal
|
||||
changeset = context[:changeset]
|
||||
module Hooks
|
||||
class MessengerListener < Redmine::Hook::Listener
|
||||
def model_changeset_scan_commit_for_issue_ids_pre_issue_update(context = {})
|
||||
issue = context[:issue]
|
||||
journal = issue.current_journal
|
||||
changeset = context[:changeset]
|
||||
|
||||
channels = Messenger.channels_for_project issue.project
|
||||
url = Messenger.url_for_project issue.project
|
||||
channels = Messenger.channels_for_project issue.project
|
||||
url = Messenger.url_for_project issue.project
|
||||
|
||||
return unless channels.present? && url && issue.changes.any? && Messenger.setting_for_project(issue.project, :post_updates)
|
||||
return if issue.is_private? && !Messenger.setting_for_project(issue.project, :post_private_issues)
|
||||
return unless channels.present? && url && issue.changes.any? && Messenger.setting_for_project(issue.project, :post_updates)
|
||||
return if issue.is_private? && !Messenger.setting_for_project(issue.project, :post_private_issues)
|
||||
|
||||
msg = "[#{Messenger.markup_format issue.project}]" \
|
||||
" #{Messenger.markup_format journal.user.to_s} updated <#{Messenger.object_url issue}|#{Messenger.markup_format issue}>"
|
||||
msg = "[#{Messenger.markup_format issue.project}]" \
|
||||
" #{Messenger.markup_format journal.user.to_s} updated <#{Messenger.object_url issue}|#{Messenger.markup_format issue}>"
|
||||
|
||||
repository = changeset.repository
|
||||
repository = changeset.repository
|
||||
|
||||
if Setting.host_name.to_s =~ %r{/\A(https?://)?(.+?)(:(\d+))?(/.+)?\z/i}
|
||||
host = Regexp.last_match 2
|
||||
port = Regexp.last_match 4
|
||||
prefix = Regexp.last_match 5
|
||||
revision_url = Rails.application.routes.url_for(
|
||||
controller: 'repositories',
|
||||
action: 'revision',
|
||||
id: repository.project,
|
||||
repository_id: repository.identifier_param,
|
||||
rev: changeset.revision,
|
||||
host: host,
|
||||
protocol: Setting.protocol,
|
||||
port: port,
|
||||
script_name: prefix
|
||||
)
|
||||
else
|
||||
revision_url = Rails.application.routes.url_for(
|
||||
controller: 'repositories',
|
||||
action: 'revision',
|
||||
id: repository.project,
|
||||
repository_id: repository.identifier_param,
|
||||
rev: changeset.revision,
|
||||
host: Setting.host_name,
|
||||
protocol: Setting.protocol
|
||||
)
|
||||
if Setting.host_name.to_s =~ %r{/\A(https?://)?(.+?)(:(\d+))?(/.+)?\z/i}
|
||||
host = Regexp.last_match 2
|
||||
port = Regexp.last_match 4
|
||||
prefix = Regexp.last_match 5
|
||||
revision_url = Rails.application.routes.url_for(
|
||||
controller: 'repositories',
|
||||
action: 'revision',
|
||||
id: repository.project,
|
||||
repository_id: repository.identifier_param,
|
||||
rev: changeset.revision,
|
||||
host: host,
|
||||
protocol: Setting.protocol,
|
||||
port: port,
|
||||
script_name: prefix
|
||||
)
|
||||
else
|
||||
revision_url = Rails.application.routes.url_for(
|
||||
controller: 'repositories',
|
||||
action: 'revision',
|
||||
id: repository.project,
|
||||
repository_id: repository.identifier_param,
|
||||
rev: changeset.revision,
|
||||
host: Setting.host_name,
|
||||
protocol: Setting.protocol
|
||||
)
|
||||
end
|
||||
|
||||
attachment = {}
|
||||
attachment[:text] = ll(Setting.default_language,
|
||||
:text_status_changed_by_changeset,
|
||||
"<#{revision_url}|#{Messenger.markup_format changeset.comments}>")
|
||||
attachment[:fields] = journal.details.map { |d| Messenger.detail_to_field d }
|
||||
|
||||
Messenger.speak msg, channels, url, attachment: attachment, project: repository.project
|
||||
end
|
||||
|
||||
attachment = {}
|
||||
attachment[:text] = ll(Setting.default_language,
|
||||
:text_status_changed_by_changeset,
|
||||
"<#{revision_url}|#{Messenger.markup_format changeset.comments}>")
|
||||
attachment[:fields] = journal.details.map { |d| Messenger.detail_to_field d }
|
||||
|
||||
Messenger.speak msg, channels, url, attachment: attachment, project: repository.project
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module RedmineMessenger
|
||||
VERSION = '1.0.10'
|
||||
end
|
||||
Reference in New Issue
Block a user