Skip to content

Instantly share code, notes, and snippets.

@mu88
Last active August 2, 2022 08:33
Show Gist options
  • Save mu88/3468d460d52455021284a6317a9f1f83 to your computer and use it in GitHub Desktop.
Save mu88/3468d460d52455021284a6317a9f1f83 to your computer and use it in GitHub Desktop.
Git hook for Conventional Commits
[includeIf "gitdir:C:/source/GitHub/"]
path = .gitconfig-github
[core]
hooksPath = C:/source/GitHub/config/hooks
#!/bin/sh
pwsh -noprofile C:/source/GitHub/config/hooks/Git_EnsureConventionalCommitMessage.ps1 $1
# 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
@mu88
Copy link
Author

mu88 commented Aug 2, 2022

See this blog post for detailed instructions on how to setup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment