From 0dd8f50592a2b3032e043bc1e2e8aab4c9fc1ae0 Mon Sep 17 00:00:00 2001 From: Thanos Kyritsis Date: Sat, 13 Feb 2016 14:26:02 +0200 Subject: [PATCH] borrow code from redmine's mailer.rb in order to proper detect sub-uri conditions (refs #4) --- lib/redmine_mattermost/listener.rb | 40 ++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/lib/redmine_mattermost/listener.rb b/lib/redmine_mattermost/listener.rb index a4164f2..a8f92ef 100644 --- a/lib/redmine_mattermost/listener.rb +++ b/lib/redmine_mattermost/listener.rb @@ -71,15 +71,30 @@ class MattermostListener < Redmine::Hook::Listener repository = changeset.repository - 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 =~ /\A(https?\:\/\/)?(.+?)(\:(\d+))?(\/.+)?\z/i + host, port, prefix = $2, $4, $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}|#{escape changeset.comments}>") @@ -127,7 +142,12 @@ private end def object_url(obj) - Rails.application.routes.url_for(obj.event_url({:host => Setting.host_name, :protocol => Setting.protocol})) + if Setting.host_name.to_s =~ /\A(https?\:\/\/)?(.+?)(\:(\d+))?(\/.+)?\z/i + host, port, prefix = $2, $4, $5 + Rails.application.routes.url_for(obj.event_url({:host => host, :protocol => Setting.protocol, :port => port, :script_name => prefix})) + else + Rails.application.routes.url_for(obj.event_url({:host => Setting.host_name, :protocol => Setting.protocol})) + end end def url_for_project(proj)