Closed l0rn closed 5 years ago
I don't run a redmine server, so would have a hard time debugging efficiently; @TomaszKolek do you have time to help with this?
I had the same issue. Redmine version 3.4.5.stable Ruby version 2.4.1-p111 (2017-03-22) [x86_64-linux] Rails version 4.2.8
I'am not a ruby dev neither a Redmine one but i made this modification in the file app/views/settings/_redmine_zulip.html.erb
<p>
<%= content_tag(:label, l(:zulip_settings_label_email)) %>
<%= text_field_tag 'settings[zulip_email]', @settings['zulip_email'] %>
</p>
<p>
<%= content_tag(:label, l(:zulip_settings_label_api_key)) %>
<%= text_field_tag 'settings[zulip_api_key]', @settings['zulip_api_key'] %>
</p>
<p>
<%= content_tag(:label, l(:zulip_settings_label_stream)) %>
<%= text_field_tag 'settings[zulip_stream]', @settings['zulip_stream'] %>
</p>
<p>
<%= content_tag(:label, l(:zulip_settings_label_server)) %>
<%= text_field_tag 'settings[zulip_server]', @settings['zulip_server'] %>
</p>
<p>
<%= content_tag(:label, l(:zulip_settings_label_port)) %>
<%= text_field_tag 'settings[zulip_port]', @settings['zulip_port'] %>
</p>
<p>
<%= content_tag(:label, l(:zulip_settings_label_projects)) %>
<%= select_tag 'settings[projects][]', project_tree_options_for_select(Project.active, :selected => Project.find_by_id(@settings['projects'])), :multiple => true, :size => Project.active.size %>
But it doesn't work for the selected project.
I had to change the lib/zulip_view_hooks.rb too. Again i'am not a ruby dev so don't judge me :rofl: With my setup Zulip url had to be 'hostname.domain.com' only no https, no /api ... It will work only with https zulip setup. Feel free to clean change my code :)
# encoding: utf-8
require 'json'
require "uri"
class NotificationHook < Redmine::Hook::Listener
# We generate Zulips for creating and updating issues.
def controller_issues_new_after_save(context = {})
issue = context[:issue]
project = issue.project
if !configured(project)
# Fail silently: the rest of the app needs to continue working.
return true
end
content = %Q{%s opened [issue %d: %s](%s) in %s
~~~ quote
%s
~~~
**Priority**: %s
**Status**: %s
**Assigned to**: %s} % [User.current.name, issue.id, issue.subject, url(issue),
project.name, issue.description, issue.priority.to_s,
issue.status.to_s, issue.assigned_to.to_s]
send_zulip_message(content, project)
end
def controller_issues_edit_after_save(context = {})
issue = context[:issue]
project = issue.project
if !configured(project)
# Fail silently: the rest of the app needs to continue working.
return true
end
content = %Q{%s updated [issue %d: %s](%s) in %s
~~~ quote
%s
~~~} % [User.current.name, issue.id, issue.subject, url(issue),
project.name, issue.notes]
send_zulip_message(content, project)
end
private
def configured(project)
# The plugin can be configured as a system setting or per-project.
if !project.zulip_email.empty? && !project.zulip_api_key.empty? &&
!project.zulip_stream.empty? && Setting.plugin_redmine_zulip['projects'] &&
Setting.plugin_redmine_zulip['zulip_server']
# We have full per-project settings.
return true
elsif Setting.plugin_redmine_zulip['projects'] &&
Setting.plugin_redmine_zulip['zulip_email'] &&
Setting.plugin_redmine_zulip['zulip_api_key'] &&
Setting.plugin_redmine_zulip['zulip_stream'] &&
Setting.plugin_redmine_zulip['zulip_server']
# We have full global settings.
return true
end
Rails.logger.info "Missing config, can't sent to Zulip!"
return false
end
def zulip_email(project)
if !project.zulip_email.empty?
return project.zulip_email
end
return Setting.plugin_redmine_zulip['zulip_email']
end
def zulip_api_key(project)
if !project.zulip_api_key.empty?
return project.zulip_api_key
end
return Setting.plugin_redmine_zulip['zulip_api_key']
end
def zulip_stream(project)
if !project.zulip_stream.empty?
return project.zulip_stream
end
return Setting.plugin_redmine_zulip['zulip_stream']
end
def zulip_server()
return Setting.plugin_redmine_zulip['zulip_server']
end
def zulip_port()
if Setting.plugin_redmine_zulip['zulip_port']
return Setting.plugin_redmine_zulip['zulip_port']
end
return 443
end
def url(issue)
return "#{Setting[:protocol]}://#{Setting[:host_name]}/issues/#{issue.id}"
end
def send_zulip_message(content, project)
data = {"to" => zulip_stream(project),
"type" => "stream",
"subject" => project.name,
"content" => content}
Rails.logger.info "Forwarding to Zulip: #{data['content']}"
new_uri = "https://" + Setting.plugin_redmine_zulip['zulip_server'] + "/api/v1/messages"
uri = URI.parse(new_uri)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
req = Net::HTTP::Post.new(uri.request_uri)
req.basic_auth zulip_email(project), zulip_api_key(project)
req.add_field('User-Agent', 'ZulipRedmine/0.1')
req.set_form_data(data)
begin
http.request(req)
rescue Net::HTTPBadResponse => e
Rails.logger.error "Error while POSTing to Zulip: #{e}"
end
end
end
This was fixed in the recent set of PRs merged, I think #11.
I followed this https://zulipchat.com/integrations/doc/redmine closely
But no updates are sent to my zulip instance.
Redmine Version:
Environment: Redmine version 3.4.2.stable Ruby version 2.3.3-p222 (2016-11-21) [x86_64-linux-gnu] Rails version 4.2.8 Environment production Database adapter PostgreSQL SCM: Git 2.11.0 Filesystem Redmine plugins: a_common_libs 2.4.0 redmine_agile 1.4.5 redmine_bootstrap_kit 0.2.4 redmine_people 1.3.1 redmine_scheduling_poll 3.0.0 redmine_zulip 0.91 rm_user_mentions 1.0.2
Zulip 1.8.0 on a private docker setup.
I noticed when I put in all the required information on the /settings/plugin/redmine_zulip page the input fields are blank after submitting - is this normal?
Attached images of what I put in the configuration page.![bildschirmfoto vom 2018-04-19 12-28-34](https://user-images.githubusercontent.com/5889030/38986666-66d605d6-43cd-11e8-8c3e-99541d12b7ae.png)