Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add top author stats to activity page #9615

Merged
merged 12 commits into from
Jan 20, 2020
Prev Previous commit
Next Next commit
Fix results to be sorted descening
  • Loading branch information
lafriks committed Jan 20, 2020
commit def28ca2eaa2a7583d0fbad6fb451ac8470d1644
5 changes: 5 additions & 0 deletions modules/git/repo_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bufio"
"bytes"
"fmt"
"sort"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -120,6 +121,10 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string)
for _, v := range authors {
a = append(a, v)
}
// Sort authors descending depending on commit count
sort.Slice(a, func(i, j int) bool {
return a[i].Commits > a[j].Commits
})

stats.AuthorCount = int64(len(authors))
stats.ChangedFiles = int64(len(files))
Expand Down
2 changes: 1 addition & 1 deletion modules/git/repo_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ func TestRepository_GetCodeActivityStats(t *testing.T) {
assert.Len(t, code.Authors, 3)
assert.EqualValues(t, "[email protected]", code.Authors[1].Email)
assert.EqualValues(t, 3, code.Authors[1].Commits)
assert.EqualValues(t, 5, code.Authors[2].Commits)
assert.EqualValues(t, 5, code.Authors[0].Commits)
}