4
4
"context"
5
5
"fmt"
6
6
"log"
7
+ "slices"
7
8
"strings"
8
9
"time"
9
10
@@ -33,9 +34,19 @@ func (s *GitLab) CurrentUser(ctx context.Context) (*User, error) {
33
34
return nil , fmt .Errorf ("get current user: %w" , err )
34
35
}
35
36
37
+ emails , _ , err := s .gitlabClient .Users .ListEmails (gitlab .WithContext (ctx ))
38
+ if err != nil {
39
+ return nil , fmt .Errorf ("get user emails: %w" , err )
40
+ }
41
+
42
+ emailAddresses := make ([]string , 0 , len (emails ))
43
+ for _ , email := range emails {
44
+ emailAddresses = append (emailAddresses , email .Email )
45
+ }
46
+
36
47
return & User {
37
48
Name : user .Name ,
38
- Email : user . Email ,
49
+ Emails : emailAddresses ,
39
50
Username : user .Username ,
40
51
CreatedAt : * user .CreatedAt ,
41
52
}, nil
@@ -100,7 +111,7 @@ func (s *GitLab) HasUserContributions(ctx context.Context, user *User, projectID
100
111
}
101
112
102
113
for _ , c := range contrs {
103
- if strings . EqualFold ( c . Email , user .Email ) {
114
+ if contains ( user . Emails , c .Email ) {
104
115
return true
105
116
}
106
117
}
@@ -161,7 +172,7 @@ func (s *GitLab) fetchCommitPage(
161
172
}
162
173
163
174
for _ , comm := range comms {
164
- if ! strings . EqualFold ( comm . AuthorEmail , user . Email ) || ! strings . EqualFold ( comm . CommitterEmail , user . Email ) {
175
+ if ! contains ( user . Emails , comm . AuthorEmail ) || ! contains ( user . Emails , comm . CommitterEmail ) {
165
176
continue
166
177
}
167
178
@@ -182,3 +193,10 @@ func (s *GitLab) fetchCommitPage(
182
193
183
194
return commits , resp .NextPage , nil
184
195
}
196
+
197
+ // contains checks if a string `v` is in the slice `s`, ignoring case.
198
+ func contains (s []string , v string ) bool {
199
+ return slices .ContainsFunc (s , func (item string ) bool {
200
+ return strings .EqualFold (item , v )
201
+ })
202
+ }
0 commit comments