This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
git_hooks [2017/10/19 08:40] – admin | git_hooks [2017/12/20 01:46] – admin | ||
---|---|---|---|
Line 4: | Line 4: | ||
This is a hook i use along with Gitlab. Its global and will be triggerd for all repositories when data ist send to the server. | This is a hook i use along with Gitlab. Its global and will be triggerd for all repositories when data ist send to the server. | ||
- | For Gitlab Omnibus installations place ' | + | For Gitlab Omnibus installations place '' |
- | / | + | '' |
- | Make sure the file ist executable using 'chmod +x pre-receive' | + | Make sure the file ist executable using ''chmod +x pre-receive'' |
- | < | + | < |
- | #!/bin/sh | + | #!/ |
+ | # Fix the PATH so that gitlab-shell can find git-upload-pack and friends. | ||
+ | ENV[' | ||
- | read oldrev newrev refname wusel | + | require ' |
+ | require ' | ||
+ | require ' | ||
- | merges=`git log --oneline --merges | + | ################### |
+ | # General variables | ||
+ | ################### | ||
+ | refs = $stdin.read | ||
+ | key_id = ENV.delete(' | ||
+ | proto = $stdin | ||
+ | protocol = ENV.delete(' | ||
+ | repo_path = Dir.pwd | ||
+ | gl_repository = ENV[' | ||
- | readarray -t COMMIT <<< | + | # Read given hashes |
+ | hash = refs.split(' | ||
+ | hash_from = hash[0] | ||
+ | hash_to = hash[1] | ||
+ | @branch = hash[2] | ||
- | if [ -z " | + | puts @branch |
- | # IF ARRAY EMPTY | + | |
- | # echo ">>>>>" | + | |
- | exit 0 | + | |
- | else | + | |
- | # IF MERGE EXISTS | + | |
- | for i in " | + | |
- | do | + | |
- | REGEX_MERGE_DEVELOP="\bMerge.*?.branch.*?.develop\b" | + | ################# |
+ | # Colorize output | ||
+ | ################# | ||
+ | class String | ||
+ | def red; | ||
+ | def green; | ||
+ | def blue; " | ||
+ | end | ||
+ | |||
+ | ########################## | ||
+ | # Pull a Chuck Norris Joke | ||
+ | ########################## | ||
+ | def get_joke(author = '' | ||
+ | begin | ||
+ | plain_uri = ' | ||
+ | url = URI.parse(plain_uri) | ||
+ | req = Net:: | ||
| | ||
- | | + | |
- | | + | http.request(req) |
- | | + | } |
- | echo -e " | + | joke = CGI.unescapeHTML(JSON.parse(res.body)[' |
- | echo -e " | + | |
- | echo -e "Please do not merge ' | + | rescue StandardError |
- | echo -e "Review | + | joke = "Chuck Norris never sleeps? Well, even Chuck Norris needs a power nap every once in a while ..." |
- | echo -e "" | + | end |
- | + | ||
- | | + | return joke |
- | | + | end |
- | echo -e " | + | |
- | | + | # Get changed files between hashes - check if commits contain file named ' |
- | + | changed_files = `git diff --name-only --stat # | |
- | echo -e "" | + | do_not_merge = changed_files.split(/ |
- | | + | |
- | + | puts changed_files | |
- | exit 1 | + | |
- | | + | ################################################## |
- | exit 0 | + | # Check if this is the .do_not_merge__ORIGIN Branch |
- | fi | + | ################################################## |
- | | + | def is_not_origin_branch(origin_branch) |
- | fi | + | current_branch = @branch.split(/ |
- | </ | + | origin_branch = origin_branch.split(/ |
+ | return current_branch != origin_branch | ||
+ | end | ||
+ | |||
+ | ###################################### | ||
+ | # Decide whether to ban or not to ban | ||
+ | ###################################### | ||
+ | do_not_merge.each do |file| | ||
+ | if (file[/ | ||
+ | | ||
+ | | ||
+ | puts get_joke().blue | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | exit 1 | ||
+ | | ||
+ | | ||
+ | end |