RC
This commit is contained in:
parent
1fe8045b31
commit
9780e5c2e8
15
README.md
Normal file
15
README.md
Normal file
@ -0,0 +1,15 @@
|
||||
# RabbitMQ Plugin for Redmine
|
||||
|
||||
This plugin is intended to provide basic integration with RabbitMQ , by sending notifications of updates to issues to a RabbitMQ.
|
||||
|
||||
Following actions will result in notifications to Jabber:
|
||||
|
||||
- Create and update issues
|
||||
|
||||
## Installation & Configuration
|
||||
|
||||
- The RabbitMQ Notifications Plugin depends on the [bunny](https://github.com/ruby-amqp/bunny). This can be installed with: $ gem install bunny
|
||||
- Then install the Plugin following the general Redmine [plugin installation instructions](http://www.redmine.org/wiki/redmine/Plugins).
|
||||
- Go to the Plugins section of the Administration page, select Configure.
|
||||
- On this page fill out the Jabber ID and password for user who will sends messages, and the MUC room where to send messages to.
|
||||
- Restart your Redmine web servers (e.g. mongrel, thin, mod_rails).
|
@ -1 +0,0 @@
|
||||
storage/docker_redmine-plugins/rabbitmq/README.rdoc
|
3
README.rdoc
Normal file
3
README.rdoc
Normal file
@ -0,0 +1,3 @@
|
||||
= rabbitmq
|
||||
|
||||
Description goes here
|
27
app/views/settings/_rabbitmq_settings.html.erb
Normal file
27
app/views/settings/_rabbitmq_settings.html.erb
Normal file
@ -0,0 +1,27 @@
|
||||
<fieldset>
|
||||
<legend><%= l(:rabbitmq_label_settings) %></legend>
|
||||
<p>
|
||||
<label><%= l(:rabbitmq_label_username) %></label>
|
||||
<%= text_field_tag "settings[username]", @settings["username"] %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label><%= l(:rabbitmq_label_password) %></label>
|
||||
<%= password_field_tag "settings[password]", @settings["password"] %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label><%= l(:rabbitmq_label_exchange) %></label>
|
||||
<%= text_field_tag "settings[exchange]", @settings["exchange"] %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label><%= l(:rabbitmq_label_server) %></label>
|
||||
<%= text_field_tag "settings[server]", @settings["server"] %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label><%= l(:rabbitmq_label_port) %></label>
|
||||
<%= number_field_tag "settings[port]", @settings["port"] %>
|
||||
</p>
|
||||
</fieldset>
|
8
config/locales/en.yml
Normal file
8
config/locales/en.yml
Normal file
@ -0,0 +1,8 @@
|
||||
# English strings go here for Rails i18n
|
||||
en:
|
||||
rabbitmq_label_settings: RabbitMQ Notifications settings
|
||||
rabbitmq_label_username: RabbitMQ username
|
||||
rabbitmq_label_password: Password
|
||||
rabbitmq_label_exchange: Exchange
|
||||
rabbitmq_label_server: Server
|
||||
rabbitmq_label_port: Port
|
8
config/locales/ru.yml
Normal file
8
config/locales/ru.yml
Normal file
@ -0,0 +1,8 @@
|
||||
# Russian strings go here for Rails i18n
|
||||
en:
|
||||
rabbitmq_label_settings: RabbitMQ Настройки
|
||||
rabbitmq_label_username: RabbitMQ имя пользователя
|
||||
rabbitmq_label_password: Пароль
|
||||
rabbitmq_label_exchange: Канал обмена
|
||||
rabbitmq_label_server: Сервер
|
||||
rabbitmq_label_port: Порт
|
2
config/routes.rb
Normal file
2
config/routes.rb
Normal file
@ -0,0 +1,2 @@
|
||||
# Plugin's routes
|
||||
# See: http://guides.rubyonrails.org/routing.html
|
18
init.rb
Normal file
18
init.rb
Normal file
@ -0,0 +1,18 @@
|
||||
require 'bunny'
|
||||
require_dependency "notifier_hook"
|
||||
|
||||
Redmine::Plugin.register :rabbitmq do
|
||||
name 'Rabbitmq plugin'
|
||||
author 'Василий Казьмин'
|
||||
description 'This is a plugin for Redmine'
|
||||
version '0.0.1'
|
||||
url 'http://example.com/path/to/plugin'
|
||||
author_url 'http://example.com/about'
|
||||
settings :default => {
|
||||
"username" => "guest",
|
||||
"password" => "guest",
|
||||
"exchange" => "redmine",
|
||||
"server" => "rabbitmq",
|
||||
"port" => 5672
|
||||
}, :partial => "settings/rabbitmq_settings"
|
||||
end
|
68
lib/notifier_hook.rb
Normal file
68
lib/notifier_hook.rb
Normal file
@ -0,0 +1,68 @@
|
||||
class NotifierHook < Redmine::Hook::Listener
|
||||
def controller_issues_new_after_save(context = {})
|
||||
deliver(make_msg(context[:issue]), make_key("issue", context[:issue].project.id, "new")) unless !validate_settings?
|
||||
end
|
||||
|
||||
def controller_issues_edit_after_save(context = {})
|
||||
deliver(make_msg(context[:issue]), make_key("issue", context[:issue].project.id, "update")) unless !validate_settings?
|
||||
if context[:time_entry]
|
||||
deliver(make_msg(context[:time_entry]), make_key("time_entry", context[:time_entry].issue.project.id, "update")) unless !validate_settings?
|
||||
end
|
||||
end
|
||||
|
||||
def controller_timelog_edit_before_save(context = {})
|
||||
deliver(make_msg(context[:time_entry]), make_key("time_entry", context[:time_entry].issue.project.id, "update")) unless !validate_settings?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def logger
|
||||
config.logger
|
||||
end
|
||||
|
||||
def notify_error(e)
|
||||
logger.error "RabbitMQ Hook error => exception #{e.class.name} : #{e.message}"
|
||||
flash[:error] = "Exception caught while delivering notification to RabbitMQ channel"
|
||||
end
|
||||
|
||||
def settings
|
||||
@settings ||= Setting.plugin_rabbitmq
|
||||
end
|
||||
|
||||
def validate_settings?
|
||||
settings["username"].present? && settings["password"].present? && settings["exchange"].present? && settings["server"].present? && settings["port"].present?
|
||||
end
|
||||
|
||||
def make_msg(issue)
|
||||
message = issue.to_json
|
||||
return message
|
||||
end
|
||||
|
||||
def make_key(object, project, event)
|
||||
message = "redmine.#{project}.#{object}.#{event}"
|
||||
return message
|
||||
end
|
||||
|
||||
def make_exchange()
|
||||
connection = Bunny.new(:host => settings["server"],
|
||||
:port => settings["port"],
|
||||
:user => settings["username"],
|
||||
:pass => settings["password"])
|
||||
connection.start
|
||||
channel = connection.create_channel
|
||||
exchange = channel.fanout(settings["exchange"])
|
||||
yield exchange
|
||||
ensure
|
||||
connection.close
|
||||
end
|
||||
|
||||
def deliver(message, key)
|
||||
make_exchange do |exchange|
|
||||
exchange.publish(
|
||||
message,
|
||||
:routing_key => key,
|
||||
:content_type => "application/json",
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
2
test/test_helper.rb
Normal file
2
test/test_helper.rb
Normal file
@ -0,0 +1,2 @@
|
||||
# Load the Redmine helper
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper')
|
Loading…
x
Reference in New Issue
Block a user