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]>
95 lines
3.4 KiB
Go
95 lines
3.4 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package repository
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
|
|
repo_model "github.com/hanzoai/git/models/repo"
|
|
user_model "github.com/hanzoai/git/models/user"
|
|
"github.com/hanzoai/git/modules/setting"
|
|
"github.com/hanzoai/git/modules/util"
|
|
)
|
|
|
|
// env keys for git hooks need
|
|
const (
|
|
EnvRepoName = "GIT_REPO_NAME"
|
|
EnvRepoUsername = "GIT_REPO_USER_NAME"
|
|
EnvRepoID = "GIT_REPO_ID"
|
|
EnvRepoIsWiki = "GIT_REPO_IS_WIKI"
|
|
EnvPusherName = "GIT_PUSHER_NAME"
|
|
EnvPusherEmail = "GIT_PUSHER_EMAIL"
|
|
EnvPusherID = "GIT_PUSHER_ID"
|
|
EnvKeyID = "GIT_KEY_ID" // public key ID
|
|
EnvDeployKeyID = "GIT_DEPLOY_KEY_ID"
|
|
EnvPRID = "GIT_PR_ID"
|
|
EnvPRIndex = "GIT_PR_INDEX" // not used by Gitea at the moment, it is for custom git hooks
|
|
EnvPushTrigger = "GIT_PUSH_TRIGGER"
|
|
EnvIsInternal = "GIT_INTERNAL_PUSH"
|
|
EnvAppURL = "GIT_ROOT_URL"
|
|
EnvActionsTaskID = "GIT_ACTIONS_TASK_ID"
|
|
)
|
|
|
|
type PushTrigger string
|
|
|
|
const (
|
|
PushTriggerPRMergeToBase PushTrigger = "pr-merge-to-base"
|
|
PushTriggerPRUpdateWithBase PushTrigger = "pr-update-with-base"
|
|
)
|
|
|
|
// InternalPushingEnvironment returns an os environment to switch off hooks on push
|
|
// It is recommended to avoid using this unless you are pushing within a transaction
|
|
// or if you absolutely are sure that post-receive and pre-receive will do nothing
|
|
// We provide the full pushing-environment for other hook providers
|
|
func InternalPushingEnvironment(doer *user_model.User, repo *repo_model.Repository) []string {
|
|
return append(PushingEnvironment(doer, repo),
|
|
EnvIsInternal+"=true",
|
|
)
|
|
}
|
|
|
|
// PushingEnvironment returns an os environment to allow hooks to work on push
|
|
func PushingEnvironment(doer *user_model.User, repo *repo_model.Repository) []string {
|
|
return FullPushingEnvironment(doer, doer, repo, repo.Name, 0, 0)
|
|
}
|
|
|
|
func DoerPushingEnvironment(doer *user_model.User, repo *repo_model.Repository, isWiki bool) []string {
|
|
env := []string{
|
|
EnvAppURL + "=" + setting.AppURL,
|
|
EnvRepoName + "=" + repo.Name + util.Iif(isWiki, ".wiki", ""),
|
|
EnvRepoUsername + "=" + repo.OwnerName,
|
|
EnvRepoID + "=" + strconv.FormatInt(repo.ID, 10),
|
|
EnvRepoIsWiki + "=" + strconv.FormatBool(isWiki),
|
|
EnvPusherName + "=" + doer.Name,
|
|
EnvPusherID + "=" + strconv.FormatInt(doer.ID, 10),
|
|
}
|
|
if !doer.KeepEmailPrivate {
|
|
env = append(env, EnvPusherEmail+"="+doer.Email)
|
|
}
|
|
if taskID, isActionsUser := user_model.GetActionsUserTaskID(doer); isActionsUser {
|
|
env = append(env, EnvActionsTaskID+"="+strconv.FormatInt(taskID, 10))
|
|
}
|
|
return env
|
|
}
|
|
|
|
// FullPushingEnvironment returns an os environment to allow hooks to work on push
|
|
func FullPushingEnvironment(author, committer *user_model.User, repo *repo_model.Repository, repoName string, prID, prIndex int64) []string {
|
|
isWiki := strings.HasSuffix(repoName, ".wiki")
|
|
authorSig := author.NewGitSig()
|
|
committerSig := committer.NewGitSig()
|
|
environ := append(os.Environ(),
|
|
"GIT_AUTHOR_NAME="+authorSig.Name,
|
|
"GIT_AUTHOR_EMAIL="+authorSig.Email,
|
|
"GIT_COMMITTER_NAME="+committerSig.Name,
|
|
"GIT_COMMITTER_EMAIL="+committerSig.Email,
|
|
EnvPRID+"="+strconv.FormatInt(prID, 10),
|
|
EnvPRIndex+"="+strconv.FormatInt(prIndex, 10),
|
|
"SSH_ORIGINAL_COMMAND=gitea-internal",
|
|
)
|
|
environ = append(environ, DoerPushingEnvironment(committer, repo, isWiki)...)
|
|
return environ
|
|
}
|