mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
2978 files. The fork is 2026-07-15 (rebrand: gitea.dev -> github.com/hanzoai/git), so 2026 is the year, and "Copyright 2026 Hanzo AI, Inc." was already the form used by the handful of files that had ours. Shape is now: // Copyright 2026 Hanzo AI, Inc. All rights reserved. // Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT Ours on top, theirs retained verbatim. Retained because MIT requires it, and separately because they are true — those authors did write that code. Not renamed to "The Git Authors": Git is a different project under a different license, and putting its name here would attribute this code to people who have nothing to do with it. Adding our line is the fix; overwriting theirs would have been both a licence violation and a false statement. gofmt still reports import-order drift in some of these files. It predates this change (verified against a stash) and is left alone rather than burying a one-line-per-file legal change under 3000 files of unrelated reordering. Build clean. Co-authored-by: Hanzo Dev <[email protected]>
66 lines
2.2 KiB
Go
66 lines
2.2 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package gituser
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
|
|
"github.com/hanzoai/git/models/user"
|
|
"github.com/hanzoai/git/modules/container"
|
|
"github.com/hanzoai/git/modules/git"
|
|
)
|
|
|
|
// CommitParticipant is one participant of a commit (its author or a co-author):
|
|
// a git identity, optionally matched to a user.
|
|
type CommitParticipant struct {
|
|
GitIdentity *git.CommitIdentity // git identity (name/email), never nil
|
|
User *user.User // matched user, nil if unmatched
|
|
}
|
|
|
|
// UserCommit represents a commit with matched of database "author" user.
|
|
type UserCommit struct {
|
|
GitCommit *git.Commit
|
|
AuthorUser *user.User
|
|
AvatarStackData *AvatarStackData
|
|
}
|
|
|
|
func RepoCommitSearchByEmailLink(repoLink string, ref git.RefName) string {
|
|
if curRefWebLinkPath := ref.RefWebLinkPath(); curRefWebLinkPath != "" {
|
|
return repoLink + "/commits/" + curRefWebLinkPath + "/search?q=" + url.QueryEscape("author:") + "{email}"
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// GetUserCommitsByGitCommits checks if authors' e-mails of commits are corresponding to users.
|
|
func GetUserCommitsByGitCommits(ctx context.Context, gitCommits []*git.Commit, repoLink string, currentRef git.RefName) ([]*UserCommit, error) {
|
|
userCommits := make([]*UserCommit, 0, len(gitCommits))
|
|
emailSet := make(container.Set[string])
|
|
for _, c := range gitCommits {
|
|
emailSet.Add(c.Author.Email)
|
|
emailSet.Add(c.Committer.Email)
|
|
for _, p := range c.AllParticipantIdentities() {
|
|
emailSet.Add(p.Email)
|
|
}
|
|
}
|
|
|
|
emailUserMap, err := user.GetUsersByEmails(ctx, emailSet.Values())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
searchByEmailLink := RepoCommitSearchByEmailLink(repoLink, currentRef)
|
|
for _, c := range gitCommits {
|
|
uc := &UserCommit{
|
|
AuthorUser: emailUserMap.GetByEmail(c.Author.Email), // FIXME: why GetUserCommitsByGitCommits uses "Author", but ParseCommitsWithSignature uses "Committer"?
|
|
GitCommit: c,
|
|
AvatarStackData: BuildAvatarStackData(ctx, c.AllParticipantIdentities(), emailUserMap),
|
|
}
|
|
uc.AvatarStackData.SearchByEmailLink = searchByEmailLink
|
|
userCommits = append(userCommits, uc)
|
|
}
|
|
return userCommits, nil
|
|
}
|