File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Pull Request Title
2+
3+ on :
4+ pull_request :
5+ types :
6+ - opened
7+ - edited
8+ - synchronize
9+ - reopened
10+
11+ permissions : {}
12+
13+ jobs :
14+ semantic-title :
15+ name : Validate semantic format
16+ runs-on : ubuntu-latest
17+ timeout-minutes : 2
18+ concurrency :
19+ group : pr-semantic-title-${{ github.event.pull_request.number }}
20+ cancel-in-progress : true
21+
22+ steps :
23+ - shell : python
24+ env :
25+ PR_TITLE : ${{ github.event.pull_request.title }}
26+ PR_VALID_TYPES : |
27+ feat
28+ fix
29+ refactor
30+ docs
31+ test
32+ build
33+ ci
34+ chore
35+ run : |
36+ import os
37+ import re
38+ import sys
39+
40+ pr_title = os.environ.get("PR_TITLE", "").strip()
41+ if not pr_title:
42+ print("ERROR: PR_TITLE environment variable is missing or empty.", file=sys.stderr)
43+ sys.exit(1)
44+
45+ pr_valid_types = [
46+ valid_type for raw_type in os.environ.get("PR_VALID_TYPES", "").splitlines()
47+ if (valid_type := raw_type.strip()) and not valid_type.startswith("#")
48+ ]
49+ if not pr_valid_types:
50+ print("ERROR: PR_VALID_TYPES environment variable is missing or empty.", file=sys.stderr)
51+ sys.exit(1)
52+
53+ title_pattern = re.compile(
54+ r"^(?P<type>[A-Za-z0-9_-]+)(?:\((?P<scope>[A-Za-z0-9_.\-/]+)\))?(?P<breaking>!)?:\s(?P<subject>\S.*)$"
55+ )
56+ matches = title_pattern.fullmatch(pr_title)
57+ if not matches:
58+ print("ERROR: Pull request title format is invalid.", file=sys.stderr)
59+ print("Expected format: <type>(<optional-scope>)<optional-!>: <subject>", file=sys.stderr)
60+ sys.exit(1)
61+
62+ pr_type = matches.group("type")
63+ if pr_type not in pr_valid_types:
64+ print("ERROR: Pull request semantic type is invalid.", file=sys.stderr)
65+ print(f"Expected one of: {', '.join(pr_valid_types)}", file=sys.stderr)
66+ sys.exit(1)
67+
68+ print("Pull request title is valid.")
69+ sys.exit(0)
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments