Skip to content
Browse files

Initial commit

  • Loading branch information...
0 parents commit 6ff2872e77b9319e24b565558251b141eb383be2 @mironov mironov committed May 5, 2010
Showing with 111 additions and 0 deletions.
  1. +17 −0 README.markdown
  2. +12 −0 app/views/settings/_jaconda_settings.html.erb
  3. +4 −0 config/locales/en.yml
  4. +16 −0 init.rb
  5. +2 −0 lang/en.yml
  6. +55 −0 lib/notifier_hook.rb
  7. +5 −0 test/test_helper.rb
17 README.markdown
@@ -0,0 +1,17 @@
+# Jaconda Notifications Plugin for Redmine
+
+This plugin is intended to provide basic integration with [Jaconda](http://jaconda.im).
+Following actions will result in notifications to your Jaconda room:
+
+- Create and update issues
+- Create and reply to messages
+- Update wiki articles
+
+## Installation & Configuration
+
+- The Jaconda Notifications Plugin depends on the [official ruby wrapper](http://github.com/mironov/jaconda-api) for Jaconda API. This can be installed with:
+ $ sudo gem install jaconda
+- 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 numerical room id and api token.
+- Restart your Redmine web servers (e.g. mongrel, thin, mod_rails).
12 app/views/settings/_jaconda_settings.html.erb
@@ -0,0 +1,12 @@
+<fieldset>
+<legend><%= l(:jaconda_label_settings) %></legend>
+
+<p>
+ <label><%= l(:jaconda_label_room_id) %></label><%= text_field_tag 'settings[room_id]', @settings['room_id'] %>
+</p>
+
+<p>
+ <label><%= l(:jaconda_label_api_token) %></label><%= text_field_tag 'settings[api_token]', @settings['api_token'] %>
+</p>
+
+</fieldset>
4 config/locales/en.yml
@@ -0,0 +1,4 @@
+en:
+ jaconda_label_settings: Jaconda configuration settings
+ jaconda_label_room_id: Numerical Room ID
+ jaconda_label_api_token: API token
16 init.rb
@@ -0,0 +1,16 @@
+require 'redmine'
+
+RAILS_DEFAULT_LOGGER.info 'Starting Jaconda Notifications Plugin for Redmine'
+
+require 'jaconda'
+require_dependency 'notifier_hook'
+
+Redmine::Plugin.register :redmine_jaconda_notifications do
+ name 'Redmine Jaconda Notifications plugin'
+ author 'Anton Mironov'
+ description 'A plugin to display Redmine activity on Jaconda'
+ version '0.0.1'
+ url 'http://github.com/mironov/redmine_jaconda_notifications'
+
+ settings :default => {'room_id' => '', 'api_token' => ''}, :partial => 'settings/jaconda_settings'
+end
2 lang/en.yml
@@ -0,0 +1,2 @@
+# English strings go here
+my_label: "My label"
55 lib/notifier_hook.rb
@@ -0,0 +1,55 @@
+class NotifierHook < Redmine::Hook::Listener
+
+ def controller_issues_new_after_save(context = { })
+ redmine_url = "#{Setting[:protocol]}://#{Setting[:host_name]}"
+ project = context[:project]
+ issue = context[:issue]
+ user = issue.author
+ deliver "#{user.firstname} created issue “#{issue.subject}”. Comment: “#{truncate_words(issue.description)}#{redmine_url}/issues/#{issue.id}"
+ end
+
+ def controller_issues_edit_after_save(context = { })
+ redmine_url = "#{Setting[:protocol]}://#{Setting[:host_name]}"
+ project = context[:project]
+ issue = context[:issue]
+ journal = context[:journal]
+ user = journal.user
+ deliver "#{user.firstname} edited issue “#{issue.subject}”. Comment: “#{truncate_words(journal.notes)}”. #{redmine_url}/issues/#{issue.id}"
+ end
+
+ def controller_messages_new_after_save(context = { })
+ redmine_url = "#{Setting[:protocol]}://#{Setting[:host_name]}"
+ project = context[:project]
+ message = context[:message]
+ user = message.author
+ deliver "#{user.firstname} wrote a new message “#{message.subject}” on #{project.name}: “#{truncate_words(message.content)}”. #{redmine_url}/boards/#{message.board.id}/topics/#{message.root.id}#message-#{message.id}"
+ end
+
+ def controller_messages_reply_after_save(context = { })
+ redmine_url = "#{Setting[:protocol]}://#{Setting[:host_name]}"
+ project = context[:project]
+ message = context[:message]
+ user = message.author
+ deliver "#{user.firstname} replied a message “#{message.subject}” on #{project.name}: “#{truncate_words(message.content)}”. #{redmine_url}/boards/#{message.board.id}/topics/#{message.root.id}#message-#{message.id}"
+ end
+
+ def controller_wiki_edit_after_save(context = { })
+ redmine_url = "#{Setting[:protocol]}://#{Setting[:host_name]}"
+ project = context[:project]
+ page = context[:page]
+ user = page.content.author
+ deliver "#{user.firstname} edited the wiki “#{page.pretty_title}” on #{project.name}. #{redmine_url}/projects/#{project.identifier}/wiki/#{page.title}"
+ end
+
+private
+ def deliver(message)
+ Jaconda::API.authenticate(Setting.plugin_redmine_jaconda_notifications[:api_token])
+ Jaconda::Message.create(:room_id => Setting.plugin_redmine_jaconda_notifications[:room_id], :text => message)
+ end
+
+ def truncate_words(text, length = 20, end_string = '')
+ return if text == nil
+ words = text.split()
+ words[0..(length-1)].join(' ') + (words.length > length ? end_string : '')
+ end
+end
5 test/test_helper.rb
@@ -0,0 +1,5 @@
+# Load the normal Rails helper
+require File.expand_path(File.dirname(__FILE__) + '/../../../../test/test_helper')
+
+# Ensure that we are using the temporary fixture path
+Engines::Testing.set_fixture_path

0 comments on commit 6ff2872

Please sign in to comment.
Something went wrong with that request. Please try again.