26 Commits

Author SHA1 Message Date
Alexander Meindl
077bdc6018 Fix settings, which should support fallback with redmine_plugin_kit 2021-12-08 16:47:56 +01:00
Alexander Meindl
6bbc235732 Version bump and changelog update 2021-12-08 15:58:08 +01:00
Alexander Meindl
a4dabae9c9 Use redmine_plugin kit as loader 2021-12-07 19:40:32 +01:00
Alexander Meindl
923d3b8408 Working on zeitwerk support 2021-11-23 19:42:25 +01:00
Alexander Meindl
bba0807350 remove ruby 2.5 tests and add ruby 3.0 tests 2021-11-11 10:21:31 +01:00
Alexander Meindl
3f12e31568 Ruby 2.6 required 2021-11-11 09:33:20 +01:00
Alexander Meindl
d046b7bec9 Switch to postgres14 for github actions 2021-10-05 07:06:15 +02:00
Alexander Meindl
959b9ce041 correct note 2021-09-20 12:46:51 +02:00
Alexander Meindl
1c34d31623 adjust rubocop for new rubocop version 2021-09-14 19:58:36 +02:00
Alexander Meindl
d04fcc814a Version bump to 1.0.10 2021-08-24 18:06:30 +02:00
Alexander Meindl
1730fb05fd Move asynchron delivery job to default Rails directory 2021-08-24 18:01:48 +02:00
Alexander Meindl
7326c81c5f Merge pull request #91 from Contargo/asynchronous-job
Use asynchronous ActiveJob for message delivery
2021-08-24 17:47:56 +02:00
Florian Krupicka
05d4b5bc8d Fix: missed a small param copied from the original network call 2021-08-24 17:13:55 +02:00
Florian Krupicka
f4fbf45895 Use asynchronous ActiveJob for message delivery
Calling out to a 3rd party web service like Slack or Mattermost blocks
the request for the current Redmine user. Depending on network latency,
this can result in very slow response on any action that is notified via
`redmine_messenger`.

Instead the backend call should make use of Rails builtin asynchronous
background job queuing (the same as used for Redmine mails), returning
to the user earlier.

We don't specify the actual queue backend for this job, so any Redmine
installation can select an appropiate queue backend by themselves or
simply use the default builtin backends.
2021-08-24 16:58:40 +02:00
Alexander Meindl
4fa7ed5d71 Remove unused css class 2021-07-15 15:54:04 +02:00
Alexander Meindl
6af8205469 delete project settings, if project is removed 2021-07-09 17:22:28 +02:00
Alexander Meindl
7d39ba99ec use project relation for messenger_setting 2021-07-09 17:09:20 +02:00
Alexander Meindl
28f5d2d0c6 adjust number of available languages 2021-07-07 07:01:18 +02:00
Alexander Meindl
32b0b01ae0 Merge pull request #89 from evroon/patch-2
Create Dutch locale
2021-07-07 06:49:13 +02:00
Alexander Meindl
b90cfe5334 Merge pull request #88 from evroon/patch-1
Fix typos in English locale
2021-07-07 06:47:21 +02:00
Erik Vroon
53e00d1abb Replace 'en' by 'nl' in nl.yml 2021-07-06 20:50:27 +02:00
Erik Vroon
78d9896647 Small improvements in nl locale 2021-07-06 20:48:36 +02:00
Erik Vroon
1bb62a1cbc Create Dutch locale 2021-07-06 20:40:57 +02:00
Erik Vroon
f6bc1310ca Fix typos in English locale 2021-07-06 20:40:37 +02:00
Alexander Meindl
eb9de1bc8e rename env JENKINS to COVERAGE 2021-05-17 16:48:10 +02:00
Alexander Meindl
51de72e3fb Fix version check 2021-04-18 16:05:57 +02:00
20 changed files with 259 additions and 162 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -1,6 +1,24 @@
Changelog
=========
1.0.12
------
- Fixed settings bug introducted with version 1.0.11
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
1.0.9
-----

View File

@@ -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__

View File

@@ -73,7 +73,7 @@ Requirements
------------
* Redmine version >= 4.1.0
* Ruby version >= 2.5.0
* Ruby version >= 2.6.0
### Older versions

View File

@@ -0,0 +1,25 @@
# frozen_string_literal: true
require 'net/http'
require 'uri'
class MessengerDeliverJob < ActiveJob::Base
queue_as :default
def perform(url, params)
uri = URI url
http_options = { use_ssl: uri.scheme == 'https' }
http_options[:verify_mode] = OpenSSL::SSL::VERIFY_NONE unless RedmineMessenger.setting? :messenger_verify_ssl
begin
req = Net::HTTP::Post.new uri
req.set_form_data payload: params.to_json
Net::HTTP.start uri.hostname, uri.port, http_options do |http|
response = http.request req
Rails.logger.warn response.inspect unless [Net::HTTPSuccess, Net::HTTPRedirection, Net::HTTPOK].include? response
end
rescue StandardError => e
Rails.logger.warn "cannot connect to #{url}"
Rails.logger.warn e
end
end
end

View File

@@ -1,8 +1,5 @@
# frozen_string_literal: true
require 'net/http'
require 'uri'
class Messenger
include Redmine::I18n
@@ -30,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 }
@@ -47,21 +44,8 @@ class Messenger
end
channels.each do |channel|
uri = URI url
params[:channel] = channel
http_options = { use_ssl: uri.scheme == 'https' }
http_options[:verify_mode] = OpenSSL::SSL::VERIFY_NONE unless RedmineMessenger.setting? :messenger_verify_ssl
begin
req = Net::HTTP::Post.new uri
req.set_form_data payload: params.to_json
Net::HTTP.start uri.hostname, uri.port, http_options do |http|
response = http.request req
Rails.logger.warn response.inspect unless [Net::HTTPSuccess, Net::HTTPRedirection, Net::HTTPOK].include? response
end
rescue StandardError => e
Rails.logger.warn "cannot connect to #{url}"
Rails.logger.warn e
end
MessengerDeliverJob.perform_later url, params
end
end
@@ -80,14 +64,14 @@ class Messenger
return if proj.blank?
# project based
pm = MessengerSetting.find_by project_id: proj.id
pm = proj.messenger_setting
return pm.messenger_url if !pm.nil? && pm.messenger_url.present?
# parent project based
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
@@ -104,7 +88,7 @@ class Messenger
return if proj.blank?
# project based
pm = MessengerSetting.find_by project_id: proj.id
pm = proj.messenger_setting
return pm.send config if !pm.nil? && pm.send(config).present?
default_textfield proj, config
@@ -114,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
@@ -123,7 +107,7 @@ class Messenger
return [] if proj.blank?
# project based
pm = MessengerSetting.find_by project_id: proj.id
pm = proj.messenger_setting
if !pm.nil? && pm.messenger_channel.present?
return [] if pm.messenger_channel == '-'
@@ -137,7 +121,7 @@ class Messenger
@setting_found = 0
# project based
pm = MessengerSetting.find_by project_id: proj.id
pm = proj.messenger_setting
unless pm.nil? || pm.send(config).zero?
@setting_found = 1
return false if pm.send(config) == 1
@@ -153,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
@@ -296,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
[]

View File

@@ -5,11 +5,11 @@ class MessengerSetting < ActiveRecord::Base
validates :messenger_url, format: { with: URI::DEFAULT_PARSER.make_regexp(%w[http https]), allow_blank: true }
def self.find_or_create(p_id)
setting = MessengerSetting.find_by project_id: p_id
def self.find_or_create(project_id)
setting = MessengerSetting.find_by project_id: project_id
unless setting
setting = MessengerSetting.new
setting.project_id = p_id
setting.project_id = project_id
setting.save!
end

View File

@@ -4,8 +4,7 @@
= labelled_form_for :setting,
@messenger_setting,
url: project_messenger_setting_path(project_id: @project),
method: :put,
class: 'tabular' do |f|
method: :put do |f|
fieldset#messenger_settings.box.tabular
legend = l :label_messenger_outgoing_webhook

View File

@@ -43,7 +43,7 @@ en:
label_settings_post_wiki_updates: Wiki updates?
label_settings_post_wiki: Post Wiki added?
label_settings_updated_include_description: Description in update issue?
messenger_channel_info_html: 'Here you have to specify the channel, which should be used. You can define multible channels, seperated by comma'
messenger_channel_info_html: 'Here you have to specify the channel, which should be used. You can define multiple channels, seperated by comma'
messenger_contacts_intro: Activate the changes for Issues that should be sent to the pre-defined Messenger channel.
messenger_db_intro: Activate the changes for DB that should be sent to the pre-defined Messenger channel.
messenger_issue_intro: Activate the changes for Issues that should be sent to the pre-defined Messenger channel.
@@ -52,6 +52,6 @@ en:
messenger_settings_project_intro: "If you left empty the Messenger URL in the administration area in case to be not globally notified by all project changes you can configure your Messenger URL in the project settings."
messenger_url_info_html: 'Generate an <a target="_blank" href="https://github.com/AlphaNodes/redmine_messenger#prepare-your-messenger-service">Incoming WebHook</a> URL from the messenger service. Leave it empty, if you only want to activate specific projects with project based settings'
messenger_verify_ssl_info_html: 'If your Messenger service uses an invalid or self-signed SSL certificate, disable it.'
messenger_direct_users_messages_info_html: 'If enabled Messenger will post http requests to each user as channel(direct message in RocketChat) along with post in channel'
messenger_direct_users_messages_info_html: 'If enabled Messenger will post http requests to each user as channel (direct message in RocketChat) along with post in channel'
messenger_wiki_intro: Activate the changes for Wikis that should be sent to the pre-defined Messenger channel.
permission_manage_messenger: Manage messenger

57
config/locales/nl.yml Normal file
View File

@@ -0,0 +1,57 @@
# Dutch strings
nl:
default_mentionsl_info: Standaard gebruikers om op de hoogte te stellen, gescheiden door een komma (e.g. @all, @here)
label_messenger_contact_created: "%{project_url} - Contact %{url} aangemaakt door *%{user}*"
label_messenger_contact_updated: "%{project_url} - Contact %{url} bijgewerkt door *%{user}*"
label_messenger_db_entry_created: "%{project_url} - DB entry %{url} aangemaakt door *%{user}*"
label_messenger_db_entry_updated: "%{project_url} - DB entry %{url} bijgewerkt door *%{user}*"
label_messenger_default_not_visible: Standaardwaarde is niet zichtbaar vanwege beveiligingsredenen.
label_messenger_issue_created: "%{project_url} - Issue %{url} aangemaakt door *%{user}*"
label_messenger_issue_updated: "%{project_url} - Issue %{url} bijgewerkt door *%{user}*"
label_messenger_outgoing_webhook: Uitgaande Webhook
label_messenger_password_created: "%{project_url} - Wachtwoord %{url} aangemaakt door *%{user}*"
label_messenger_password_updated: "%{project_url} - Wachtwoord %{url} bijgewerkt door *%{user}*"
label_messenger_project_text_field_info: Laat leeg voor systeeminstelling.
label_messenger_setting: Messenger Instellingen
label_messenger_settings_default: Systeeminstelling
label_messenger_settings_disabled: Uitgeschakeld
label_messenger_settings_enabled: Ingeschakeld
label_messenger_wiki_created: "%{project_url} - Wiki %{url} aangemaakt door *%{user}*"
label_messenger_wiki_updated: "%{project_url} - Wiki %{url} bijgewerkt door *%{user}*"
label_messenger: Messenger
label_settings_auto_mentions: Zet namen om in mentions?
label_settings_default_mentions: Standaardgebuikers voor mentions
label_settings_display_watchers: Geef watchers weer?
label_settings_messenger_channel: Messenger Kanaal
label_settings_messenger_icon: Messenger Icoon
label_settings_messenger_url: Messenger URL
label_settings_messenger_username: Messenger gebruikersnaam
label_settings_messenger_verify_ssl: Verifieer SSL
label_settings_messenger_direct_users_messages: Stuur directe berichten
label_settings_new_include_description: Nieuwe issue beschrijving?
label_settings_post_contact_updates: Contact bijwerkingen?
label_settings_post_contact: Contact aangemaakt?
label_settings_post_db_updates: DB entry bijwerkingen?
label_settings_post_db: DB entry toegevoegd?
label_settings_post_password_updates: Wachtwoord bijwerkingen?
label_settings_post_password: Wachtwoord toegevoegd?
label_settings_post_private_contacts: Private contacten?
label_settings_post_private_db: Private DB entries?
label_settings_post_private_issues: Private issue bijwerkingen?
label_settings_post_private_notes: Private notes bijwerkingen?
label_settings_post_updates: Issue bijwerkingen?
label_settings_post_wiki_updates: Wiki bijwerkingen?
label_settings_post_wiki: Wiki toegevoegd?
label_settings_updated_include_description: Beschrijving in bijwerking issue?
messenger_channel_info_html: 'Hier kun je het kanaal opgeven dat gebruikt moet worden. Meerdere kanalen kunnen worden gebruikt, gescheiden door een komma'
messenger_contacts_intro: Activeer de bijwerkingen voor Issues die gestuurd moeten worden naar het van tevoren gekozen kanaal.
messenger_db_intro: Activeer de bijwerkingen van de database die gestuurd moeten worden naar het van tevoren gekozen kanaal.
messenger_issue_intro: Activeer de bijwerkingen voor Issues die gestuurd moeten worden naar het van tevoren gekozen kanaal.
messenger_passwords_intro: Activeer de bijwerkingen voor wachtwoorden die gestuurd moeten worden naar het van tevoren gekozen kanaal.
messenger_settings_intro: "Laat de Messenger-URL in het beheergedeelte leeg om geen berichten van Redmine naar de Messenger te sturen. Het maakt niet uit wat je hier nog meer hebt geconfigureerd. Als je berichten van alle Redmine-projecten naar de Messenger wilt sturen, vul dan de URL in. De berichten worden naar het specifieke kanaal gestuurd. Als je alleen door enkele van de projecten (niet alle) op de hoogte wilt worden gehouden, laat u de messenger-URL hier leeg en gebruik de specifieke projectconfiguratie."
messenger_settings_project_intro: "Als u de Messenger-URL in het beheergedeelte leeg hebt gelaten voor het geval je niet wereldwijd op de hoogte wordt gesteld door alle projectwijzigingen, kun je de Messenger-URL configureren in de projectinstellingen."
messenger_url_info_html: 'Genereer een <a target="_blank" href="https://github.com/AlphaNodes/redmine_messenger#prepare-your-messenger-service">Inkomende WebHook</a> URL van de messenger service. Laat het leeg als u alleen specifieke projecten wilt activeren met projectgebaseerde instellingen'
messenger_verify_ssl_info_html: 'Als je Messenger-service een ongeldig of zelfondertekend SSL-certificaat gebruikt, schakel deze checkbox uit.'
messenger_direct_users_messages_info_html: 'Indien ingeschakeld, zal Messenger http-verzoeken naar elke gebruiker plaatsen als kanaal (direct bericht in RocketChat) samen met een bericht in het kanaal'
messenger_wiki_intro: "Activeer de wijzigingen voor Wiki's die naar het vooraf gedefinieerde Messenger-kanaal moeten worden verzonden."
permission_manage_messenger: Beheer messenger

26
config/settings.yml Normal file
View File

@@ -0,0 +1,26 @@
---
messenger_url: ''
messenger_icon: 'https://raw.githubusercontent.com/alphanodes/redmine_messenger/master/assets/images/icon.png'
messenger_channel: 'redmine'
messenger_username: 'robot'
messenger_verify_ssl: 1
messenger_direct_users_messages: 0
auto_mentions: 0
default_mentions: ''
display_watchers: 0
post_updates: 1
new_include_description: 1
updated_include_description: 1
post_private_contacts: 0
post_private_db: 0
post_private_issues: 0
post_private_notes: 0
post_wiki: 0
post_wiki_updates: 0
post_db: 0
post_db_updates: 0
post_contact: 0
post_contact_updates: 0
post_password: 0
post_password_updates: 0

34
init.rb
View File

@@ -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.4'
loader = RedminePluginKit::Loader.new plugin_id: 'redmine_messenger'
Redmine::Plugin.register :redmine_messenger do
name 'Redmine Messenger'
@@ -14,34 +14,8 @@ Redmine::Plugin.register :redmine_messenger do
permission :manage_messenger, projects: :settings, messenger_settings: :update
settings default: {
messenger_url: '',
messenger_icon: 'https://raw.githubusercontent.com/alphanodes/redmine_messenger/master/assets/images/icon.png',
messenger_channel: 'redmine',
messenger_username: 'robot',
messenger_verify_ssl: '1',
messenger_direct_users_messages: '0',
auto_mentions: '0',
default_mentions: '',
display_watchers: '0',
post_updates: '1',
new_include_description: '1',
updated_include_description: '1',
post_private_contacts: '0',
post_private_db: '0',
post_private_issues: '0',
post_private_notes: '0',
post_wiki: '0',
post_wiki_updates: '0',
post_db: '0',
post_db_updates: '0',
post_contact: '0',
post_contact_updates: '0',
post_password: '0',
post_password_updates: '0'
}, partial: 'settings/messenger_settings'
settings default: loader.default_settings, 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'

View File

@@ -1,43 +1,33 @@
# frozen_string_literal: true
require 'redmine_messenger/version'
module RedmineMessenger
VERSION = '1.0.12'
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
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

View File

@@ -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

View 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

View File

@@ -0,0 +1,13 @@
# frozen_string_literal: true
module RedmineMessenger
module Patches
module ProjectPatch
extend ActiveSupport::Concern
included do
has_one :messenger_setting, dependent: :destroy
end
end
end
end

View File

@@ -1,5 +0,0 @@
# frozen_string_literal: true
module RedmineMessenger
VERSION = '1.0.9'
end

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
if ENV['JENKINS']
if ENV['COVERAGE']
require 'simplecov'
SimpleCov.start :rails do
add_filter 'init.rb'

View File

@@ -21,7 +21,7 @@ class I18nTest < ActiveSupport::TestCase
def test_locales_validness
lang_files_count = Dir[Rails.root.join('plugins/redmine_messenger/config/locales/*.yml')].size
assert_equal 6, lang_files_count
assert_equal 7, lang_files_count
valid_languages.each do |lang|
assert set_language_if_valid(lang)
case lang.to_s