Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6bbc235732 | ||
|
|
a4dabae9c9 | ||
|
|
923d3b8408 | ||
|
|
bba0807350 | ||
|
|
3f12e31568 | ||
|
|
d046b7bec9 | ||
|
|
959b9ce041 | ||
|
|
1c34d31623 |
8
.github/workflows/tests.yml
vendored
8
.github/workflows/tests.yml
vendored
@@ -12,17 +12,21 @@ jobs:
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
ruby: ['2.7', '2.6', '2.5']
|
||||
ruby: ['2.7', '2.6', '3.0']
|
||||
redmine: ['4.1-stable', '4.2-stable', 'master']
|
||||
db: ['postgres', 'mysql']
|
||||
exclude:
|
||||
- ruby: '2.7'
|
||||
redmine: 4.1-stable
|
||||
- ruby: '3.0'
|
||||
redmine: 4.1-stable
|
||||
- ruby: '3.0'
|
||||
redmine: 4.2-stable
|
||||
fail-fast: false
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:13
|
||||
image: postgres:14
|
||||
env:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
|
||||
@@ -6,7 +6,7 @@ Rails:
|
||||
Enabled: true
|
||||
|
||||
AllCops:
|
||||
TargetRubyVersion: 2.5
|
||||
TargetRubyVersion: 2.6
|
||||
TargetRailsVersion: 5.2
|
||||
NewCops: enable
|
||||
|
||||
@@ -23,6 +23,9 @@ Layout/LineLength:
|
||||
Rails/ApplicationJob:
|
||||
Enabled: false
|
||||
|
||||
Lint/AmbiguousOperatorPrecedence:
|
||||
Enabled: false
|
||||
|
||||
Rails/ApplicationRecord:
|
||||
Enabled: false
|
||||
|
||||
|
||||
10
CHANGELOG.md
10
CHANGELOG.md
@@ -1,8 +1,16 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
1.0.11
|
||||
------
|
||||
|
||||
- Upcoming Redmine 5 support
|
||||
- Ruby 3 support
|
||||
- Ruby 2.6 or higher is required
|
||||
- Use redmine_plugin_kit as plugin loader
|
||||
|
||||
1.0.10
|
||||
-----
|
||||
------
|
||||
|
||||
- Web service is called asynchron which does not block performance while sending message
|
||||
|
||||
|
||||
3
Gemfile
3
Gemfile
@@ -1,11 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
gem 'redmine_plugin_kit'
|
||||
gem 'slim-rails'
|
||||
|
||||
group :development do
|
||||
# this is only used for development.
|
||||
# if you want to use it, do:
|
||||
# - create .enable_dev file in additionals directory
|
||||
# - create .enable_dev file in messenger directory
|
||||
# - remove rubocop entries from REDMINE/Gemfile
|
||||
# - remove REDMINE/.rubocop* files
|
||||
if File.file? File.expand_path './.enable_dev', __dir__
|
||||
|
||||
@@ -73,7 +73,7 @@ Requirements
|
||||
------------
|
||||
|
||||
* Redmine version >= 4.1.0
|
||||
* Ruby version >= 2.5.0
|
||||
* Ruby version >= 2.6.0
|
||||
|
||||
### Older versions
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class Messenger
|
||||
end
|
||||
|
||||
def speak(msg, channels, url, options)
|
||||
url ||= RedmineMessenger.settings[:messenger_url]
|
||||
url ||= RedmineMessenger.setting :messenger_url
|
||||
return if url.blank? || channels.blank?
|
||||
|
||||
params = { text: msg, link_names: 1 }
|
||||
@@ -71,7 +71,7 @@ class Messenger
|
||||
parent_url = url_for_project proj.parent
|
||||
return parent_url if parent_url.present?
|
||||
# system based
|
||||
return RedmineMessenger.settings[:messenger_url] if RedmineMessenger.settings[:messenger_url].present?
|
||||
return RedmineMessenger.setting :messenger_url if RedmineMessenger.setting(:messenger_url).present?
|
||||
|
||||
nil
|
||||
end
|
||||
@@ -98,7 +98,7 @@ class Messenger
|
||||
# parent project based
|
||||
parent_field = textfield_for_project proj.parent, config
|
||||
return parent_field if parent_field.present?
|
||||
return RedmineMessenger.settings[config] if RedmineMessenger.settings[config].present?
|
||||
return RedmineMessenger.setting config if RedmineMessenger.setting(config).present?
|
||||
|
||||
''
|
||||
end
|
||||
@@ -137,7 +137,7 @@ class Messenger
|
||||
return parent_setting if @setting_found == 1
|
||||
end
|
||||
# system based
|
||||
return true if RedmineMessenger.settings[config].present? && RedmineMessenger.setting?(config)
|
||||
return true if RedmineMessenger.setting(config).present? && RedmineMessenger.setting?(config)
|
||||
|
||||
false
|
||||
end
|
||||
@@ -280,9 +280,9 @@ class Messenger
|
||||
parent_channel = channels_for_project proj.parent
|
||||
return parent_channel if parent_channel.present?
|
||||
# system based
|
||||
if RedmineMessenger.settings[:messenger_channel].present? &&
|
||||
RedmineMessenger.settings[:messenger_channel] != '-'
|
||||
return RedmineMessenger.settings[:messenger_channel].split(',').map!(&:strip).uniq
|
||||
if RedmineMessenger.setting(:messenger_channel).present? &&
|
||||
RedmineMessenger.setting(:messenger_channel) != '-'
|
||||
return RedmineMessenger.setting(:messenger_channel).split(',').map!(&:strip).uniq
|
||||
end
|
||||
|
||||
[]
|
||||
|
||||
7
init.rb
7
init.rb
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
raise "\n\033[31mredmine_messenger requires ruby 2.5 or newer. Please update your ruby version.\033[0m" if RUBY_VERSION < '2.5'
|
||||
loader = RedminePluginKit::Loader.new plugin_id: 'redmine_messenger'
|
||||
|
||||
Redmine::Plugin.register :redmine_messenger do
|
||||
name 'Redmine Messenger'
|
||||
@@ -42,6 +42,5 @@ Redmine::Plugin.register :redmine_messenger do
|
||||
}, partial: 'settings/messenger_settings'
|
||||
end
|
||||
|
||||
Rails.configuration.to_prepare do
|
||||
RedmineMessenger.setup
|
||||
end
|
||||
RedminePluginKit::Loader.persisting { loader.load_model_hooks! }
|
||||
RedminePluginKit::Loader.to_prepare { RedmineMessenger.setup! } if Rails.version < '6.0'
|
||||
|
||||
@@ -1,44 +1,33 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'redmine_messenger/version'
|
||||
|
||||
module RedmineMessenger
|
||||
VERSION = '1.0.11'
|
||||
REDMINE_CONTACTS_SUPPORT = Redmine::Plugin.installed? 'redmine_contacts'
|
||||
REDMINE_DB_SUPPORT = Redmine::Plugin.installed? 'redmine_db'
|
||||
|
||||
include RedminePluginKit::PluginBase
|
||||
|
||||
class << self
|
||||
private
|
||||
|
||||
def setup
|
||||
# Patches
|
||||
Issue.include RedmineMessenger::Patches::IssuePatch
|
||||
Project.include RedmineMessenger::Patches::ProjectPatch
|
||||
WikiPage.include RedmineMessenger::Patches::WikiPagePatch
|
||||
ProjectsController.send :helper, MessengerProjectsHelper
|
||||
Contact.include RedmineMessenger::Patches::ContactPatch if RedmineMessenger::REDMINE_CONTACTS_SUPPORT
|
||||
DbEntry.include RedmineMessenger::Patches::DbEntryPatch if RedmineMessenger::REDMINE_DB_SUPPORT
|
||||
Password.include RedmineMessenger::Patches::PasswordPatch if Redmine::Plugin.installed? 'redmine_passwords'
|
||||
loader.add_patch %w[Issue
|
||||
Project
|
||||
WikiPage]
|
||||
|
||||
loader.add_patch 'Contact' if RedmineMessenger::REDMINE_CONTACTS_SUPPORT
|
||||
loader.add_patch 'DbEntry' if RedmineMessenger::REDMINE_DB_SUPPORT
|
||||
loader.add_patch 'Password' if Redmine::Plugin.installed? 'redmine_passwords'
|
||||
|
||||
# Helper
|
||||
loader.add_helper [{ controller: 'Projects', helper: 'MessengerProjects' }]
|
||||
|
||||
# Global helpers
|
||||
ActionView::Base.include RedmineMessenger::Helpers
|
||||
loader.add_global_helper RedmineMessenger::Helpers
|
||||
|
||||
# Hooks
|
||||
require_dependency 'redmine_messenger/hooks'
|
||||
end
|
||||
|
||||
def settings
|
||||
if Setting[:plugin_redmine_messenger].is_a? Hash
|
||||
new_settings = ActiveSupport::HashWithIndifferentAccess.new Setting[:plugin_redmine_messenger]
|
||||
Setting.plugin_redmine_messenger = new_settings
|
||||
new_settings
|
||||
else
|
||||
# Rails 5 uses ActiveSupport::HashWithIndifferentAccess
|
||||
Setting[:plugin_redmine_messenger]
|
||||
end
|
||||
end
|
||||
|
||||
def setting?(value)
|
||||
return true if settings[value].to_i == 1
|
||||
|
||||
false
|
||||
# Apply patches and helper
|
||||
loader.apply!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
# 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]
|
||||
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
65
lib/redmine_messenger/hooks/model_hook.rb
Normal file
65
lib/redmine_messenger/hooks/model_hook.rb
Normal file
@@ -0,0 +1,65 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module RedmineMessenger
|
||||
module Hooks
|
||||
class ModelHook < Redmine::Hook::Listener
|
||||
def after_plugins_loaded(_context = {})
|
||||
return if Rails.version < '6.0'
|
||||
|
||||
RedmineMessenger.setup!
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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}>"
|
||||
|
||||
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
|
||||
)
|
||||
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
|
||||
end
|
||||
@@ -1,5 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module RedmineMessenger
|
||||
VERSION = '1.0.10'
|
||||
end
|
||||
Reference in New Issue
Block a user