@@ -21,9 +21,9 @@ def logger(message, debug_only = false, with_newline = true)
21
21
22
22
23
23
def load_gitolite_vars
24
- redmine_vars_hash = { }
24
+ git_config = { }
25
25
26
- redmine_var_names = [
26
+ redmine_vars = [
27
27
"redminegitolite.redmineurl" ,
28
28
"redminegitolite.projectid" ,
29
29
"redminegitolite.repositoryid" ,
@@ -32,7 +32,7 @@ def load_gitolite_vars
32
32
"redminegitolite.asyncmode" ,
33
33
]
34
34
35
- redmine_var_names . each do |var_name |
35
+ redmine_vars . each do |var_name |
36
36
var_value = get_gitolite_config ( var_name )
37
37
38
38
if var_value . to_s == ""
@@ -45,39 +45,45 @@ def load_gitolite_vars
45
45
end
46
46
else
47
47
var_name = var_name . gsub ( /^.*\. / , "" )
48
- redmine_vars_hash [ var_name ] = var_value
48
+ git_config [ var_name ] = var_value
49
49
end
50
50
end
51
51
52
- return redmine_vars_hash
52
+ return git_config
53
53
end
54
54
55
55
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
58
58
end
59
59
60
60
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 )
63
71
64
72
# 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 )
66
76
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 )
72
78
73
- url = URI ( url_str )
79
+ url = URI ( string_url )
74
80
http = Net ::HTTP . new ( url . host , url . port )
75
81
http . open_timeout = 5
76
82
http . read_timeout = 10
77
83
78
84
if url . scheme == 'https'
79
85
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 )
81
87
http . verify_mode = OpenSSL ::SSL ::VERIFY_NONE
82
88
end
83
89
@@ -106,17 +112,28 @@ def run_http_query(params)
106
112
end
107
113
108
114
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
+
110
124
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 ]
117
133
end
118
134
end
119
- return params
135
+
136
+ return new_git_config
120
137
end
121
138
122
139
@@ -220,10 +237,10 @@ def call_extra_hooks(extra_hooks, stdin)
220
237
$debug = false
221
238
222
239
## Load Gitolite config variables
223
- redmine_vars_hash = load_gitolite_vars
240
+ git_config = load_gitolite_vars
224
241
225
242
## Set debug mode if needed
226
- $debug = redmine_vars_hash [ "debugmode" ] == "true"
243
+ $debug = git_config [ "debugmode" ] == "true"
227
244
228
245
## Let's read the refs passed to us, but also copy stdin
229
246
## for potential use with extra hooks.
@@ -236,10 +253,10 @@ def call_extra_hooks(extra_hooks, stdin)
236
253
end
237
254
238
255
## Set refs
239
- redmine_vars_hash [ "refs[]" ] = refs
256
+ git_config [ "refs[]" ] = refs
240
257
241
258
## Fork if needed
242
- if redmine_vars_hash [ "asyncmode" ] == "true"
259
+ if git_config [ "asyncmode" ] == "true"
243
260
pid = fork
244
261
exit unless pid . nil?
245
262
pid = fork
@@ -252,12 +269,8 @@ def call_extra_hooks(extra_hooks, stdin)
252
269
STDERR . reopen STDOUT
253
270
end
254
271
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 )
261
274
262
275
if !success
263
276
logger ( "Error contacting Redmine about changes to this repo." , false , true )
0 commit comments