1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-10-26 07:55:34 +03:00

Have co-author parsing be more robust and some refactoring

This commit is contained in:
Kemal Zebari 2024-05-11 16:02:08 -07:00
parent 9ac9327c57
commit cce78121ff
2 changed files with 13 additions and 12 deletions

View File

@ -159,7 +159,7 @@ func getExtendedCommitStats(repo *git.Repository, revision string /*, limit int
// There should be an empty line before we read the commit stats line.
break
}
coAuthorEmail, coAuthorName, err := parseCoAuthorTrailerValue(line)
coAuthorName, coAuthorEmail, err := parseCoAuthorTrailerValue(line)
if err != nil {
continue
}
@ -222,27 +222,29 @@ func getExtendedCommitStats(repo *git.Repository, revision string /*, limit int
var errSyntax = errors.New("syntax error occurred")
func parseCoAuthorTrailerValue(value string) (email, name string, err error) {
func parseCoAuthorTrailerValue(value string) (name, email string, err error) {
value = strings.TrimSpace(value)
if !strings.HasSuffix(value, ">") {
return "", "", errSyntax
}
if openEmailBracketIdx := strings.LastIndex(value, "<"); openEmailBracketIdx == -1 {
closedBracketIdx := len(value) - 1
openEmailBracketIdx := strings.LastIndex(value, "<")
if openEmailBracketIdx == -1 {
return "", "", errSyntax
}
parts := strings.Split(value, "<")
if len(parts) < 2 {
return "", "", errSyntax
}
email = strings.TrimRight(parts[1], ">")
email = value[openEmailBracketIdx+1 : closedBracketIdx]
if _, err := mail.ParseAddress(email); err != nil {
return "", "", err
}
name = strings.TrimSpace(parts[0])
return email, name, nil
name = strings.TrimSpace(value[:openEmailBracketIdx])
if len(name) == 0 {
return "", "", errSyntax
}
return name, email, nil
}
func generateContributorStats(genDone chan struct{}, cache cache.StringCache, cacheKey string, repo *repo_model.Repository, revision string) {

View File

@ -88,7 +88,6 @@ func TestRepository_ContributorsGraph(t *testing.T) {
},
}, data["total"])
})
t.Run("generate contributor stats with co-authored commit", func(t *testing.T) {
mockCache, err := cache.NewStringCache(setting.Cache{})
assert.NoError(t, err)