Skip to content

Commit

Permalink
Add Slack notification when wiki pages are updated
Browse files Browse the repository at this point in the history
Closes #44
  • Loading branch information
kayo_tozaki authored and sciyoshi committed Feb 27, 2016
1 parent 5992e7c commit 5b6ffe0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/views/settings/_slack_settings.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,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>
23 changes: 23 additions & 0 deletions lib/redmine_slack/listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,29 @@ def model_changeset_scan_commit_for_issue_ids_pre_issue_update(context={})
speak msg, channel, attachment, url
end

def controller_wiki_edit_after_save(context = { })
return unless Setting.plugin_redmine_slack[: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_slack[:slack_url] if not url
username = Setting.plugin_redmine_slack[:username]
Expand Down

0 comments on commit 5b6ffe0

Please sign in to comment.