@@ -35,42 +35,36 @@ type PushCommits struct {
35
35
HeadCommit * PushCommit
36
36
CompareURL string
37
37
Len int
38
-
39
- avatars map [string ]string
40
- emailUsers map [string ]* user_model.User
41
38
}
42
39
43
40
// NewPushCommits creates a new PushCommits object.
44
41
func NewPushCommits () * PushCommits {
45
- return & PushCommits {
46
- avatars : make (map [string ]string ),
47
- emailUsers : make (map [string ]* user_model.User ),
48
- }
42
+ return & PushCommits {}
49
43
}
50
44
51
45
// toAPIPayloadCommit converts a single PushCommit to an api.PayloadCommit object.
52
- func (pc * PushCommits ) toAPIPayloadCommit (ctx context.Context , repoPath , repoLink string , commit * PushCommit ) (* api.PayloadCommit , error ) {
46
+ func (pc * PushCommits ) toAPIPayloadCommit (ctx context.Context , emailUsers map [ string ] * user_model. User , repoPath , repoLink string , commit * PushCommit ) (* api.PayloadCommit , error ) {
53
47
var err error
54
48
authorUsername := ""
55
- author , ok := pc . emailUsers [commit .AuthorEmail ]
49
+ author , ok := emailUsers [commit .AuthorEmail ]
56
50
if ! ok {
57
51
author , err = user_model .GetUserByEmail (ctx , commit .AuthorEmail )
58
52
if err == nil {
59
53
authorUsername = author .Name
60
- pc . emailUsers [commit .AuthorEmail ] = author
54
+ emailUsers [commit .AuthorEmail ] = author
61
55
}
62
56
} else {
63
57
authorUsername = author .Name
64
58
}
65
59
66
60
committerUsername := ""
67
- committer , ok := pc . emailUsers [commit .CommitterEmail ]
61
+ committer , ok := emailUsers [commit .CommitterEmail ]
68
62
if ! ok {
69
63
committer , err = user_model .GetUserByEmail (ctx , commit .CommitterEmail )
70
64
if err == nil {
71
65
// TODO: check errors other than email not found.
72
66
committerUsername = committer .Name
73
- pc . emailUsers [commit .CommitterEmail ] = committer
67
+ emailUsers [commit .CommitterEmail ] = committer
74
68
}
75
69
} else {
76
70
committerUsername = committer .Name
@@ -108,11 +102,10 @@ func (pc *PushCommits) ToAPIPayloadCommits(ctx context.Context, repoPath, repoLi
108
102
commits := make ([]* api.PayloadCommit , len (pc .Commits ))
109
103
var headCommit * api.PayloadCommit
110
104
111
- if pc .emailUsers == nil {
112
- pc .emailUsers = make (map [string ]* user_model.User )
113
- }
105
+ emailUsers := make (map [string ]* user_model.User )
106
+
114
107
for i , commit := range pc .Commits {
115
- apiCommit , err := pc .toAPIPayloadCommit (ctx , repoPath , repoLink , commit )
108
+ apiCommit , err := pc .toAPIPayloadCommit (ctx , emailUsers , repoPath , repoLink , commit )
116
109
if err != nil {
117
110
return nil , nil , err
118
111
}
@@ -124,7 +117,7 @@ func (pc *PushCommits) ToAPIPayloadCommits(ctx context.Context, repoPath, repoLi
124
117
}
125
118
if pc .HeadCommit != nil && headCommit == nil {
126
119
var err error
127
- headCommit , err = pc .toAPIPayloadCommit (ctx , repoPath , repoLink , pc .HeadCommit )
120
+ headCommit , err = pc .toAPIPayloadCommit (ctx , emailUsers , repoPath , repoLink , pc .HeadCommit )
128
121
if err != nil {
129
122
return nil , nil , err
130
123
}
@@ -176,7 +169,5 @@ func GitToPushCommits(gitCommits []*git.Commit) *PushCommits {
176
169
HeadCommit : nil ,
177
170
CompareURL : "" ,
178
171
Len : len (commits ),
179
- avatars : make (map [string ]string ),
180
- emailUsers : make (map [string ]* user_model.User ),
181
172
}
182
173
}
0 commit comments