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]>
92 lines
2.2 KiB
Go
92 lines
2.2 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package user
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/hanzoai/git/modules/structs"
|
|
)
|
|
|
|
const (
|
|
GhostUserID int64 = -1
|
|
GhostUserName = "Ghost"
|
|
)
|
|
|
|
// NewGhostUser creates and returns a fake user for someone has deleted their account.
|
|
func NewGhostUser() *User {
|
|
return &User{
|
|
ID: GhostUserID,
|
|
Name: GhostUserName,
|
|
LowerName: strings.ToLower(GhostUserName),
|
|
}
|
|
}
|
|
|
|
// IsGhost check if user is fake user for a deleted account
|
|
func (u *User) IsGhost() bool {
|
|
if u == nil {
|
|
return false
|
|
}
|
|
return u.ID == GhostUserID && u.Name == GhostUserName
|
|
}
|
|
|
|
const (
|
|
ActionsUserID int64 = -2
|
|
ActionsUserName = "hanzo-actions"
|
|
ActionsUserEmail = "[email protected]"
|
|
)
|
|
|
|
// NewActionsUser creates and returns a fake user for running the actions.
|
|
func NewActionsUser() *User {
|
|
return &User{
|
|
ID: ActionsUserID,
|
|
Name: ActionsUserName,
|
|
LowerName: ActionsUserName,
|
|
IsActive: true,
|
|
FullName: "Hanzo Actions",
|
|
Email: ActionsUserEmail,
|
|
KeepEmailPrivate: true,
|
|
LoginName: ActionsUserName,
|
|
Type: UserTypeBot,
|
|
Visibility: structs.VisibleTypePublic,
|
|
}
|
|
}
|
|
|
|
func NewActionsUserWithTaskID(id int64) *User {
|
|
u := NewActionsUser()
|
|
// LoginName is for only internal usage in this case, so it can be moved to other fields in the future
|
|
u.LoginSource = -1
|
|
u.LoginName = "@" + ActionsUserName + "/" + strconv.FormatInt(id, 10)
|
|
return u
|
|
}
|
|
|
|
func GetActionsUserTaskID(u *User) (int64, bool) {
|
|
if u == nil || u.ID != ActionsUserID {
|
|
return 0, false
|
|
}
|
|
prefix, payload, _ := strings.Cut(u.LoginName, "/")
|
|
if prefix != "@"+ActionsUserName {
|
|
return 0, false
|
|
} else if taskID, err := strconv.ParseInt(payload, 10, 64); err == nil {
|
|
return taskID, true
|
|
}
|
|
return 0, false
|
|
}
|
|
|
|
func (u *User) IsGiteaActions() bool {
|
|
return u != nil && u.ID == ActionsUserID
|
|
}
|
|
|
|
func GetSystemUserByName(name string) *User {
|
|
if strings.EqualFold(name, GhostUserName) {
|
|
return NewGhostUser()
|
|
}
|
|
if strings.EqualFold(name, ActionsUserName) {
|
|
return NewActionsUser()
|
|
}
|
|
return nil
|
|
}
|