Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d1c844c4c | ||
|
|
42ff187547 | ||
|
|
3271493126 | ||
|
|
e001232b23 | ||
|
|
b3e8f3a6e4 | ||
|
|
4719dec85a | ||
|
|
6a3c5c7694 | ||
|
|
a5cecdb814 | ||
|
|
7eef353849 | ||
|
|
0dd8f50592 |
@@ -3,7 +3,7 @@
|
||||
This plugin posts updates to issues in your Redmine installation to a Mattermost
|
||||
channel.
|
||||
|
||||
Redmine Supported versions: 2.0.x - 3.1.x (3.2.x is not yet tested but should work).
|
||||
Redmine Supported versions: 2.0.x - 3.2.x.
|
||||
|
||||
## Screenshot
|
||||
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The URL can be changed on a per-project basis by creating a
|
||||
<a href="/custom_fields/new?type=ProjectCustomField">project custom field</a> named "Mattermost URL" (without quotes).
|
||||
Generate an "Incoming WebHook" URL from the <a href="http://docs.mattermost.com/developer/webhooks-incoming.html">Integrations configuration page on Mattermost</a>. This URL can be changed on a per-project basis by creating a <a href="/custom_fields/new?type=ProjectCustomField">project custom field</a> named "Mattermost URL" (without quotes).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
@@ -40,3 +39,8 @@
|
||||
<label for="settings_post_updates">Post Issue Updates?</label>
|
||||
<input type="checkbox" id="settings_post_updates" value="1" name="settings[post_updates]" <%= settings['post_updates'] == '1' ? 'checked="checked"' : '' %> />
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="settings_post_wiki_updates">Post Wiki Updates?</label>
|
||||
<input type="checkbox" id="settings_post_wiki_updates" value="1" name="settings[post_wiki_updates]" <%= settings['post_wiki_updates'] == '1' ? 'checked="checked"' : '' %> />
|
||||
</p>
|
||||
|
||||
11
init.rb
11
init.rb
@@ -8,9 +8,9 @@ Redmine::Plugin.register :redmine_mattermost do
|
||||
url 'https://github.com/altsol/redmine_mattermost'
|
||||
author_url 'http://altsol.gr'
|
||||
description 'Mattermost chat integration'
|
||||
version '0.1'
|
||||
version '0.3'
|
||||
|
||||
requires_redmine :version_or_higher => '0.8.0'
|
||||
requires_redmine :version_or_higher => '2.0.0'
|
||||
|
||||
settings \
|
||||
:default => {
|
||||
@@ -22,3 +22,10 @@ Redmine::Plugin.register :redmine_mattermost do
|
||||
},
|
||||
:partial => 'settings/mattermost_settings'
|
||||
end
|
||||
|
||||
ActionDispatch::Callbacks.to_prepare do
|
||||
require_dependency 'issue'
|
||||
unless Issue.included_modules.include? RedmineMattermost::IssuePatch
|
||||
Issue.send(:include, RedmineMattermost::IssuePatch)
|
||||
end
|
||||
end
|
||||
|
||||
33
lib/redmine_mattermost/issue_patch.rb
Normal file
33
lib/redmine_mattermost/issue_patch.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
module RedmineMattermost
|
||||
module IssuePatch
|
||||
def self.included(base) # :nodoc:
|
||||
base.extend(ClassMethods)
|
||||
base.send(:include, InstanceMethods)
|
||||
|
||||
base.class_eval do
|
||||
unloadable # Send unloadable so it will not be unloaded in development
|
||||
after_create :create_from_issue
|
||||
after_save :save_from_issue
|
||||
end
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
def create_from_issue
|
||||
@create_already_fired = true
|
||||
Redmine::Hook.call_hook(:redmine_mattermost_issues_new_after_save, { :issue => self})
|
||||
return true
|
||||
end
|
||||
|
||||
def save_from_issue
|
||||
if not @create_already_fired
|
||||
Redmine::Hook.call_hook(:redmine_mattermost_issues_edit_after_save, { :issue => self, :journal => self.current_journal}) unless self.current_journal.nil?
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'httpclient'
|
||||
|
||||
class MattermostListener < Redmine::Hook::Listener
|
||||
def controller_issues_new_after_save(context={})
|
||||
def redmine_mattermost_issues_new_after_save(context={})
|
||||
issue = context[:issue]
|
||||
|
||||
channel = channel_for_project issue.project
|
||||
@@ -37,7 +37,7 @@ class MattermostListener < Redmine::Hook::Listener
|
||||
speak msg, channel, attachment, url
|
||||
end
|
||||
|
||||
def controller_issues_edit_after_save(context={})
|
||||
def redmine_mattermost_issues_edit_after_save(context={})
|
||||
issue = context[:issue]
|
||||
journal = context[:journal]
|
||||
|
||||
@@ -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}>")
|
||||
@@ -88,6 +103,29 @@ class MattermostListener < Redmine::Hook::Listener
|
||||
speak msg, channel, attachment, url
|
||||
end
|
||||
|
||||
def controller_wiki_edit_after_save(context = { })
|
||||
return unless Setting.plugin_redmine_mattermost[:post_wiki_updates] == '1'
|
||||
|
||||
project = context[:project]
|
||||
page = context[:page]
|
||||
|
||||
user = page.content.author
|
||||
project_url = "<#{object_url project}|#{escape project}>"
|
||||
page_url = "<#{object_url page}|#{page.title}>"
|
||||
comment = "[#{project_url}] #{page_url} updated by *#{user}*"
|
||||
|
||||
channel = channel_for_project project
|
||||
url = url_for_project project
|
||||
|
||||
attachment = nil
|
||||
if not page.content.comments.empty?
|
||||
attachment = {}
|
||||
attachment[:text] = "#{escape page.content.comments}"
|
||||
end
|
||||
|
||||
speak comment, channel, attachment, url
|
||||
end
|
||||
|
||||
def speak(msg, channel, attachment=nil, url=nil)
|
||||
url = Setting.plugin_redmine_mattermost[:mattermost_url] if not url
|
||||
username = Setting.plugin_redmine_mattermost[:username]
|
||||
@@ -127,7 +165,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)
|
||||
@@ -213,6 +256,7 @@ private
|
||||
end
|
||||
|
||||
def mentions text
|
||||
return nil if text.nil?
|
||||
names = extract_usernames text
|
||||
names.present? ? "\nTo: " + names.join(', ') : nil
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user