style: fmtBranch

This commit is contained in:
liruichen_wsl 2024-03-13 16:24:27 +08:00
parent f6129f75ae
commit c85c491bc9

View File

@ -195,7 +195,7 @@ func (b *Build) injectGocAgent(where string, covers []*PackageCover) {
cmd := exec.Command("git", "rev-parse", "--short=8", "HEAD") cmd := exec.Command("git", "rev-parse", "--short=8", "HEAD")
output, err := cmd.Output() output, err := cmd.Output()
if err != nil { if err != nil {
log.Errorf("git describe Error: %v", err) log.Errorf("git rev-parse Error: %v", err)
} else { } else {
commitID = strings.TrimRight(string(output), "\n") commitID = strings.TrimRight(string(output), "\n")
} }
@ -206,11 +206,7 @@ func (b *Build) injectGocAgent(where string, covers []*PackageCover) {
log.Errorf("get git branch Error: %v", err) log.Errorf("get git branch Error: %v", err)
} else { } else {
log.Infof("[goc][info] raw branch: %v ", br) log.Infof("[goc][info] raw branch: %v ", br)
branch = strings.Replace(string(br), "\n", "", -1) branch = fmtBranch(br)
branch = strings.TrimLeft(branch, "heads/")
branch = strings.Trim(branch, " ")
branch = strings.Replace(branch, "/", "-", -1)
branch = strings.Replace(branch, "_", "-", -1)
} }
log.Infof("[goc][info] branch: %v --- commitID: %v", branch, commitID) log.Infof("[goc][info] branch: %v --- commitID: %v", branch, commitID)
tmplData := struct { tmplData := struct {
@ -317,3 +313,11 @@ func UploadCoverChangeEvent_%v(name string, pos []uint32, i int, stmts uint16) {
log.Fatalf("fail to write to global cover definition file: %v", err) log.Fatalf("fail to write to global cover definition file: %v", err)
} }
} }
func fmtBranch(br []byte) (branch string) {
branch = strings.Replace(string(br), "\n", "", -1)
branch = strings.TrimLeft(branch, "heads/")
branch = strings.Trim(branch, " ")
branch = strings.Replace(branch, "/", "-", -1)
return
}