Skip to content

Commit 2325ba7

Browse files
author
root
committed
Small changes in Redmine post_receive hook
1 parent 6110f05 commit 2325ba7

File tree

1 file changed

+48
-35
lines changed

1 file changed

+48
-35
lines changed

Diff for: contrib/hooks/post-receive.redmine_gitolite.rb

+48-35
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ def logger(message, debug_only = false, with_newline = true)
2121

2222

2323
def load_gitolite_vars
24-
redmine_vars_hash = {}
24+
git_config = {}
2525

26-
redmine_var_names = [
26+
redmine_vars = [
2727
"redminegitolite.redmineurl",
2828
"redminegitolite.projectid",
2929
"redminegitolite.repositoryid",
@@ -32,7 +32,7 @@ def load_gitolite_vars
3232
"redminegitolite.asyncmode",
3333
]
3434

35-
redmine_var_names.each do |var_name|
35+
redmine_vars.each do |var_name|
3636
var_value = get_gitolite_config(var_name)
3737

3838
if var_value.to_s == ""
@@ -45,39 +45,45 @@ def load_gitolite_vars
4545
end
4646
else
4747
var_name = var_name.gsub(/^.*\./, "")
48-
redmine_vars_hash[var_name] = var_value
48+
git_config[var_name] = var_value
4949
end
5050
end
5151

52-
return redmine_vars_hash
52+
return git_config
5353
end
5454

5555

56-
def get_gitolite_config(varname)
57-
(%x[git config #{varname}]).chomp.strip
56+
def get_gitolite_config(var_name)
57+
(%x[git config #{var_name}]).chomp.strip
5858
end
5959

6060

61-
def run_http_query(params)
62-
params = get_http_params(params)
61+
def run_http_query(git_config)
62+
logger("", false, true)
63+
64+
if git_config.has_key?('repositoryid')
65+
repo_name = "#{git_config['projectid']}/#{git_config['repositoryid']}"
66+
else
67+
repo_name = "#{git_config['projectid']}"
68+
end
69+
70+
logger("Notifying Redmine about changes to this repository : '#{repo_name}' ...", false, true)
6371

6472
# pass projectid directly in the url
65-
url_str = "#{params['redmineurl']}/#{params['projectid']}"
73+
string_url = "#{git_config['redmineurl']}/#{git_config['projectid']}"
74+
75+
logger("Redmine URL : '#{string_url}'", true, true)
6676

67-
# remove useless params
68-
params = params.tap{|x| x.delete('redmineurl')}
69-
params = params.tap{|x| x.delete('projectid')}
70-
params = params.tap{|x| x.delete('debugmode')}
71-
params = params.tap{|x| x.delete('asyncmode')}
77+
params = get_http_params(git_config)
7278

73-
url = URI(url_str)
79+
url = URI(string_url)
7480
http = Net::HTTP.new(url.host, url.port)
7581
http.open_timeout = 5
7682
http.read_timeout = 10
7783

7884
if url.scheme == 'https'
7985
http.use_ssl = true
80-
http.ssl_version = :SSLv3 if http.respond_to? :ssl_version
86+
http.ssl_version = :SSLv3 if http.respond_to?(:ssl_version)
8187
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
8288
end
8389

@@ -106,17 +112,28 @@ def run_http_query(params)
106112
end
107113

108114

109-
def get_http_params(redmine_vars_hash)
115+
def get_http_params(git_config)
116+
ignore_list = [
117+
"redmineurl",
118+
"projectid",
119+
"debugmode",
120+
"asyncmode",
121+
"repositorykey"
122+
]
123+
110124
clear_time = Time.new.utc.to_i.to_s
111-
params = {}
112-
params["clear_time"] = clear_time
113-
params["encoded_time"] = Digest::SHA1.hexdigest(clear_time.to_s + redmine_vars_hash["repositorykey"])
114-
redmine_vars_hash.each_key do |key|
115-
if key != "repositorykey"
116-
params[key] = redmine_vars_hash[key]
125+
126+
new_git_config = {}
127+
new_git_config["clear_time"] = clear_time
128+
new_git_config["encoded_time"] = Digest::SHA1.hexdigest(clear_time.to_s + git_config["repositorykey"])
129+
130+
git_config.each_key do |key|
131+
if !ignore_list.include?(key)
132+
new_git_config[key] = git_config[key]
117133
end
118134
end
119-
return params
135+
136+
return new_git_config
120137
end
121138

122139

@@ -220,10 +237,10 @@ def call_extra_hooks(extra_hooks, stdin)
220237
$debug = false
221238

222239
## Load Gitolite config variables
223-
redmine_vars_hash = load_gitolite_vars
240+
git_config = load_gitolite_vars
224241

225242
## Set debug mode if needed
226-
$debug = redmine_vars_hash["debugmode"] == "true"
243+
$debug = git_config["debugmode"] == "true"
227244

228245
## Let's read the refs passed to us, but also copy stdin
229246
## for potential use with extra hooks.
@@ -236,10 +253,10 @@ def call_extra_hooks(extra_hooks, stdin)
236253
end
237254

238255
## Set refs
239-
redmine_vars_hash["refs[]"] = refs
256+
git_config["refs[]"] = refs
240257

241258
## Fork if needed
242-
if redmine_vars_hash["asyncmode"] == "true"
259+
if git_config["asyncmode"] == "true"
243260
pid = fork
244261
exit unless pid.nil?
245262
pid = fork
@@ -252,12 +269,8 @@ def call_extra_hooks(extra_hooks, stdin)
252269
STDERR.reopen STDOUT
253270
end
254271

255-
## Do the job!
256-
logger("", false, true)
257-
logger("Notifying Redmine project '#{redmine_vars_hash['projectid']}' about changes to this repo...", false, true)
258-
259-
## Call Redmine
260-
success = run_http_query(redmine_vars_hash)
272+
## Do the job, call Redmine
273+
success = run_http_query(git_config)
261274

262275
if !success
263276
logger("Error contacting Redmine about changes to this repo.", false, true)

0 commit comments

Comments
 (0)