mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.6 KiB
80 lines
2.6 KiB
6 years ago
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
3 years ago
|
package repository
|
||
6 years ago
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"strings"
|
||
4 years ago
|
|
||
3 years ago
|
repo_model "code.gitea.io/gitea/models/repo"
|
||
3 years ago
|
user_model "code.gitea.io/gitea/models/user"
|
||
4 years ago
|
"code.gitea.io/gitea/modules/setting"
|
||
6 years ago
|
)
|
||
|
|
||
5 years ago
|
// env keys for git hooks need
|
||
|
const (
|
||
|
EnvRepoName = "GITEA_REPO_NAME"
|
||
|
EnvRepoUsername = "GITEA_REPO_USER_NAME"
|
||
4 years ago
|
EnvRepoID = "GITEA_REPO_ID"
|
||
5 years ago
|
EnvRepoIsWiki = "GITEA_REPO_IS_WIKI"
|
||
|
EnvPusherName = "GITEA_PUSHER_NAME"
|
||
|
EnvPusherEmail = "GITEA_PUSHER_EMAIL"
|
||
|
EnvPusherID = "GITEA_PUSHER_ID"
|
||
3 years ago
|
EnvKeyID = "GITEA_KEY_ID" // public key ID
|
||
|
EnvDeployKeyID = "GITEA_DEPLOY_KEY_ID"
|
||
4 years ago
|
EnvPRID = "GITEA_PR_ID"
|
||
5 years ago
|
EnvIsInternal = "GITEA_INTERNAL_PUSH"
|
||
4 years ago
|
EnvAppURL = "GITEA_ROOT_URL"
|
||
5 years ago
|
)
|
||
|
|
||
5 years ago
|
// 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
|
||
3 years ago
|
func InternalPushingEnvironment(doer *user_model.User, repo *repo_model.Repository) []string {
|
||
5 years ago
|
return append(PushingEnvironment(doer, repo),
|
||
|
EnvIsInternal+"=true",
|
||
|
)
|
||
|
}
|
||
|
|
||
6 years ago
|
// PushingEnvironment returns an os environment to allow hooks to work on push
|
||
3 years ago
|
func PushingEnvironment(doer *user_model.User, repo *repo_model.Repository) []string {
|
||
5 years ago
|
return FullPushingEnvironment(doer, doer, repo, repo.Name, 0)
|
||
5 years ago
|
}
|
||
|
|
||
|
// FullPushingEnvironment returns an os environment to allow hooks to work on push
|
||
3 years ago
|
func FullPushingEnvironment(author, committer *user_model.User, repo *repo_model.Repository, repoName string, prID int64) []string {
|
||
6 years ago
|
isWiki := "false"
|
||
5 years ago
|
if strings.HasSuffix(repoName, ".wiki") {
|
||
6 years ago
|
isWiki = "true"
|
||
|
}
|
||
|
|
||
5 years ago
|
authorSig := author.NewGitSig()
|
||
|
committerSig := committer.NewGitSig()
|
||
6 years ago
|
|
||
4 years ago
|
environ := append(os.Environ(),
|
||
5 years ago
|
"GIT_AUTHOR_NAME="+authorSig.Name,
|
||
|
"GIT_AUTHOR_EMAIL="+authorSig.Email,
|
||
|
"GIT_COMMITTER_NAME="+committerSig.Name,
|
||
|
"GIT_COMMITTER_EMAIL="+committerSig.Email,
|
||
5 years ago
|
EnvRepoName+"="+repoName,
|
||
5 years ago
|
EnvRepoUsername+"="+repo.OwnerName,
|
||
6 years ago
|
EnvRepoIsWiki+"="+isWiki,
|
||
5 years ago
|
EnvPusherName+"="+committer.Name,
|
||
|
EnvPusherID+"="+fmt.Sprintf("%d", committer.ID),
|
||
4 years ago
|
EnvRepoID+"="+fmt.Sprintf("%d", repo.ID),
|
||
|
EnvPRID+"="+fmt.Sprintf("%d", prID),
|
||
4 years ago
|
EnvAppURL+"="+setting.AppURL,
|
||
5 years ago
|
"SSH_ORIGINAL_COMMAND=gitea-internal",
|
||
6 years ago
|
)
|
||
|
|
||
4 years ago
|
if !committer.KeepEmailPrivate {
|
||
|
environ = append(environ, EnvPusherEmail+"="+committer.Email)
|
||
|
}
|
||
|
|
||
|
return environ
|
||
6 years ago
|
}
|