tenseleyflow/shithub / cde2a48

Browse files

Merge verified contributor identities

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
cde2a485a4788ee21313c08c20b9f374c5627923
Parents
8b3c058
Tree
0a31c0a

1 changed file

StatusFile+-
M internal/web/handlers/repo/about_sidebar.go 32 23
internal/web/handlers/repo/about_sidebar.gomodified
@@ -8,6 +8,7 @@ import (
88
 	"html/template"
99
 	"path/filepath"
1010
 	"sort"
11
+	"strconv"
1112
 	"strings"
1213
 
1314
 	"github.com/tenseleyFlow/shithub/internal/repos/git"
@@ -159,44 +160,52 @@ func (h *Handlers) repoAboutContributors(ctx context.Context, gitDir, ref string
159160
 		return nil
160161
 	}
161162
 	type aggregate struct {
162
-		name  string
163
-		email string
164
-		count int
163
+		contributor repoAboutContributor
165164
 	}
166165
 	byAuthor := map[string]*aggregate{}
166
+	resolver := identity.New(h.d.Pool)
167167
 	for _, c := range commits {
168
-		key := strings.ToLower(strings.TrimSpace(c.AuthorEmail))
169
-		if key == "" {
170
-			key = strings.ToLower(strings.TrimSpace(c.AuthorName))
168
+		resolved := resolver.Resolve(ctx, c.AuthorEmail)
169
+		key := ""
170
+		contributor := repoAboutContributor{}
171
+		if resolved.User {
172
+			key = "user:" + strconv.FormatInt(resolved.UserID, 10)
173
+			contributor.User = true
174
+			contributor.Username = resolved.Username
175
+			contributor.DisplayName = resolved.DisplayName
176
+			contributor.AvatarURL = resolved.AvatarURL
177
+			contributor.Label = resolved.DisplayName
178
+			if contributor.Label == "" {
179
+				contributor.Label = resolved.Username
180
+			}
181
+		} else {
182
+			email := strings.ToLower(strings.TrimSpace(c.AuthorEmail))
183
+			name := strings.ToLower(strings.TrimSpace(c.AuthorName))
184
+			if email != "" {
185
+				key = "email:" + email
186
+			} else if name != "" {
187
+				key = "name:" + name
188
+			}
189
+			contributor.Label = strings.TrimSpace(c.AuthorName)
190
+			if contributor.Label == "" {
191
+				contributor.Label = strings.TrimSpace(c.AuthorEmail)
192
+			}
193
+			contributor.IdenticonSeed = resolved.IdenticonSeed
171194
 		}
172195
 		if key == "" {
173196
 			continue
174197
 		}
175198
 		agg, ok := byAuthor[key]
176199
 		if !ok {
177
-			agg = &aggregate{name: c.AuthorName, email: c.AuthorEmail}
200
+			agg = &aggregate{contributor: contributor}
178201
 			byAuthor[key] = agg
179202
 		}
180
-		agg.count++
203
+		agg.contributor.Count++
181204
 	}
182205
 
183
-	resolver := identity.New(h.d.Pool)
184206
 	contributors := make([]repoAboutContributor, 0, len(byAuthor))
185207
 	for _, agg := range byAuthor {
186
-		resolved := resolver.Resolve(ctx, agg.email)
187
-		c := repoAboutContributor{Count: agg.count, Label: agg.name}
188
-		if resolved.User {
189
-			c.User = true
190
-			c.Username = resolved.Username
191
-			c.DisplayName = resolved.DisplayName
192
-			c.AvatarURL = resolved.AvatarURL
193
-			c.Label = resolved.DisplayName
194
-			if c.Label == "" {
195
-				c.Label = resolved.Username
196
-			}
197
-		} else {
198
-			c.IdenticonSeed = resolved.IdenticonSeed
199
-		}
208
+		c := agg.contributor
200209
 		if c.Label == "" {
201210
 			c.Label = "Unknown author"
202211
 		}