def is_good_message()

in hghooks/mozhghooks/commit-message.py [0:0]


def is_good_message(ui, c):
    def message(fmt):
        formatted_fmt = fmt % {b"rev": c.hex()[:12]}
        ui.write(
            b"\n\n"
            b"************************** ERROR ****************************\n"
            b"%s\n%s\n%s\n"
            b"*************************************************************\n"
            b"\n\n" % (formatted_fmt, c.user(), c.description())
        )

    desc = c.description()
    firstline = desc.splitlines()[0]

    # Ensure backout commit descriptions are well formed.
    if commitparser.is_backout(desc):
        try:
            if not commitparser.parse_backouts(desc, strict=True):
                raise ValueError("Rev %(rev)s has malformed backout message.")
            nodes, bugs = commitparser.parse_backouts(desc, strict=True)
            if not nodes:
                raise ValueError("Rev %(rev)s is missing backed out revisions.")
        except ValueError as e:
            # Reject invalid backout messages on vendored paths, warn otherwise.
            if is_vendor_ctx(c):
                message(pycompat.bytestr(e))
                return False
            ui.write(b"Warning: %s\n" % (pycompat.bytestr(e) % {b"rev": c.hex()[:12]}))

    # Vendored merges must reference source revisions.
    if b"Source-Revision: " in desc and is_vendor_ctx(c):
        ui.write(
            b"(%s looks like a vendoring change; ignoring commit message "
            b"hook)\n" % short(c.node())
        )
        return True

    if c.user() in [b"ffxbld", b"seabld", b"tbirdbld", b"cltbld"]:
        return True

    # Match against [PATCH] and [PATCH n/m]
    if b"[PATCH" in desc:
        message(
            b'Rev %(rev)s contains git-format-patch "[PATCH]" cruft. Use '
            b"git-format-patch -k to avoid this."
        )
        return False

    if INVALID_REVIEW_FLAG_RE.search(firstline):
        message(
            b"Rev %(rev)s contains 'r?' in the commit message. Please use "
            b"'r=' instead."
        )
        return False

    desc_lower = desc.lower()
    if desc_lower.startswith(b"wip:"):
        message(b"Rev %(rev)s seems to be marked as WIP.")
        return False

    for r in goodMessage:
        if r.search(firstline):
            return True

    if desc_lower.startswith((b"merge", b"merging", b"automated merge")):
        if len(c.parents()) == 2:
            return True
        else:
            message(
                b"Rev %(rev)s claims to be a merge, but it has only one parent."
            )
            return False

    if desc_lower.startswith((b"back", b"revert")):
        # Purposely ambiguous: it's ok to say "backed out rev N" or
        # "reverted to rev N-1"
        message(b"Backout rev %(rev)s needs a bug number or a rev id.")
    else:
        message(b'Rev %(rev)s needs "Bug N" or "No bug" in the commit message.')

    return False