Skip to content

Add a global server pre-receive hook with customised error message

John McDonnell requested to merge jmd-add-global-server-hooks into master

What does this MR do and why?

Add support for testing Custom Error Messages on pre-receive hooks as part of gitlab#362666 (closed).
See: https://docs.gitlab.com/ee/administration/server_hooks.html#custom-error-messages

This hook will be triggered on any project containing the substring 'reject-prereceive' .

Screenshots or screen recordings

image

How to set up and validate locally

exe/gitlab-qa Test::Instance::Image CE --no-tests --no-server-hooks
exe/gitlab-qa Test::Instance::Image CE --no-tests

# Check for the existence of the executable script depending on flag `/opt/gitlab/embedded/service/gitlab-shell/hooks/pre-receive.d/pre-receive.d` in the gitlab container that is spun up. 
  • Create a project that has 'reject-prereceive' in the project path (note you won't be able to Initialize repository with a README as the commit is rejected)
  • Attempt to commit a file to project, and you'll see the Custom Error message rendered
  • If you create a project that doesn't include this string (or changes the project to a different path) you will be able to commit again

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by John McDonnell

Merge request reports