Skip to content

Commit c1a2a39

Browse files
author
root
committed
Store mailer config in Global Git config, not the repo one
1 parent 1ac5668 commit c1a2a39

File tree

4 files changed

+62
-40
lines changed

4 files changed

+62
-40
lines changed

Diff for: app/services/git_notifier.rb

+1-26
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,16 @@ class GitNotifier
77
attr_reader :default_list
88
attr_reader :mail_mapping
99

10-
attr_reader :mailer
11-
attr_reader :smtp_auth
12-
attr_reader :smtp_server
13-
attr_reader :smtp_port
14-
attr_reader :smtp_user
15-
attr_reader :smtp_pass
16-
1710

1811
def initialize(repository)
1912
@repository = repository
2013
@project = repository.project
14+
2115
@email_prefix = ''
2216
@sender_address = ''
2317
@default_list = []
2418
@mail_mapping = {}
2519

26-
if ActionMailer::Base.delivery_method == :smtp
27-
@mailer = 'smtp'
28-
else
29-
@mailer = 'sendmail'
30-
end
31-
32-
@smtp_auth =
33-
if ActionMailer::Base.smtp_settings.has_key?(:authentication) &&
34-
ActionMailer::Base.smtp_settings[:authentication] != :none
35-
true
36-
else
37-
false
38-
end
39-
40-
@smtp_server = ActionMailer::Base.smtp_settings[:address]
41-
@smtp_port = ActionMailer::Base.smtp_settings[:port]
42-
@smtp_user = ActionMailer::Base.smtp_settings[:user_name]
43-
@smtp_pass = ActionMailer::Base.smtp_settings[:password]
44-
4520
build_notifier
4621
end
4722

Diff for: app/views/settings/_gitolite_config_test.html.erb

+12
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@
6060
</td>
6161
</tr>
6262

63+
<tr>
64+
<td><%= l(:label_gitolite_mailer_params_installed) %></td>
65+
<td>
66+
<% params_installed = hooks_manager.mailer_params_installed? %>
67+
<% params_installed.each do |param, installed| %>
68+
<%= image_tag((installed ? 'true.png' : 'exclamation.png'), :style => "vertical-align: bottom;") %>
69+
<em><%= param %></em>
70+
<br />
71+
<% end %>
72+
</td>
73+
</tr>
74+
6375
<tr>
6476
<td><%= l(:label_mirroring_keys_installed) %></td>
6577
<td><%= image_tag (RedmineGitolite::GitoliteWrapper.mirroring_keys_installed?(:reset => true) ? 'true.png' : 'exclamation.png') %></td>

Diff for: lib/redmine_gitolite/gitolite_wrapper/repositories_helper.rb

-12
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,9 @@ def set_mail_settings(repository, repo_conf)
120120

121121
if repository.extra[:git_notify] && !notifier.mailing_list.empty?
122122
repo_conf.set_git_config("multimailhook.enabled", 'true')
123-
repo_conf.set_git_config("multimailhook.environment", "gitolite")
124-
125123
repo_conf.set_git_config("multimailhook.mailinglist", notifier.mailing_list.join(", "))
126124
repo_conf.set_git_config("multimailhook.from", notifier.sender_address)
127125
repo_conf.set_git_config("multimailhook.emailPrefix", notifier.email_prefix)
128-
repo_conf.set_git_config("multimailhook.mailer", notifier.mailer)
129-
130-
# Set SMTP server for mail-notifications hook
131-
if notifier.mailer == 'smtp'
132-
repo_conf.set_git_config("multimailhook.smtpAuth", notifier.smtp_auth.to_s)
133-
repo_conf.set_git_config("multimailhook.smtpServer", notifier.smtp_server)
134-
repo_conf.set_git_config("multimailhook.smtpPort", notifier.smtp_port)
135-
repo_conf.set_git_config("multimailhook.smtpUser", notifier.smtp_user)
136-
repo_conf.set_git_config("multimailhook.smtpPass", notifier.smtp_pass)
137-
end
138126
else
139127
repo_conf.set_git_config("multimailhook.enabled", 'false')
140128
end

Diff for: lib/redmine_gitolite/hooks.rb

+49-2
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ def initialize
2929
@gitolite_hooks_dir = File.join('$HOME', '.gitolite', 'hooks', 'common')
3030
@post_receive_hook_dir = File.join(@gitolite_hooks_dir, 'post-receive.d')
3131

32-
@global_hook_params = get_git_config_params(GITOLITE_HOOKS_NAMESPACE)
32+
@global_hook_params = get_git_config_params(GITOLITE_HOOKS_NAMESPACE)
33+
@multimailhook_params = get_git_config_params('multimailhook')
34+
3335
@gitolite_hooks_namespace = GITOLITE_HOOKS_NAMESPACE
3436
end
3537

3638

3739
def check_install
38-
return [ hooks_installed?, hook_params_installed? ]
40+
return [ hooks_installed?, hook_params_installed?, mailer_params_installed? ]
3941
end
4042

4143

@@ -77,6 +79,23 @@ def hook_params_installed?
7779
end
7880

7981

82+
def mailer_params_installed?
83+
params = %w(mailer environment smtpAuth smtpServer smtpPort smtpUser smtpPass)
84+
current_params = get_mailer_params
85+
installed = {}
86+
87+
params.each do |param|
88+
if @multimailhook_params[param] != current_params[param]
89+
installed[param] = set_git_config_param(param, current_params[param].to_s, "multimailhook")
90+
else
91+
installed[param] = true
92+
end
93+
end
94+
95+
return installed
96+
end
97+
98+
8099
private
81100

82101

@@ -85,6 +104,34 @@ def logger
85104
end
86105

87106

107+
def get_mailer_params
108+
params = {}
109+
110+
params['environment'] = 'gitolite'
111+
112+
if ActionMailer::Base.delivery_method == :smtp
113+
params['mailer'] = 'smtp'
114+
else
115+
params['mailer'] = 'sendmail'
116+
end
117+
118+
auth = ActionMailer::Base.smtp_settings[:authentication]
119+
120+
if auth != nil && auth != '' && auth != :none
121+
params['smtpAuth'] = true
122+
else
123+
params['smtpAuth'] = false
124+
end
125+
126+
params['smtpServer'] = ActionMailer::Base.smtp_settings[:address]
127+
params['smtpPort'] = ActionMailer::Base.smtp_settings[:port]
128+
params['smtpUser'] = ActionMailer::Base.smtp_settings[:user_name] || ''
129+
params['smtpPass'] = ActionMailer::Base.smtp_settings[:password] || ''
130+
131+
params
132+
end
133+
134+
88135
###############################
89136
## ##
90137
## HOOKS DIR ##

0 commit comments

Comments
 (0)