pre-commit-hooks/pre_commit_hooks/loaderon-hooks/general_hooks/check_branch_name.py
Alvaro Andrés Rodríguez Scelza 0a66e6635d Added loaderon-hooks logic
2019-06-02 02:10:25 -03:00

25 lines
847 B
Python

# -*- coding: utf-8 -*-
import re
from pre_commit_logic.util.template_methods.checker_template_method import CheckerTemplateMethod
from pre_commit_logic.util.git_helpers import get_current_branch_name
class BranchNameChecker(CheckerTemplateMethod):
def _add_arguments_to_parser(self):
self.parser.add_argument('-r', '--regex', help='Regex that git current branch must match.')
def _perform_checks(self):
regular_expression = self.args.regex
pattern = re.compile(regular_expression)
current_branch_name = get_current_branch_name()
if not pattern.match(current_branch_name):
self.inform_check_failure('El nombre de la rama debe ser del estilo {}'.format(regular_expression))
def main(argv=None):
return BranchNameChecker(argv).run()
if __name__ == '__main__':
exit(main())