1
1
package contributors
2
2
3
3
import (
4
+ "context"
5
+ "fmt"
6
+ "time"
7
+
4
8
repo_model "code.gitea.io/gitea/models/repo"
5
9
user_model "code.gitea.io/gitea/models/user"
6
10
"code.gitea.io/gitea/modules/git"
7
- "code.gitea.io/gitea/modules/json"
8
11
util "code.gitea.io/gitea/modules/util"
9
- "context"
10
- "fmt"
11
- "time"
12
12
)
13
13
14
14
type WeekData struct {
@@ -20,12 +20,12 @@ type WeekData struct {
20
20
21
21
// ContributorData represents statistical git commit count data
22
22
type ContributorData struct {
23
- Name string `json:"name"`
24
- Login string `json:"login"`
25
- AvatarLink string `json:"avatar_link"`
26
- HomeLink string `json:"home_link"`
27
- Total int64 `json:"total "`
28
- Weeks []* WeekData `json:"weeks"`
23
+ Name string `json:"name"`
24
+ Login string `json:"login"`
25
+ AvatarLink string `json:"avatar_link"`
26
+ HomeLink string `json:"home_link"`
27
+ TotalCommits int64 `json:"total_commits "`
28
+ Weeks []* WeekData `json:"weeks"`
29
29
}
30
30
31
31
func CreateWeeks (sundays []int64 ) []* WeekData {
@@ -51,7 +51,7 @@ func GetContributorStats(ctx context.Context, repo *repo_model.Repository) (map[
51
51
defer closer .Close ()
52
52
53
53
default_branch , _ := gitRepo .GetDefaultBranch ()
54
- extended_commit_stats , err := gitRepo .ExtendedCommitStats (default_branch , 6000 )
54
+ extended_commit_stats , err := gitRepo .ExtendedCommitStats (default_branch )
55
55
if err != nil {
56
56
return nil , fmt .Errorf ("ExtendedCommitStats: %w" , err )
57
57
}
@@ -66,11 +66,12 @@ func GetContributorStats(ctx context.Context, repo *repo_model.Repository) (map[
66
66
67
67
unknownUserAvatarLink := user_model .NewGhostUser ().AvatarLink (ctx )
68
68
contributors_commit_stats := make (map [string ]* ContributorData )
69
- contributors_commit_stats ["" ] = & ContributorData {
69
+ contributors_commit_stats ["Total " ] = & ContributorData {
70
70
Name : "Total" ,
71
71
AvatarLink : unknownUserAvatarLink ,
72
72
Weeks : CreateWeeks (sundays ),
73
73
}
74
+ total , _ := contributors_commit_stats ["Total" ]
74
75
75
76
for _ , v := range extended_commit_stats {
76
77
if len (v .Author .Email ) == 0 {
@@ -92,7 +93,6 @@ func GetContributorStats(ctx context.Context, repo *repo_model.Repository) (map[
92
93
HomeLink : u .HomeLink (),
93
94
Weeks : CreateWeeks (sundays ),
94
95
}
95
-
96
96
}
97
97
}
98
98
// Update user statistics
@@ -105,22 +105,14 @@ func GetContributorStats(ctx context.Context, repo *repo_model.Repository) (map[
105
105
user .Weeks [idx ].Additions += v .Stats .Additions
106
106
user .Weeks [idx ].Deletions += v .Stats .Deletions
107
107
user .Weeks [idx ].Commits ++
108
- user .Total ++
108
+ user .TotalCommits ++
109
109
110
110
// Update overall statistics
111
- total , _ := contributors_commit_stats ["" ]
112
111
total .Weeks [idx ].Additions += v .Stats .Additions
113
112
total .Weeks [idx ].Deletions += v .Stats .Deletions
114
113
total .Weeks [idx ].Commits ++
115
- total .Total ++
114
+ total .TotalCommits ++
116
115
}
117
116
118
- fmt .Printf ("users are: %s" , prettyPrint (contributors_commit_stats ))
119
-
120
117
return contributors_commit_stats , nil
121
118
}
122
-
123
- func prettyPrint (i interface {}) string {
124
- s , _ := json .MarshalIndent (i , "" , "\t " )
125
- return string (s )
126
- }
0 commit comments