Skip to content

Commit

Permalink
Update CI config: add Redmine 5
Browse files Browse the repository at this point in the history
  • Loading branch information
nanego committed Dec 19, 2023
1 parent 95c1d77 commit e01e7c1
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 35 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/4_1_7.yml → .github/workflows/5_1_1.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Tests 4.1.7
name: Tests 5.1.1

env:
PLUGIN_NAME: redmine_notified
REDMINE_VERSION: 4.1.7
REDMINE_VERSION: 5.1.1
RAILS_ENV: test

on:
Expand All @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
ruby: ['2.6']
ruby: ['3.1']
db: ['postgres']
fail-fast: false

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
ruby: ['2.7']
ruby: ['3.1']
db: ['postgres']
fail-fast: false

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ Test status
|Plugin branch| Redmine Version | Test Status |
|-------------|-------------------|------------------|
|master | 4.2.11 | [![4.2.11][1]][5]|
|master | 4.1.7 | [![4.1.7][2]][5] |
|master | 5.1.1 | [![5.1.1][2]][5] |
|master | master | [![master][4]][5]|

[1]: https://github.com/jbbarth/redmine_notified/actions/workflows/4_2_11.yml/badge.svg
[2]: https://github.com/jbbarth/redmine_notified/actions/workflows/4_1_7.yml/badge.svg
[2]: https://github.com/jbbarth/redmine_notified/actions/workflows/5_1_1.yml/badge.svg
[4]: https://github.com/jbbarth/redmine_notified/actions/workflows/master.yml/badge.svg
[5]: https://github.com/jbbarth/redmine_notified/actions

Expand Down
7 changes: 1 addition & 6 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
require 'redmine'
require 'redmine_notified/hooks'

ActiveSupport::Reloader.to_prepare do
require_dependency 'redmine_notified/mail_notifications_subscriber'
require_dependency 'redmine_notified/notifications_association_patch'
end
require_relative 'lib/redmine_notified/hooks'

Redmine::Plugin.register :redmine_notified do
name 'Redmine Notified plugin'
Expand Down
9 changes: 9 additions & 0 deletions lib/redmine_notified/hooks.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
module RedmineNotified

class Hooks < Redmine::Hook::ViewListener
#adds our css on each page
def view_layouts_base_html_head(context)
stylesheet_link_tag('plugin', :plugin => "redmine_notified")
end
end

class ModelHook < Redmine::Hook::Listener
def after_plugins_loaded(_context = {})
require_relative 'mail_notifications_subscriber'
require_relative 'notifications_association_patch'
end
end

end
46 changes: 25 additions & 21 deletions lib/redmine_notified/mail_notifications_subscriber.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
ActiveSupport::Notifications.subscribe "deliver.action_mailer" do |name, start, finish, id, payload|
attrs = payload.dup.stringify_keys
%w(from to cc bcc).each do |key|
attrs[key] = attrs[key].join(", ") if attrs.has_key?(key) && attrs[key].is_a?(Enumerable)
end
attrs['mail'] = nil
begin
new_notif = Notification.new(attrs.slice(*Notification.column_names))
new_notif.infer_object_from_message_id
old_notif = Notification.where(:notificable_type => new_notif.notificable_type, :notificable_id => new_notif.notificable_id).first
if old_notif
bcc = []
bcc |= old_notif.bcc.split(', ') if old_notif.bcc.present?
bcc |= new_notif.bcc.split(', ') if new_notif.bcc.present?
old_notif.bcc = bcc.join(", ")
old_notif.save
else
new_notif.save
module RedmineNotified
module MailNotificationsSubscriber
ActiveSupport::Notifications.subscribe "deliver.action_mailer" do |name, start, finish, id, payload|
attrs = payload.dup.stringify_keys
%w(from to cc bcc).each do |key|
attrs[key] = attrs[key].join(", ") if attrs.has_key?(key) && attrs[key].is_a?(Enumerable)
end
attrs['mail'] = nil
begin
new_notif = Notification.new(attrs.slice(*Notification.column_names))
new_notif.infer_object_from_message_id
old_notif = Notification.where(:notificable_type => new_notif.notificable_type, :notificable_id => new_notif.notificable_id).first
if old_notif
bcc = []
bcc |= old_notif.bcc.split(', ') if old_notif.bcc.present?
bcc |= new_notif.bcc.split(', ') if new_notif.bcc.present?
old_notif.bcc = bcc.join(", ")
old_notif.save
else
new_notif.save
end
rescue
#this shouldn't happen, but hey, we don't want to prevent ticket creation if anything fails
Rails.logger.error("ERROR: redmine_notified plugin, unable to add notification for #{attrs.inspect}")
end
end
rescue
#this shouldn't happen, but hey, we don't want to prevent ticket creation if anything fails
Rails.logger.error("ERROR: redmine_notified plugin, unable to add notification for #{attrs.inspect}")
end
end
4 changes: 2 additions & 2 deletions lib/redmine_notified/notifications_association_patch.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module NotificationsAssociationPatch
module RedmineNotified::NotificationsAssociationPatch
def self.included(base)
base.class_eval do
has_many :notifications, :as => :notificable
Expand All @@ -8,5 +8,5 @@ def self.included(base)

%w(issue journal news comment message wiki_content).each do |klass|
require_dependency klass
klass.camelize.constantize.send(:include, NotificationsAssociationPatch)
klass.camelize.constantize.send(:include, RedmineNotified::NotificationsAssociationPatch)
end

0 comments on commit e01e7c1

Please sign in to comment.