From 8738c29008421eb638343893857449af0f4613e3 Mon Sep 17 00:00:00 2001 From: avadesian Date: Tue, 3 Aug 2021 16:29:30 +0800 Subject: [PATCH] merge contributors having different names or different emails --- routers/repo/view.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/routers/repo/view.go b/routers/repo/view.go index 76593ecc7..5c116285f 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -569,10 +569,19 @@ func safeURL(address string) string { } type ContributorInfo struct { - UserInfo *models.User - Email string // for contributor who is not a registered user + UserInfo *models.User // nil for contributor who is not a registered user + Email string + CommitCnt int } +func getContributorInfo(contributorInfos []*ContributorInfo, email string) *ContributorInfo{ + for _, c := range contributorInfos { + if strings.Compare(c.Email,email) == 0 { + return c + } + } + return nil +} // Home render repository home page func Home(ctx *context.Context) { if len(ctx.Repo.Units) > 0 { @@ -583,12 +592,17 @@ func Home(ctx *context.Context) { for _, c := range contributors { user, err := models.GetUserByEmail(c.Email) if err == nil { - contributorInfos = append(contributorInfos, &ContributorInfo{ - user, c.Email, - }) + existedContributorInfo := getContributorInfo(contributorInfos,user.Email) + if existedContributorInfo != nil { + existedContributorInfo.CommitCnt += c.CommitCnt + }else{ + contributorInfos = append(contributorInfos, &ContributorInfo{ + user, user.Email,c.CommitCnt, + }) + } } else { contributorInfos = append(contributorInfos, &ContributorInfo{ - nil, c.Email, + nil, c.Email,c.CommitCnt, }) } }