Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
53 lines
1.5 KiB
Go
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
|
|
}
|