Created
February 20, 2021 19:02
-
-
Save Allanfs/0108bdb726585ee033d201838fdf8b83 to your computer and use it in GitHub Desktop.
Hook para adicionar informação na mensagem do commit
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/python3.8 | |
import sys, re | |
from subprocess import check_output | |
commit_msg_filepath = sys.argv[1] | |
branch = check_output(['git', 'symbolic-ref', '--short', 'HEAD']).strip() | |
regex = rb'[0-9]+$' | |
if re.search(regex, branch): | |
issue = str(re.findall(regex, branch)[0], 'utf-8') | |
with open(commit_msg_filepath, 'r+') as fh: | |
commit_msg = fh.read() | |
fh.seek(0, 0) | |
fh.write('%s\n[%s]' % (commit_msg, issue)) # ID no final da msg do commit | |
# fh.write('[%s] %s' % (issue, commit_msg)) # ID no começo da msg do commit | |
elif branch != 'master' and branch != 'dev': | |
print('Branch protegida:', str(branch, 'utf-8')) | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
O hook acima é ideal para branches no padrão que terminam com números. Exemplo:
c_teste_de_hook_12345
Algumas informações a mais:
git init
incluir hooks predefinidos no repositório