summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2020-01-20 12:07:30 +0200
committerGitHub <noreply@github.com>2020-01-20 12:07:30 +0200
commit81cfe243f9cb90b0a75de7a03bb2d264c97f0036 (patch)
tree0b98db10d626eff18384ad460ec04e2a6da61468 /models
parent7d7ab1eeae43d99fe329878ac9c8db5e45e2dee5 (diff)
downloadgitea-81cfe243f9cb90b0a75de7a03bb2d264c97f0036.tar.gz
gitea-81cfe243f9cb90b0a75de7a03bb2d264c97f0036.zip
Add top author stats to activity page (#9615)
Diffstat (limited to 'models')
-rw-r--r--models/repo_activity.go22
1 files changed, 16 insertions, 6 deletions
diff --git a/models/repo_activity.go b/models/repo_activity.go
index d25524c057..8ee1011c2a 100644
--- a/models/repo_activity.go
+++ b/models/repo_activity.go
@@ -19,6 +19,7 @@ type ActivityAuthorData struct {
Name string `json:"name"`
Login string `json:"login"`
AvatarLink string `json:"avatar_link"`
+ HomeLink string `json:"home_link"`
Commits int64 `json:"commits"`
}
@@ -91,12 +92,20 @@ func GetActivityStatsTopAuthors(repo *Repository, timeFrom time.Time, count int)
return nil, nil
}
users := make(map[int64]*ActivityAuthorData)
- for k, v := range code.Authors {
- if len(k) == 0 {
+ var unknownUserID int64
+ unknownUserAvatarLink := NewGhostUser().AvatarLink()
+ for _, v := range code.Authors {
+ if len(v.Email) == 0 {
continue
}
- u, err := GetUserByEmail(k)
+ u, err := GetUserByEmail(v.Email)
if u == nil || IsErrUserNotExist(err) {
+ unknownUserID--
+ users[unknownUserID] = &ActivityAuthorData{
+ Name: v.Name,
+ AvatarLink: unknownUserAvatarLink,
+ Commits: v.Commits,
+ }
continue
}
if err != nil {
@@ -107,10 +116,11 @@ func GetActivityStatsTopAuthors(repo *Repository, timeFrom time.Time, count int)
Name: u.DisplayName(),
Login: u.LowerName,
AvatarLink: u.AvatarLink(),
- Commits: v,
+ HomeLink: u.HomeLink(),
+ Commits: v.Commits,
}
} else {
- user.Commits += v
+ user.Commits += v.Commits
}
}
v := make([]*ActivityAuthorData, 0)
@@ -119,7 +129,7 @@ func GetActivityStatsTopAuthors(repo *Repository, timeFrom time.Time, count int)
}
sort.Slice(v, func(i, j int) bool {
- return v[i].Commits < v[j].Commits
+ return v[i].Commits > v[j].Commits
})
cnt := count