fix(发布变更): 使用github自带的发行功能放二进制

This commit is contained in:
xiaoqidun 2020-07-31 16:39:33 +08:00
commit f04d2813ba
5 changed files with 248 additions and 0 deletions

1
.gitignore vendored Normal file

@ -0,0 +1 @@
.idea/

21
LICENSE Normal file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 xiaoqidun
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

26
README.md Normal file

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

197
gitcz.go Normal file

@ -0,0 +1,197 @@
package main
import (
"bufio"
"bytes"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"strconv"
"strings"
)
type CzType struct {
Type string
Message string
}
type CzCommit struct {
Type *CzType
Scope *string
Subject *string
Body *string
Footer *string
}
var StdinInput = bufio.NewReader(os.Stdin)
var (
InputTypePrompt = "选择或输入一个提交类型(必填): "
InputScopePrompt = "说明本次提交的影响范围(必填): "
InputSubjectPrompt = "对本次提交进行简短描述(必填): "
)
var CzTypeList = []CzType{
{
Type: "feat",
Message: "新的功能",
},
{
Type: "fix",
Message: "修补错误",
},
{
Type: "docs",
Message: "文档修改",
},
{
Type: "style",
Message: "格式变化",
},
{
Type: "refactor",
Message: "重构代码",
},
{
Type: "perf",
Message: "性能提高",
},
{
Type: "test",
Message: "测试用例",
},
{
Type: "chore",
Message: "构建变动",
},
}
func main() {
amend := flag.Bool(
"amend",
false,
"覆盖上次提交信息",
)
author := flag.Bool(
"author",
false,
"关于本软件开发者",
)
flag.Parse()
if *author {
Author()
return
}
czCommit := &CzCommit{}
czCommit.Type = InputType()
czCommit.Scope = InputScope()
czCommit.Subject = InputSubject()
commit := GenerateCommit(czCommit)
if err := GitCommit(commit, *amend); err != nil {
log.Println(err)
}
}
func Author() {
fmt.Println("welcome to our website https://aite.xyz/")
fmt.Println("----------------------------------------")
fmt.Println("腾讯扣扣88966001")
fmt.Println("电子邮箱xiaoqidun@gmail.com")
fmt.Println("----------------------------------------")
fmt.Println("Copyright (c) 2020 xiaoqidun@gmail.com")
}
func NewLine() {
fmt.Println()
}
func GitCommit(commit string, amend bool) (err error) {
tempFile, err := ioutil.TempFile("", "git_commit_")
if err != nil {
return
}
defer func() {
_ = tempFile.Close()
_ = os.Remove(tempFile.Name())
}()
if _, err = tempFile.WriteString(commit); err != nil {
return
}
args := []string{"commit"}
if amend {
args = append(args, "--amend")
}
args = append(args, "-F", tempFile.Name())
cmd := exec.Command("git", args...)
result, err := cmd.CombinedOutput()
if err != nil && !strings.ContainsAny(err.Error(), "exit status") {
return
} else {
fmt.Println(string(bytes.TrimSpace(result)))
}
return nil
}
func InputType() *CzType {
typeNum := len(CzTypeList)
for i := 0; i < typeNum; i++ {
fmt.Printf("[%d] %s:\t%s\n", i+1, CzTypeList[i].Type, CzTypeList[i].Message)
}
fmt.Print(InputTypePrompt)
text, _ := StdinInput.ReadString('\n')
text = strings.TrimSpace(text)
selectId, err := strconv.Atoi(text)
if err == nil && (selectId > 0 && selectId <= typeNum) {
NewLine()
return &CzTypeList[selectId-1]
}
for i := 0; i < typeNum; i++ {
if text == CzTypeList[i].Type {
NewLine()
return &CzTypeList[i]
}
}
return InputType()
}
func InputScope() *string {
fmt.Print(InputScopePrompt)
text, _ := StdinInput.ReadString('\n')
text = strings.TrimSpace(text)
if text != "" {
NewLine()
return &text
}
return InputScope()
}
func InputSubject() *string {
fmt.Print(InputSubjectPrompt)
text, _ := StdinInput.ReadString('\n')
text = strings.TrimSpace(text)
if text != "" {
NewLine()
return &text
}
return InputScope()
}
func GenerateCommit(czCommit *CzCommit) string {
commit := fmt.Sprintf(
"%s(%s): %s\n",
czCommit.Type.Type,
*czCommit.Scope,
*czCommit.Subject,
)
if czCommit.Body != nil {
commit += *czCommit.Body
}
commit += "\n"
if czCommit.Footer != nil {
commit += *czCommit.Footer
}
return commit
}

3
go.mod Normal file

@ -0,0 +1,3 @@
module gitcz
go 1.13