Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

elicec/gitlab-custom-hooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

7 Commits

Repository files navigation

gitlab-custom-hooks

gitlab custom hooks writted in python

put pre-receive in to dir bleow.and change the permission to git

/var/opt/gitlab/git-data/repositories/root/testapp.git/custom_hooks

#!/usr/bin/env python
import re
import sys
import subprocess
CREDBG = '33円[41m'
CEND = '33円[0m'
CRED = '33円[91m'
CGREEN = '33円[92m'
def isPushTag(msg):
 return 'refs/tags' in msg
def git(args):
	args = ['git'] + args
	git = subprocess.Popen(args, stdout = subprocess.PIPE)
	details = git.stdout.read()
	details = details.decode('utf-8','replace').strip()
	return details
def getCommitMsg(old, new):
 out = git(['log', old+'..'+new, '--pretty=format:%s'])
 return out
def isAutoMsg(msg):
 pat = re.compile(r'^(?:Merge|Rvert)')
 return pat.match(msg)
#TODO check content in []
def verifyCommitMsgs(msgs):
 match = None
 pat = re.compile(r'^\[.{0,16}\]\[.*\]\[.*\]')#[test][test][test]
 for msg in msgs:
 if isAutoMsg(msg):# Merge or Revert msg
 continue
 match = pat.match(msg)
 if not match:
 print(CREDBG + msg + ' [ERROR format!!]' + CEND)
 return False
 else:
 continue
 return True
def main():
 print(CGREEN + 'Start Verify Commit Message' + CEND)
 (old, new, branch) = sys.stdin.read().split()
 print("old:"+old)
 print("new:"+new)
 print("branch:"+branch)
 if isPushTag(branch):
 print("is a tag")
 sys.exit(0)#success exit
 com_msg = getCommitMsg(old, new).split()
 result = verifyCommitMsgs(com_msg)
 if result:
 print(CGREEN + 'Verify Commit Message success' + CEND)
 sys.exit(0)
 else:
 sys.exit(1)
if __name__ == '__main__':
 main()

About

gitlab custom hooks writted in python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /