this is Author struct
type Author struct {
Name string
Email string
CommitNumber int
}
// get all authors
func GetAllAuthor() []Author {
args := []string{"shortlog", "-s", "-n", "-e", "--no-merges"}
var authors []Author
info := utils.MustExecRtOut(Cmd, args...)
lines := strings.Split(info, "\n")
for _, line := range lines {
if len(strings.TrimSpace(line)) > 0 {
author := GetAuthor(line)
authors = append(authors, author)
}
}
return authors
}
// get information about an author
func GetAuthor(line string) Author {
authorInfo := strings.Fields(strings.TrimSpace(line))
emailIndex := len(authorInfo) - 1
email := strings.TrimSpace(authorInfo[emailIndex])
email = utils.SubString(email, 1, len(email)-1)
author := strings.Join(authorInfo[1:emailIndex], " ")
number, err := strconv.Atoi(authorInfo[0])
if err != nil {
fmt.Printf("%s parse commit number %s error!\n", line, authorInfo[0])
}
return Author{
Name: author,
Email: email,
CommitNumber: number,
}
}
When I call GetAllAuthor
in the test function, the output is an empty array [], but when I debug or call it in the main function, the output can be normal,like this [{Joeeeeeeey 123@xx.com 169} {Tony 123@xx.com 62}]
Aucun commentaire:
Enregistrer un commentaire