其他分享
首页 > 其他分享> > gitlab配置webhook限制提交注释

gitlab配置webhook限制提交注释

作者:互联网

一、打开gitlab相关配置项

vim /etc/gitlab/gitlab.rb

gitlab_shell['custom_hooks_dir'] = "/etc/gitlab/custom_hooks"

 

二、创建相关文件夹

mkdir -p /etc/gitlab/custom_hooks

mkdir -p /etc/gitlab/custom_hooks/post-receive.d

mkdir -p /etc/gitlab/custom_hooks/pre-receive.d

mkdir -p /etc/gitlab/custom_hooks/update.d

 

#将相关脚本放入对应目录

参考文档:https://docs.gitlab.com/ee/administration/server_hooks.html

https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks#Server-Side-Hooks

 

#!/usr/bin/env  python3
import sys
import re
import subprocess
#import redis
refname = sys.argv[1]
oldrev  = sys.argv[2]
newrev  = sys.argv[3]



regex='([a-zA-Z0-9]+-\\d+)\\,\\s+.{10,}'


def check_message_format():
	cmd='git rev-list '+oldrev+'..'+newrev
	print(cmd)
	p = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
	l= p.stdout.readlines()
	for rev in l:
		cmdsub="git cat-file commit "+rev.decode().strip('''\n''')+"  | sed '1,/^$/d'"
		p1 = subprocess.Popen(cmdsub,shell=True,stdout=subprocess.PIPE)
		l1 = p1.stdout.readline()
		print(l1)
		result = re.match('([a-zA-Z0-9]+-\\d+)\\,\\s+.{10,}',l1.decode())
		if result == None:
			 print("your commit msg should like : TEST-123,  fix the wrong caution")
			 sys.exit(1)
	sys.exit(0) 
check_message_format()

 

三、使配置生效

gitlab-ctl reconfigure

标签:sys,hooks,gitlab,webhook,custom,注释,etc,subprocess
来源: https://www.cnblogs.com/breeze-24/p/15919224.html