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)