Files
gitea/models/gituser/avatar_stack.go
Brecht Van Lommel 43390e802c fix(ui): too many participants shown in commit avatar stacks (#38689)
Show only author and co-authors without committer, and deduplicate the
same user with multiple email addresses.

The commit list "Author" column should not show the committer. This is
somewhat misleading, and arguably showing it on the individual commit
page is sufficient and consistent with other forges.

The same user with multiple email addresses often happens when
DEFAULT_KEEP_EMAIL_PRIVATE is enabled and Gitea does not use an actual
email address by default for edits. Showing the same avatar and name
twice is not helpful then.

Ref #37594
Fix #38488

---

Before
<img width="4088" height="2138" alt="before"
src="https://github.com/user-attachments/assets/a9e919f4-72d0-495f-a0b5-ec094f148f5a"
/>

After
<img width="4124" height="2142" alt="after"
src="https://github.com/user-attachments/assets/7212e527-ab83-440a-a8a4-95b5a79b3580"
/>

---------

Co-authored-by: bircni <bircni@icloud.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2026-07-29 12:39:35 +00:00

53 lines
1.5 KiB
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package gituser
import (
"context"
"gitea.dev/models/user"
"gitea.dev/modules/container"
"gitea.dev/modules/git"
"gitea.dev/modules/log"
)
// AvatarStackData is the view-model for the AvatarStack render helpers. Participants[0] is
// the primary participant (commit author), painted on top; the rest follow.
type AvatarStackData struct {
Participants []*CommitParticipant
SearchByEmailLink string
}
func BuildAvatarStackData(ctx context.Context, allParticipants []*git.CommitIdentity, emailUserMap *user.EmailUserMap) *AvatarStackData {
if emailUserMap == nil {
emails := make([]string, len(allParticipants))
for i, sig := range allParticipants {
emails[i] = sig.Email
}
var err error
emailUserMap, err = user.GetUsersByEmails(ctx, emails)
if err != nil {
log.Error("GetUsersByEmails failed: %v", err)
}
}
ret := &AvatarStackData{
Participants: make([]*CommitParticipant, 0, len(allParticipants)),
}
uniqueUserIDs := make(container.Set[int64])
for _, p := range allParticipants {
var giteaUser *user.User
if emailUserMap != nil {
giteaUser = emailUserMap.GetByEmail(p.Email)
}
if giteaUser != nil {
// identities without a Gitea account can only be compared by their git identity
if !uniqueUserIDs.Add(giteaUser.ID) {
continue
}
}
ret.Participants = append(ret.Participants, &CommitParticipant{GiteaUser: giteaUser, GitIdentity: p})
}
return ret
}