Last active
August 2, 2022 08:33
-
-
Save mu88/3468d460d52455021284a6317a9f1f83 to your computer and use it in GitHub Desktop.
Git hook for Conventional Commits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[includeIf "gitdir:C:/source/GitHub/"] | |
path = .gitconfig-github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[core] | |
hooksPath = C:/source/GitHub/config/hooks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
pwsh -noprofile C:/source/GitHub/config/hooks/Git_EnsureConventionalCommitMessage.ps1 $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The commit message has to be loaded from a Git-internal file | |
$commitMessage = Get-Content $args[0] | |
# Attention: contains a filter for Jira! | |
$conventionalCommitRegex = "(?-i)^(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert|BREAKING CHANGE)!?(\([\w\-]+\))?:\s(\w{3}-\d{4})?\s?[a-z]{1}.*" | |
# Without Jira filter: | |
# $conventionalCommitRegex = "(?-i)^(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert|BREAKING CHANGE)!?(\([\w\-]+\))?:\s[a-z]{1}.*" | |
$nuKeeperRegex = "(?-i)^:package: [A-Z].*" | |
if ($commitMessage -match $conventionalCommitRegex) { | |
exit 0 | |
} | |
if ($commitMessage -match $nuKeeperRegex) { | |
exit 0 | |
} | |
Write-Host "The commit message does not match the Conventional Commit rules" | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See this blog post for detailed instructions on how to setup