1
0
mirror of https://github.com/xiaoqidun/gitcz.git synced 2025-03-15 16:34:38 +08:00

11 Commits

4 changed files with 32 additions and 16 deletions

@ -1,20 +1,21 @@
kind: pipeline kind: pipeline
type: docker type: docker
name: default name: default
node:
region: cn
steps: steps:
- name: generate - name: generate
pull: if-not-exists pull: if-not-exists
image: hkccr.ccs.tencentyun.com/xiaoqidun/build image: ccr.ccs.tencentyun.com/xiaoqidun/build
commands: commands:
- build -f build.sh -i gitcz.go -o release/gitcz - build -f build.sh -i gitcz.go -o release/gitcz
- name: build - name: build
pull: if-not-exists pull: if-not-exists
image: hkccr.ccs.tencentyun.com/xiaoqidun/goenv image: ccr.ccs.tencentyun.com/xiaoqidun/goenv
commands: commands:
- ./build.sh - ./build.sh
- name: upload - name: upload
image: hkccr.ccs.tencentyun.com/xiaoqidun/gocos image: ccr.ccs.tencentyun.com/xiaoqidun/gocos
settings: settings:
secret_id: secret_id:
from_secret: cos_secret_id from_secret: cos_secret_id

@ -1,26 +1,38 @@
# gitcz # gitcz
Golang版本Git Commitizencommit规范工具
Golang 版本 Git Commitizencommit 规范工具
# 快速安装 # 快速安装
go install github.com/xiaoqidun/gitcz@latest go install github.com/xiaoqidun/gitcz@latest
# 编译安装 # 编译安装
``` ```
git clone https://github.com/xiaoqidun/gitcz.git git clone https://github.com/xiaoqidun/gitcz.git
cd gitcz cd gitcz
go build gitcz.go go build gitcz.go
``` ```
# 手动安装 # 手动安装
1. 根据系统架构下载为你编译好的[二进制文件](https://aite.xyz/product/gitcz/) 1. 根据系统架构下载为你编译好的[二进制文件](https://aite.xyz/product/gitcz/)
2. 将下载好的二进制文件重命名为gitcz并保留后缀 2. 将下载好的二进制文件重命名为 gitcz 并保留后缀
3. 把gitcz文件移动到系统PATH环境变量中的目录下 3. gitcz 文件移动到系统 PATH 环境变量中的目录下
4. windows外的系统需使用chmod命令赋予可执行权限 4. windows 外的系统需使用 chmod 命令赋予可执行权限
# 使用说明 # 使用说明
```shell script ```shell script
# 添加文件到本地仓库 # 添加文件到本地仓库
git add . git add .
# 使用-amend参数可覆盖最近一次提交信息等同于git commit --amend # 使用-amend参数可覆盖最近一次提交信息等同于git commit --amend
# 使用-S参数可进行签署commit操作等同于git commit -S
gitcz gitcz
# 推送文件到远程仓库 # 推送文件到远程仓库
git push git push
``` ```
# 规范文档 # 规范文档
gitcz使用[angular git commit规范](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines)
gitcz 使用:[angular git commit 规范](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines)

@ -5,7 +5,6 @@ import (
"bytes" "bytes"
"flag" "flag"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"strconv" "strconv"
@ -78,6 +77,7 @@ func main() {
false, false,
"覆盖上次提交信息", "覆盖上次提交信息",
) )
sign := flag.Bool("S", false, "对commit进行签名")
author := flag.Bool( author := flag.Bool(
"author", "author",
false, false,
@ -96,7 +96,7 @@ func main() {
czCommit.BreakingChange = InputBreakingChange() czCommit.BreakingChange = InputBreakingChange()
czCommit.Closes = InputCloses() czCommit.Closes = InputCloses()
commit := GenerateCommit(czCommit) commit := GenerateCommit(czCommit)
if err := GitCommit(commit, *amend); err != nil { if err := GitCommit(commit, *amend, *sign); err != nil {
fmt.Println(err) fmt.Println(err)
} }
} }
@ -114,8 +114,8 @@ func NewLine() {
fmt.Println() fmt.Println()
} }
func GitCommit(commit string, amend bool) (err error) { func GitCommit(commit string, amend bool, sign bool) (err error) {
tempFile, err := ioutil.TempFile("", "git_commit_") tempFile, err := os.CreateTemp("", "git_commit_")
if err != nil { if err != nil {
return return
} }
@ -130,6 +130,9 @@ func GitCommit(commit string, amend bool) (err error) {
if amend { if amend {
args = append(args, "--amend") args = append(args, "--amend")
} }
if sign {
args = append(args, "-S")
}
args = append(args, "-F", tempFile.Name()) args = append(args, "-F", tempFile.Name())
cmd := exec.Command("git", args...) cmd := exec.Command("git", args...)
result, err := cmd.CombinedOutput() result, err := cmd.CombinedOutput()
@ -236,11 +239,11 @@ func GenerateCommit(czCommit *CzCommit) string {
commit += "\n\n" commit += "\n\n"
} }
if czCommit.BreakingChange != nil { if czCommit.BreakingChange != nil {
commit += ("BREAKING CHANGE: " + *czCommit.BreakingChange) commit += "BREAKING CHANGE: " + *czCommit.BreakingChange
commit += "\n\n" commit += "\n\n"
} }
if czCommit.Closes != nil { if czCommit.Closes != nil {
commit += ("Closes fix " + *czCommit.Closes) commit += "Closes fix " + *czCommit.Closes
} }
return commit return commit
} }

2
go.mod

@ -1,3 +1,3 @@
module github.com/xiaoqidun/gitcz module github.com/xiaoqidun/gitcz
go 1.18 go 1.21.2