giteabot backport / giteabot (push) Canceled after 0s
giteabot / giteabot (push) Canceled after 0s
release-nightly / nightly-binary (push) Canceled after 0s
release-nightly / nightly-container (push) Canceled after 0s
cache-seeder / gobuild (push) Canceled after 0s
cache-seeder / lint (bindata, lint-backend) (push) Canceled after 0s
release-nightly-snapcraft / build-and-publish (push) Canceled after 0s
Includes direct password setup links in registration emails. Assisted-by: Codex:GPT-5
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
|
|
}
|