Skip to content

Commit fb4f791

Browse files
committed
change conventional commit check to reflect angular conventions (NO_JIRA)
1 parent add2d87 commit fb4f791

1 file changed

Lines changed: 29 additions & 11 deletions

File tree

main/githooks.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -855,9 +855,12 @@ def check_commit_msg(message, files, repo):
855855
return 0
856856

857857

858-
# Check for Conventional Commits compliance
859-
if check_conventional_commit(message):
860-
return 1
858+
# Check for Conventional Commits compliance.
859+
# Opt-in per repo: commit an empty marker file named
860+
# `.conventional-commits` at the repo root.
861+
if _conventional_commits_enabled():
862+
if check_conventional_commit(message):
863+
return 1
861864

862865
if NO_JIRA_MARKER not in message:
863866
if jira_id_pattern.search(message) is None:
@@ -880,20 +883,35 @@ def check_commit_msg(message, files, repo):
880883

881884

882885

886+
def _conventional_commits_enabled():
887+
'''Return True if the repo opts in to Conventional Commits enforcement.
888+
889+
Opt-in is signalled by a `.conventional-commits` file at the repo root.
890+
'''
891+
try:
892+
repo_root = _get_output(['git', 'rev-parse', '--show-toplevel']).strip()
893+
except subprocess.CalledProcessError:
894+
return False
895+
return (Path(repo_root) / '.conventional-commits').is_file()
896+
897+
883898
def check_conventional_commit(message):
884-
'''Check if the commit message follows the Conventional Commits standard.'''
885-
# Conventional Commits: type(scope?): subject\n\nbody\n\nfooter
886-
# type: feat, fix, chore, docs, style, refactor, perf, test, build, ci, revert, etc.
899+
'''Check if the commit message follows the Angular Conventional Commits standard.'''
900+
# Angular Conventional Commits header: type(scope?)!?: subject
901+
# Allowed types from @commitlint/config-angular:
902+
# build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test
887903
pattern = re.compile(
888-
r'^(feat|fix|chore|docs|style|refactor|perf|test|build|ci|revert)' # type
889-
r'(\([\w\-]+\))?' # optional scope
890-
r'!?: ' # optional breaking change indicator and colon
904+
r'^(BREAKING CHANGE|feat|fix|refactor|build|chore|ci|docs|perf|revert|style|test)' # type
905+
r'(\([\w\-\.\/]+\))?' # optional scope
906+
r'!?: ' # optional breaking change indicator and required ": "
891907
r'.+' # subject
892908
)
893909
first_line = message.split('\n', 1)[0]
894910
if not pattern.match(first_line):
895-
_fail('Commit message does not follow Conventional Commits standard.\n'
896-
'See https://www.conventionalcommits.org/en/v1.0.0/')
911+
_fail('Commit message does not follow the Angular Conventional '
912+
'Commits standard.\n'
913+
'Expected: <type>(<scope>)?!?: <subject>\n'
914+
'See https://github.com/angular/angular/blob/main/contributing-docs/commit-message-guidelines.md')
897915
return 1
898916
return 0
899917

0 commit comments

Comments
 (0)