mirror of
https://github.com/xiaoqidun/gitcz.git
synced 2025-03-15 08:24:38 +08:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
d36f61bc80 | |||
b45c7a8e32 | |||
55c015a566 | |||
00b8e2c4b6 |
@ -10,11 +10,11 @@ steps:
|
|||||||
- 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: xiaoqidun/goenv
|
image: hkccr.ccs.tencentyun.com/xiaoqidun/goenv
|
||||||
commands:
|
commands:
|
||||||
- ./build.sh
|
- ./build.sh
|
||||||
- name: upload
|
- name: upload
|
||||||
image: xiaoqidun/gocos
|
image: hkccr.ccs.tencentyun.com/xiaoqidun/gocos
|
||||||
settings:
|
settings:
|
||||||
secret_id:
|
secret_id:
|
||||||
from_secret: cos_secret_id
|
from_secret: cos_secret_id
|
||||||
|
79
gitcz.go
79
gitcz.go
@ -6,7 +6,6 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -19,19 +18,23 @@ type CzType struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CzCommit struct {
|
type CzCommit struct {
|
||||||
Type *CzType
|
Type *CzType
|
||||||
Scope *string
|
Scope *string
|
||||||
Subject *string
|
Subject *string
|
||||||
Body *string
|
Body *string
|
||||||
Footer *string
|
BreakingChange *string
|
||||||
|
Closes *string
|
||||||
}
|
}
|
||||||
|
|
||||||
var StdinInput = bufio.NewReader(os.Stdin)
|
var StdinInput = bufio.NewReader(os.Stdin)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
InputTypePrompt = "选择或输入一个提交类型(必填): "
|
InputTypePrompt = "选择或输入一个提交类型(必填): "
|
||||||
InputScopePrompt = "说明本次提交的影响范围(必填): "
|
InputScopePrompt = "说明本次提交的影响范围(必填): "
|
||||||
InputSubjectPrompt = "对本次提交进行简短描述(必填): "
|
InputSubjectPrompt = "对本次提交进行简短描述(必填): "
|
||||||
|
InputBodyPrompt = "对本次提交进行完整描述(选填): "
|
||||||
|
InputBreakingChangePrompt = "如果当前代码版本与上一版本不兼容,对变动、变动的理由及迁移的方法进行描述(选填): "
|
||||||
|
InputClosesPrompt = "如果本次提交针对某个issue,列出关闭的issues(选填): "
|
||||||
)
|
)
|
||||||
|
|
||||||
var CzTypeList = []CzType{
|
var CzTypeList = []CzType{
|
||||||
@ -89,9 +92,12 @@ func main() {
|
|||||||
czCommit.Type = InputType()
|
czCommit.Type = InputType()
|
||||||
czCommit.Scope = InputScope()
|
czCommit.Scope = InputScope()
|
||||||
czCommit.Subject = InputSubject()
|
czCommit.Subject = InputSubject()
|
||||||
|
czCommit.Body = InputBody()
|
||||||
|
czCommit.BreakingChange = InputBreakingChange()
|
||||||
|
czCommit.Closes = InputCloses()
|
||||||
commit := GenerateCommit(czCommit)
|
commit := GenerateCommit(czCommit)
|
||||||
if err := GitCommit(commit, *amend); err != nil {
|
if err := GitCommit(commit, *amend); err != nil {
|
||||||
log.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,6 +160,7 @@ func InputType() *CzType {
|
|||||||
return &CzTypeList[i]
|
return &CzTypeList[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
NewLine()
|
||||||
return InputType()
|
return InputType()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,6 +172,7 @@ func InputScope() *string {
|
|||||||
NewLine()
|
NewLine()
|
||||||
return &text
|
return &text
|
||||||
}
|
}
|
||||||
|
NewLine()
|
||||||
return InputScope()
|
return InputScope()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,22 +184,63 @@ func InputSubject() *string {
|
|||||||
NewLine()
|
NewLine()
|
||||||
return &text
|
return &text
|
||||||
}
|
}
|
||||||
return InputScope()
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateCommit(czCommit *CzCommit) string {
|
func GenerateCommit(czCommit *CzCommit) string {
|
||||||
commit := fmt.Sprintf(
|
commit := fmt.Sprintf(
|
||||||
"%s(%s): %s\n",
|
"%s(%s): %s\n\n",
|
||||||
czCommit.Type.Type,
|
czCommit.Type.Type,
|
||||||
*czCommit.Scope,
|
*czCommit.Scope,
|
||||||
*czCommit.Subject,
|
*czCommit.Subject,
|
||||||
)
|
)
|
||||||
if czCommit.Body != nil {
|
if czCommit.Body != nil {
|
||||||
commit += *czCommit.Body
|
commit += *czCommit.Body
|
||||||
|
commit += "\n\n"
|
||||||
}
|
}
|
||||||
commit += "\n"
|
if czCommit.BreakingChange != nil {
|
||||||
if czCommit.Footer != nil {
|
commit += ("BREAKING CHANGE: " + *czCommit.BreakingChange)
|
||||||
commit += *czCommit.Footer
|
commit += "\n\n"
|
||||||
|
}
|
||||||
|
if czCommit.Closes != nil {
|
||||||
|
commit += ("Closes fix " + *czCommit.Closes)
|
||||||
}
|
}
|
||||||
return commit
|
return commit
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user