Actions
Here's a list of all CaptainHook's built-in Actions.
- Commit message validation with the Beams rules
- Commit message validation with regex
- Inject issue key from branch name
- Write invalid commit message to a file
- Load commit message from file
- Git commit message notifications
- Block secrets from being committed
- Check file size
- Prevent committing empty files
- Prevent committing specific content to files
- Enforce branch naming
- Block pushing of squash or fixup commits
Commit-Message validation
Enforce Chris Beams commit message rules
Make sure your commit message complies to the following rules.
- Subject line starts with an upper-case character
- Subject line doesn't exceed 50 characters
- Subject line doesn't end with a period
- Subject line and body are separated by a blank line
- Body lines don't exceed 72 characters
- Use imperative mood
{
"run": "CaptainHook::Message.MustFollowBeamsRules"
}
Commit message regex validation
Use a regex to validate your commit messages.
{
"run": "CaptainHook::Message.ContainsRegex",
"options": {
"regex": ".*"
}
}
Write invalid commit message to file
Writes the invalid commit message to a file. This way it can be loaded for the next commit attempt, and you don't have to type the whole message again. Instead, you can just fix the errors and proceed.
{
"run": "CaptainHook::Message.CacheOnFail",
"options": {
"file": ".git/CH_MSG.temp"
}
}
Commit-Message preparation
-
Commit without providing a message
Then the editor will load with your prepared commit message to edit. -
Commit with providing a message
This way the commit message will be whatever you prepare. So you have to use the provided message and combine it with your "preparation" otherwise you will just overwrite the message.
Inject issue key into your commit message
Extracts an issue key from the current branch name and appends or prepends it to your commit messages subject or body. If the commit message already contains the key nothing is added. If you set the force option to true it will fail if no issue key can be extracted.
{
"action": "CaptainHook::Message.InjectIssueKeyFromBranch",
"options": {
"regex": "#([A-Z]+\\-[0-9]+)#i",
"into": "body",
"mode": "append",
"prefix": "\n\nIssue: ",
"force": false
}
}
Load commit message from file
Load a commit message from a file for example if you wrote an invalid commit message to a file in a previous commit attempt.
{
"action": "CaptainHook::Message.PrepareFromFile",
"options": {
"file": ".git/CH_MSG.temp"
}
}
Pre-Commit / Pre-Push
Block secrets from being committed to the repository
You can use presets provided by CaptainHook or define your own blocked patterns. You can define an allow list of accepted secrets to allow certain secrets to be committed.
{
"run": "CaptainHook::File.BlockSecrets",
"options: {
"presets": ["Aws", "GitHub", "Stripe", "Google"],
"blocked": ["pattern1", "pattern2"],
"allowed": ["patternA"]
}
}
Check if files are too big
Make sure you do not commit files that are bigger than a configured size limit.
Use 'B', 'K' or 'M' as size indication.
{
"run": "CaptainHook::File.MaxSize",
"options": {
"max-size": "5M"
}
}
Check if a file is not empty
Make sure you do not commit empty files to the repository. With this configuration you can make sure that README files are not committed without any contents.
{
"run": "CaptainHook\::File.IsNotEmpty",
"options": {
"files": [
"README.md",
"src/Modules/**/README.md"
]
}
}
Check if a file does not contain certain text
Make sure you do not commit specific contents to a list of file types.
{
"run": "CaptainHook::File.DoesNotContainRegex",
"options": {
"regex": "os.exit"
"regexName": "debug output"
"fileExtensions": [
"go"
]
}
}
Enforce branch naming rules
Make sure branch names match a configured regex.
{
"run": "CaptainHook::Branch.EnsureNaming",
"options": {
"regex": "master|integration|feature/[a-z]+-[0-9]+"
}
}
Block pushing of !fixup or !squash commits
Preparing !fixup or !squash commits for smooth rebasing is very handy. But you may not want to push those commits to the main branch. If you don't provide any protected branches push fixup and squash commits is generally prohibited.
{
"run": "CaptainHook::Branch.BlockFixupAndSquashCommits",
"options": {
"protected-branches": ["main", "master"]
}
}
Post-Merge, Post-Rewrite, Post-Checkout
Display notifications if you merge or checkout commits with notifications
Inspired by: git-notify from Jani Eväkallio
Update dev tooling git-notify: WARNING Please update your dev tooling
{
"run": "CaptainHook::Notify.GitNotify",
"options": {
"prefix": "git-notify:"
}
}