Compare commits

..

No commits in common. "d36f61bc8072565aa05c9659ee2269cf9009e01f" and "00b8e2c4b6a0ff9f4685eb34eb10585685054397" have entirely different histories.

2 changed files with 16 additions and 65 deletions

@ -6,6 +6,7 @@ import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"strconv"
@ -22,8 +23,7 @@ type CzCommit struct {
Scope *string
Subject *string
Body *string
BreakingChange *string
Closes *string
Footer *string
}
var StdinInput = bufio.NewReader(os.Stdin)
@ -32,9 +32,6 @@ var (
InputTypePrompt = "选择或输入一个提交类型(必填): "
InputScopePrompt = "说明本次提交的影响范围(必填): "
InputSubjectPrompt = "对本次提交进行简短描述(必填): "
InputBodyPrompt = "对本次提交进行完整描述(选填): "
InputBreakingChangePrompt = "如果当前代码版本与上一版本不兼容,对变动、变动的理由及迁移的方法进行描述(选填): "
InputClosesPrompt = "如果本次提交针对某个issue,列出关闭的issues(选填): "
)
var CzTypeList = []CzType{
@ -92,12 +89,9 @@ func main() {
czCommit.Type = InputType()
czCommit.Scope = InputScope()
czCommit.Subject = InputSubject()
czCommit.Body = InputBody()
czCommit.BreakingChange = InputBreakingChange()
czCommit.Closes = InputCloses()
commit := GenerateCommit(czCommit)
if err := GitCommit(commit, *amend); err != nil {
fmt.Println(err)
log.Println(err)
}
}
@ -160,7 +154,6 @@ func InputType() *CzType {
return &CzTypeList[i]
}
}
NewLine()
return InputType()
}
@ -172,7 +165,6 @@ func InputScope() *string {
NewLine()
return &text
}
NewLine()
return InputScope()
}
@ -184,63 +176,22 @@ func InputSubject() *string {
NewLine()
return &text
}
NewLine()
return InputSubject()
}
func InputBody() *string {
fmt.Print(InputBodyPrompt)
text, _ := StdinInput.ReadString('\n')
text = strings.TrimSpace(text)
if text != "" {
NewLine()
return &text
}
NewLine()
return nil
}
func InputBreakingChange() *string {
fmt.Print(InputBreakingChangePrompt)
text, _ := StdinInput.ReadString('\n')
text = strings.TrimSpace(text)
if text != "" {
NewLine()
return &text
}
NewLine()
return nil
}
func InputCloses() *string {
fmt.Print(InputClosesPrompt)
text, _ := StdinInput.ReadString('\n')
text = strings.TrimSpace(text)
if text != "" {
NewLine()
return &text
}
NewLine()
return nil
return InputScope()
}
func GenerateCommit(czCommit *CzCommit) string {
commit := fmt.Sprintf(
"%s(%s): %s\n\n",
"%s(%s): %s\n",
czCommit.Type.Type,
*czCommit.Scope,
*czCommit.Subject,
)
if czCommit.Body != nil {
commit += *czCommit.Body
commit += "\n\n"
}
if czCommit.BreakingChange != nil {
commit += ("BREAKING CHANGE: " + *czCommit.BreakingChange)
commit += "\n\n"
}
if czCommit.Closes != nil {
commit += ("Closes fix " + *czCommit.Closes)
commit += "\n"
if czCommit.Footer != nil {
commit += *czCommit.Footer
}
return commit
}

2
go.mod

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