<commit_before>#!/usr/local/bin/python3
"""
Git commit hook:
 .git/hooks/commit-msg
"""

import argparse
import re
import inspect
from enum import Enum


def main() -> None:
    parser = argparse.ArgumentParser(description="Git commit message checker",
                                     formatter_class=argparse.RawDescriptionHelpFormatter,
                                     epilog=CommitMsg.help())
    parser.add_argument("msg", help="the commit message to check")
    args = parser.parse_args()
    msg = args.msg
    if "COMMIT_EDITMSG" in msg:
        with open(args.msg) as msg_file:
            msg = msg_file.read()
    try:
        CommitMsg.parse(msg)
    except CommitSyntaxError:
        parser.error(CommitMsg.help())
        exit(1)
    exit(0)


class CommitSyntaxError(Exception):
    """
    Invalid commit syntax error
    """


class CommitType(Enum):
    feat = 'new feature for the user, not a new feature for build script'
    fix = 'bug fix for the user, not a fix to a build script'
    docs = 'changes to the documentation'
    style = 'formatting, missing semi colons, etc; no production code change'
    refactor = 'refactoring production code, eg.renaming a variable'
    test = 'adding missing tests, refactoring tests; no production code change'
    chore = 'updating gradle scripts, continuous integration scripts,  etc; no production code change'


class CommitMsg:
    """
    Commit message

    Your commit message have to follow this format:
    <type>(<scope>): <subject>

    <body>

    <footer>
    Where :
    Message first line (type, scope and subject)
        The first line cannot be longer than {firstline_max_length} characters.<commit_msg>feat(help): improve the help message when there is a format error<commit_after>#!/usr/local/bin/python3
"""
Git commit hook:
 .git/hooks/commit-msg
"""

import argparse
import re
import inspect
from enum import Enum


def main() -> None:
    parser = argparse.ArgumentParser(description="Git commit message checker",
                                     formatter_class=argparse.RawDescriptionHelpFormatter,
                                     epilog=CommitMsg.help())
    parser.add_argument("msg", help="the commit message to check")
    args = parser.parse_args()
    msg = args.msg
    if "COMMIT_EDITMSG" in msg:
        with open(args.msg) as msg_file:
            msg = msg_file.read()
    try:
        CommitMsg.parse(msg)
    except CommitSyntaxError as e:
        parser.error("{error}\n\n{help}".format(error=e, help=CommitMsg.help()))
        exit(1)
    exit(0)


class CommitSyntaxError(Exception):
    """
    Invalid commit syntax error
    """


class CommitType(Enum):
    feat = 'new feature for the user, not a new feature for build script'
    fix = 'bug fix for the user, not a fix to a build script'
    docs = 'changes to the documentation'
    style = 'formatting, missing semi colons, etc; no production code change'
    refactor = 'refactoring production code, eg.renaming a variable'
    test = 'adding missing tests, refactoring tests; no production code change'
    chore = 'updating gradle scripts, continuous integration scripts,  etc; no production code change'


class CommitMsg:
    """
    Your commit message have to follow this format:
    <type>(<scope>): <subject>

    <body>

    <footer>
    Where :
    Message first line (type, scope and subject)
        The first line cannot be longer than {firstline_max_length} characters.
{'fraction_non_alphanumeric': 0.09206349206349207, 'fraction_numerical': 0.0017316017316017316, 'mean_word_length': 2.8425720620842574, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6145933', 'n_tokens_mistral': 976, 'n_tokens_neox': 957, 'n_words': 338}