@naverpay/commithelper-go
v1.3.1
Published
A CLI tool to assist with commit messages based on branch names and configuration.
Downloads
174
Maintainers
Keywords
Readme
@naverpay/commithelper-go
A Go-based CLI tool to assist your commit messages based on husky commit-msg hook.
Performance Comparison with @naverpay/commit-helper
@naverpay/commithelper-go is a Go-based rewrite of @naverpay/commit-helper with significant performance improvements:
- ⚡ Speed: 5-6x faster execution compared to Node.js version
- 📦 Memory: Lower memory footprint due to compiled binary
- 🚀 Startup: Instant startup time vs Node.js runtime initialization
- 🔧 Dependencies: Zero runtime dependencies after installation
Installation
npm install @naverpay/commithelper-goOr install globally:
npm install -g @naverpay/commithelper-goHow to use
.husky/commit-msg
node node_modules/@naverpay/commithelper-go/bin/cli.js "$1"
@latestis not necessary but this option always provides latest version of commithelper-go.
.lefthook.yml
commit-msg:
commands:
commithelper:
run: node node_modules/@naverpay/commithelper-go/bin/cli.js {1}[!TIP]
npxadds ~460ms of overhead even when the package is installed locally. Callingnode cli.jsdirectly takes ~76ms — about 6x faster thannpx. For hooks that run on every commit, directnodeinvocation is recommended.
What it does
Tag related issue
Automatically Add your related github issue number at your commit message through your branch name
➜ your-repo git:(feature/1) git add . && git commit -m ":memo: test"
ℹ No staged files match any configured task.
$ git branch --show-current
feature/1
[feature/1 1e70c244f] [#1] :memo: test
1 file changed, 1 insertion(+)Your issue number is automatically tagged based on your setting (.commithelperrc.json)
Blocking commit
- Blocks direct commit toward
main,developmasterbranch by throwing error on commit attempt. - To block specific branches, add at
protectfield oncommithelperrc.
Configuration
commithelperrc
This is Basic rule of .commithelperrc.json.
{
"protect": ["main", "master", "develop"],
"rules": {
"feature": null,
"qa": "your-org/your-repo"
}
}rules
- Key of rules field means branch prefix. By
featurekey, this rule is applied to branches named using thefeature/***pattern. - Value represents the repository to be tagged. For example, rule with value 'your-org/your-repo' tags 'your-org/your-repo#1'.
- A rule with a
nullvalue tags repository itself.
protect
- Defines branches that are blocked from committing. Supports glob-style wildcard patterns.
*matches any sequence of characters except/?matches any single character except/[...]matches any character in the set- Note:
*does not match across/, sorelease/*matchesrelease/1.0but notrelease/1.0/hotfix. Userelease/*/*for nested branches.
{
"protect": ["main", "master", "develop", "release/*", "epic/*"]
}template
- Defines a custom format for commit messages using Go template syntax.
- If not specified, uses the default format:
[{{.Prefix}}] {{.Message}} - Available template variables:
{{.Message}}: Original commit message{{.Number}}: Issue number extracted from branch name{{.Repo}}: Repository name (empty string if not specified in rules){{.Prefix}}: Full prefix (#123ororg/repo#123)
Template Examples
Example 1: Add issue reference at the end
{
"rules": {
"feature": null
},
"template": "{{.Message}}\n\nRef. [#{{.Number}}]"
}Result:
:memo: Update documentation
Ref. [#123]Example 2: Custom format with repository
{
"rules": {
"qa": "your-org/your-repo"
},
"template": "{{.Message}}\n\nSee: {{.Prefix}}"
}Result:
:bug: Fix login bug
See: your-org/your-repo#456Example 3: Conditional formatting
{
"rules": {
"feature": null
},
"template": "[{{.Prefix}}] {{.Message}}"
}Result:
[#123] :sparkles: Add new featureExample
// .commithelperrc.json
{
"protect": ["epic"],
"rules": {
"feature": null,
"qa": "your-org/your-repo"
}
}For example as above,
- commit on
feature/1branch will be tagged as[#1].- commit on
qa/1branch will be tagged as[your-org/your-repo#1].- direct commit attempt toward
main,master,develop,epic/*branch will be blocked
Platform Support
The appropriate platform-specific binary package is automatically installed via optionalDependencies.
- macOS: Intel (x64) and Apple Silicon (arm64)
- Linux: x64
- Windows: x64
Q&A
- What happens if commit has already tagged issue like
[your-org/your-repo#1]?commithelper-godo not works. Already tagged issue remains unchanged
- How does commithelper-go behaves on
feature/1_xxxfeature/1-xxxpatterned branch name?- It works same as
feature/1branch.
- It works same as
- What's the difference between
@naverpay/commit-helperand@naverpay/commithelper-go?commithelper-gois a Go-based rewrite with significantly better performance and lower resource usage.
License
MIT
