Skip to content

Commit

Permalink
Merge pull request #76 from southbridgeio/compatibility_redmine_5.1
Browse files Browse the repository at this point in the history
add compatibility with Redmine 5.1
  • Loading branch information
nevrfl authored Oct 8, 2024
2 parents bd7ff42 + c557f09 commit b5e3668
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: ruby
rvm:
- 2.4.9
- 2.6.5
- 2.7.2

branches:
only:
Expand All @@ -14,6 +15,7 @@ addons:
env:
- REDMINE_VER=3.4-stable
- REDMINE_VER=4.1-stable
- REDMINE_VER=5.1-stable

install: "echo skip bundle install"

Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.5.6

* Add compatibility with Redmine 5.1
* Fix showing errors

# 0.5.5

* Add functionality for processing photos from telegram
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/redmine_telegram_setup_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def bot_init
bot.api.setWebhook(url: web_hook_url)

redirect_to plugin_settings_path('redmine_bots'), notice: t('redmine_2chat.bot.authorize.success')

rescue Telegram::Bot::Exceptions::ResponseError => error
redirect_to plugin_settings_path('redmine_bots'), alert: parsed_error(error)['description']
end

def bot_deinit
Expand All @@ -66,4 +69,8 @@ def bot_deinit
def save_phone_settings(phone_number:)
Setting.send('plugin_redmine_bots=', Setting.plugin_redmine_bots.merge({'telegram_phone_number' => phone_number.to_s}).to_h)
end

def parsed_error(error)
JSON.parse(error.response.body)
end
end
13 changes: 8 additions & 5 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

require 'telegram/bot'

# Rails 5.1/Rails 4
reloader = defined?(ActiveSupport::Reloader) ? ActiveSupport::Reloader : ActionDispatch::Reloader
reloader.to_prepare do
require_dependency 'redmine_bots/telegram'

register_after_redmine_initialize_proc =
if Redmine::VERSION::MAJOR >= 5
Rails.application.config.public_method(:after_initialize)
else
reloader = defined?(ActiveSupport::Reloader) ? ActiveSupport::Reloader : ActionDispatch::Reloader
reloader.public_method(:to_prepare)
end
register_after_redmine_initialize_proc.call do
paths = '/lib/redmine_bots/telegram/{patches/*_patch,hooks/*_hook}.rb'

Dir.glob(File.dirname(__FILE__) + paths).each do |file|
Expand Down
2 changes: 1 addition & 1 deletion lib/redmine_bots/telegram/tdlib/authenticate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def call(params)
promise.then do |res|
result = res
condition.broadcast
end.on_error do |err|
end.rescue do |err|
error = err
condition.broadcast
end
Expand Down

0 comments on commit b5e3668

Please sign in to comment.