@@ -8,6 +8,7 @@ import ( |
| 8 | 8 | "html/template" |
| 9 | 9 | "path/filepath" |
| 10 | 10 | "sort" |
| 11 | + "strconv" |
| 11 | 12 | "strings" |
| 12 | 13 | |
| 13 | 14 | "github.com/tenseleyFlow/shithub/internal/repos/git" |
@@ -159,44 +160,52 @@ func (h *Handlers) repoAboutContributors(ctx context.Context, gitDir, ref string |
| 159 | 160 | return nil |
| 160 | 161 | } |
| 161 | 162 | type aggregate struct { |
| 162 | | - name string |
| 163 | | - email string |
| 164 | | - count int |
| 163 | + contributor repoAboutContributor |
| 165 | 164 | } |
| 166 | 165 | byAuthor := map[string]*aggregate{} |
| 166 | + resolver := identity.New(h.d.Pool) |
| 167 | 167 | 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 |
| 171 | 194 | } |
| 172 | 195 | if key == "" { |
| 173 | 196 | continue |
| 174 | 197 | } |
| 175 | 198 | agg, ok := byAuthor[key] |
| 176 | 199 | if !ok { |
| 177 | | - agg = &aggregate{name: c.AuthorName, email: c.AuthorEmail} |
| 200 | + agg = &aggregate{contributor: contributor} |
| 178 | 201 | byAuthor[key] = agg |
| 179 | 202 | } |
| 180 | | - agg.count++ |
| 203 | + agg.contributor.Count++ |
| 181 | 204 | } |
| 182 | 205 | |
| 183 | | - resolver := identity.New(h.d.Pool) |
| 184 | 206 | contributors := make([]repoAboutContributor, 0, len(byAuthor)) |
| 185 | 207 | 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 |
| 200 | 209 | if c.Label == "" { |
| 201 | 210 | c.Label = "Unknown author" |
| 202 | 211 | } |