54
54
PROXY_PROPERTY = 'proxy'
55
55
COMMANDS_PROPERTY = 'commands'
56
56
DISABLED_PROPERTY = 'disabled'
57
+ DISABLED_REASON_PROPERTY = 'disabled-reason'
57
58
HOOKDIR_PROPERTY = 'hookdir'
58
59
HOOKS_PROPERTY = 'hooks'
59
60
LOGDIR_PROPERTY = 'logdir'
@@ -304,14 +305,27 @@ def run_command(cmd, project_name):
304
305
cmd .getoutputstr ()))
305
306
306
307
307
- def handle_disabled_project (config , project_name ):
308
+ def handle_disabled_project (config , project_name , disabled_msg ):
308
309
disabled_command = config .get (DISABLED_CMD_PROPERTY )
309
310
if disabled_command :
310
311
logger = logging .getLogger (__name__ )
311
312
312
313
logger .debug ("Calling disabled command: {}" .format (disabled_command ))
313
314
command_args = disabled_command .get (COMMAND_PROPERTY )
314
- if is_web_uri (command_args [0 ]):
315
+ uri = command_args [0 ]
316
+ if is_web_uri (uri ):
317
+ # Is this perhaps OpenGrok API call to supply a Message ?
318
+ # If so and there was a string supplied, append it
319
+ # to the message text.
320
+ data = command_args [2 ]
321
+ text = None
322
+ if type (data ) is dict :
323
+ text = data .get ("text" )
324
+ if text and uri .find ("/api/v1/" ) > 0 and type (disabled_msg ) is str :
325
+ logger .debug ("Appending text to message: {}" .
326
+ format (disabled_msg ))
327
+ command_args [2 ]["text" ] = text + ": " + disabled_msg
328
+
315
329
r = call_rest_api (disabled_command , PROJECT_SUBST , project_name )
316
330
try :
317
331
r .raise_for_status ()
@@ -320,11 +334,15 @@ def handle_disabled_project(config, project_name):
320
334
"project '{}': {}" .
321
335
format (project_name , r ))
322
336
else :
337
+ args = [project_name ]
338
+ if disabled_msg and type (disabled_msg ) is str :
339
+ args .append (disabled_command )
340
+
323
341
cmd = Command (command_args ,
324
342
env_vars = disabled_command .get ("env" ),
325
343
resource_limits = disabled_command .get ("limits" ),
326
344
args_subst = {PROJECT_SUBST : project_name },
327
- args_append = [ project_name ] , excl_subst = True )
345
+ args_append = args , excl_subst = True )
328
346
run_command (cmd , project_name )
329
347
330
348
@@ -363,7 +381,9 @@ def mirror_project(config, project_name, check_changes, uri,
363
381
# We want this to be logged to the log file (if any).
364
382
if project_config :
365
383
if project_config .get (DISABLED_PROPERTY ):
366
- handle_disabled_project (config , project_name )
384
+ handle_disabled_project (config , project_name ,
385
+ project_config .
386
+ get (DISABLED_REASON_PROPERTY ))
367
387
logger .info ("Project '{}' disabled, exiting" .
368
388
format (project_name ))
369
389
return CONTINUE_EXITVAL
@@ -429,7 +449,8 @@ def check_project_configuration(multiple_project_config, hookdir=False,
429
449
# Quick sanity check.
430
450
known_project_tunables = [DISABLED_PROPERTY , CMD_TIMEOUT_PROPERTY ,
431
451
HOOK_TIMEOUT_PROPERTY , PROXY_PROPERTY ,
432
- IGNORED_REPOS_PROPERTY , HOOKS_PROPERTY ]
452
+ IGNORED_REPOS_PROPERTY , HOOKS_PROPERTY ,
453
+ DISABLED_REASON_PROPERTY ]
433
454
434
455
if not multiple_project_config :
435
456
return True
0 commit comments