Elffuss BraidHub

kikocis/kleidiai public

main · 1.2 KiBRawPermalink
1#!/usr/bin/env python3
2#
3# SPDX-FileCopyrightText: Copyright 2026 Arm Limited and/or its affiliates <open-source-office@arm.com>
4#
5# SPDX-License-Identifier: Apache-2.0
6#
7"""
8Check that the merge request title is valid for use as a squash/merge commit message.
9"""
10import os
11import re
12import sys
13
14ALLOWED_TYPES = "major, feat, fix, docs, chore"
15TITLE_RE = re.compile(r"^(?:major|feat|fix|docs|chore): \S(?:.*\S)?$")
16
17
18def main() -> int:
19 assert (
20 "CI_MERGE_REQUEST_TITLE" in os.environ
21 ), "CI_MERGE_REQUEST_TITLE environment variable is not set."
22 title = os.environ["CI_MERGE_REQUEST_TITLE"]
23
24 if os.environ["CI_MERGE_REQUEST_DRAFT"] == "true":
25 print("Merge request squash-commit validation skipped for draft merge request.")
26 raise SystemExit(0)
27
28 if not TITLE_RE.fullmatch(title.strip()):
29 print("Merge request squash-commit validation failed:")
30 print("- Merge request title must match '<type>: <description>'.")
31 print(f"- Allowed types: {ALLOWED_TYPES}.")
32 print(f"- Received title: {title!r}")
33 raise SystemExit(1)
34
35 print("Merge request squash-commit validation passed.")
36 return 0
37
38
39if __name__ == "__main__":
40 sys.exit(main())