Created
August 17, 2018 17:15
-
-
Save avandrevitor/6a60b2bfef4d1dd9af2427965ac6a611 to your computer and use it in GitHub Desktop.
Git Hook Pre-Receive from https://rafpe.ninja/2017/02/11/gitlab-custom-pre-receive-hook/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
our_secret = "aaaa" | |
params = gets | |
oldref = params.split()[0] | |
newref = params.split()[1] | |
refname = params.split()[2] | |
changed_files = `git diff --no-commit-id --name-only #{oldref}..#{newref}` | |
if changed_files.include? '.gitlab-ci.yml' then | |
commit_messages = `git log --pretty=%s #{newref} | head -3`.split("\n") | |
unless commit_messages.include? our_secret | |
puts "================================================================= " | |
puts "██████╗ ███████╗ ██╗███████╗ ██████╗████████╗███████╗██████╗ " | |
puts "██╔══██╗██╔════╝ ██║██╔════╝██╔════╝╚══██╔══╝██╔════╝██╔══██╗ " | |
puts "██████╔╝█████╗ ██║█████╗ ██║ ██║ █████╗ ██║ ██║ " | |
puts "██╔══██╗██╔══╝ ██ ██║██╔══╝ ██║ ██║ ██╔══╝ ██║ ██║ " | |
puts "██║ ██║███████╗╚█████╔╝███████╗╚██████╗ ██║ ███████╗██████╔╝ " | |
puts "╚═╝ ╚═╝╚══════╝ ╚════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚══════╝╚═════╝ " | |
puts "================================================================= " | |
puts "" | |
puts " oldref is #{oldref}" | |
puts " newref is #{newref}" | |
puts " refname is #{refname}" | |
puts " " | |
puts " We are very very sorry but your change seems to violate our policies! " | |
puts " Please check with your nearest Guru! :) ERROR_ID: 001 " | |
puts "================================================================= " | |
exit 1 | |
end | |
end # if changed_files.include? | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment