Skip to content
Browse files

Render changelog for issue update events.

  • Loading branch information...
1 parent 426a27d commit 98695f187c84e679867c1b3b4923d5e7b3d3f284 @mutru mutru committed
Showing with 34 additions and 3 deletions.
  1. +1 −0 init.rb
  2. +6 −3 lib/flowdock_listener.rb
  3. +27 −0 lib/flowdock_renderer.rb
View
1 init.rb
@@ -1,4 +1,5 @@
require 'redmine'
+require_dependency 'flowdock_renderer'
require_dependency 'flowdock_listener'
Redmine::Plugin.register :flowdock do
View
9 lib/flowdock_listener.rb
@@ -2,6 +2,8 @@ class FlowdockListener < Redmine::Hook::Listener
INTEGRATION_SOURCE = 'Redmine'
FLOWDOCK_API_HOST = 'api.flowdock.com'
+ @@renderer = FlowdockRenderer.new
+
def controller_issues_new_after_save(context = {})
set_data(context[:issue])
@@ -15,8 +17,9 @@ def controller_issues_edit_after_save(context = {})
set_data(context[:issue])
subject = "Updated \"#{@issue.subject}\" (#{@tracker})"
+ body = @@renderer.notes_to_html(context[:journal]) + @@renderer.details_to_html(context[:journal])
- send_message!(subject)
+ send_message!(subject, body)
end
def controller_wiki_edit_after_save(context = {})
@@ -24,7 +27,7 @@ def controller_wiki_edit_after_save(context = {})
subject = "Updated \"#{@page.pretty_title}\" (Wiki)"
- send_message!(subject)
+ send_message!(subject, "XXX")
end
protected
@@ -56,7 +59,7 @@ def set_data(object)
@project_name = @project.name
end
- def send_message!(subject, body = "XXX")
+ def send_message!(subject, body)
token = api_token
return unless token
View
27 lib/flowdock_renderer.rb
@@ -0,0 +1,27 @@
+class FlowdockRenderer
+ include Redmine::I18n
+ include IssuesHelper
+
+ def notes_to_html(journal)
+ if journal && journal.notes
+ "<p>#{journal.notes}</p>"
+ else
+ ""
+ end
+ end
+
+ def details_to_html(journal)
+ if journal && journal.details && journal.details.size > 0
+ html_list = journal_details(journal.details).map { |detail| "<li>#{detail}</li>" }
+ "<ul>#{html_list.join}</ul>"
+ else
+ ""
+ end
+ end
+
+ protected
+
+ def journal_details(details)
+ details_to_strings(details, true)
+ end
+end

0 comments on commit 98695f1

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