mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	Rename models.ProtectedBranchRepoID to models.EnvRepoID and ensure EnvPusherEmail is set (#12646)
Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
		@@ -170,7 +170,7 @@ Gitea or set your environment appropriately.`, "")
 | 
				
			|||||||
	username := os.Getenv(models.EnvRepoUsername)
 | 
						username := os.Getenv(models.EnvRepoUsername)
 | 
				
			||||||
	reponame := os.Getenv(models.EnvRepoName)
 | 
						reponame := os.Getenv(models.EnvRepoName)
 | 
				
			||||||
	userID, _ := strconv.ParseInt(os.Getenv(models.EnvPusherID), 10, 64)
 | 
						userID, _ := strconv.ParseInt(os.Getenv(models.EnvPusherID), 10, 64)
 | 
				
			||||||
	prID, _ := strconv.ParseInt(os.Getenv(models.ProtectedBranchPRID), 10, 64)
 | 
						prID, _ := strconv.ParseInt(os.Getenv(models.EnvPRID), 10, 64)
 | 
				
			||||||
	isDeployKey, _ := strconv.ParseBool(os.Getenv(models.EnvIsDeployKey))
 | 
						isDeployKey, _ := strconv.ParseBool(os.Getenv(models.EnvIsDeployKey))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	hookOptions := private.HookOptions{
 | 
						hookOptions := private.HookOptions{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -206,9 +206,10 @@ func runServ(c *cli.Context) error {
 | 
				
			|||||||
	os.Setenv(models.EnvRepoName, results.RepoName)
 | 
						os.Setenv(models.EnvRepoName, results.RepoName)
 | 
				
			||||||
	os.Setenv(models.EnvRepoUsername, results.OwnerName)
 | 
						os.Setenv(models.EnvRepoUsername, results.OwnerName)
 | 
				
			||||||
	os.Setenv(models.EnvPusherName, results.UserName)
 | 
						os.Setenv(models.EnvPusherName, results.UserName)
 | 
				
			||||||
 | 
						os.Setenv(models.EnvPusherEmail, results.UserEmail)
 | 
				
			||||||
	os.Setenv(models.EnvPusherID, strconv.FormatInt(results.UserID, 10))
 | 
						os.Setenv(models.EnvPusherID, strconv.FormatInt(results.UserID, 10))
 | 
				
			||||||
	os.Setenv(models.ProtectedBranchRepoID, strconv.FormatInt(results.RepoID, 10))
 | 
						os.Setenv(models.EnvRepoID, strconv.FormatInt(results.RepoID, 10))
 | 
				
			||||||
	os.Setenv(models.ProtectedBranchPRID, fmt.Sprintf("%d", 0))
 | 
						os.Setenv(models.EnvPRID, fmt.Sprintf("%d", 0))
 | 
				
			||||||
	os.Setenv(models.EnvIsDeployKey, fmt.Sprintf("%t", results.IsDeployKey))
 | 
						os.Setenv(models.EnvIsDeployKey, fmt.Sprintf("%t", results.IsDeployKey))
 | 
				
			||||||
	os.Setenv(models.EnvKeyID, fmt.Sprintf("%d", results.KeyID))
 | 
						os.Setenv(models.EnvKeyID, fmt.Sprintf("%d", results.KeyID))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,13 +19,6 @@ import (
 | 
				
			|||||||
	"github.com/unknwon/com"
 | 
						"github.com/unknwon/com"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					 | 
				
			||||||
	// ProtectedBranchRepoID protected Repo ID
 | 
					 | 
				
			||||||
	ProtectedBranchRepoID = "GITEA_REPO_ID"
 | 
					 | 
				
			||||||
	// ProtectedBranchPRID protected Repo PR ID
 | 
					 | 
				
			||||||
	ProtectedBranchPRID = "GITEA_PR_ID"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// ProtectedBranch struct
 | 
					// ProtectedBranch struct
 | 
				
			||||||
type ProtectedBranch struct {
 | 
					type ProtectedBranch struct {
 | 
				
			||||||
	ID                        int64  `xorm:"pk autoincr"`
 | 
						ID                        int64  `xorm:"pk autoincr"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,12 +14,14 @@ import (
 | 
				
			|||||||
const (
 | 
					const (
 | 
				
			||||||
	EnvRepoName     = "GITEA_REPO_NAME"
 | 
						EnvRepoName     = "GITEA_REPO_NAME"
 | 
				
			||||||
	EnvRepoUsername = "GITEA_REPO_USER_NAME"
 | 
						EnvRepoUsername = "GITEA_REPO_USER_NAME"
 | 
				
			||||||
 | 
						EnvRepoID       = "GITEA_REPO_ID"
 | 
				
			||||||
	EnvRepoIsWiki   = "GITEA_REPO_IS_WIKI"
 | 
						EnvRepoIsWiki   = "GITEA_REPO_IS_WIKI"
 | 
				
			||||||
	EnvPusherName   = "GITEA_PUSHER_NAME"
 | 
						EnvPusherName   = "GITEA_PUSHER_NAME"
 | 
				
			||||||
	EnvPusherEmail  = "GITEA_PUSHER_EMAIL"
 | 
						EnvPusherEmail  = "GITEA_PUSHER_EMAIL"
 | 
				
			||||||
	EnvPusherID     = "GITEA_PUSHER_ID"
 | 
						EnvPusherID     = "GITEA_PUSHER_ID"
 | 
				
			||||||
	EnvKeyID        = "GITEA_KEY_ID"
 | 
						EnvKeyID        = "GITEA_KEY_ID"
 | 
				
			||||||
	EnvIsDeployKey  = "GITEA_IS_DEPLOY_KEY"
 | 
						EnvIsDeployKey  = "GITEA_IS_DEPLOY_KEY"
 | 
				
			||||||
 | 
						EnvPRID         = "GITEA_PR_ID"
 | 
				
			||||||
	EnvIsInternal   = "GITEA_INTERNAL_PUSH"
 | 
						EnvIsInternal   = "GITEA_INTERNAL_PUSH"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -48,9 +50,7 @@ func FullPushingEnvironment(author, committer *User, repo *Repository, repoName
 | 
				
			|||||||
	authorSig := author.NewGitSig()
 | 
						authorSig := author.NewGitSig()
 | 
				
			||||||
	committerSig := committer.NewGitSig()
 | 
						committerSig := committer.NewGitSig()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// We should add "SSH_ORIGINAL_COMMAND=gitea-internal",
 | 
						environ := append(os.Environ(),
 | 
				
			||||||
	// once we have hook and pushing infrastructure working correctly
 | 
					 | 
				
			||||||
	return append(os.Environ(),
 | 
					 | 
				
			||||||
		"GIT_AUTHOR_NAME="+authorSig.Name,
 | 
							"GIT_AUTHOR_NAME="+authorSig.Name,
 | 
				
			||||||
		"GIT_AUTHOR_EMAIL="+authorSig.Email,
 | 
							"GIT_AUTHOR_EMAIL="+authorSig.Email,
 | 
				
			||||||
		"GIT_COMMITTER_NAME="+committerSig.Name,
 | 
							"GIT_COMMITTER_NAME="+committerSig.Name,
 | 
				
			||||||
@@ -60,9 +60,15 @@ func FullPushingEnvironment(author, committer *User, repo *Repository, repoName
 | 
				
			|||||||
		EnvRepoIsWiki+"="+isWiki,
 | 
							EnvRepoIsWiki+"="+isWiki,
 | 
				
			||||||
		EnvPusherName+"="+committer.Name,
 | 
							EnvPusherName+"="+committer.Name,
 | 
				
			||||||
		EnvPusherID+"="+fmt.Sprintf("%d", committer.ID),
 | 
							EnvPusherID+"="+fmt.Sprintf("%d", committer.ID),
 | 
				
			||||||
		ProtectedBranchRepoID+"="+fmt.Sprintf("%d", repo.ID),
 | 
							EnvRepoID+"="+fmt.Sprintf("%d", repo.ID),
 | 
				
			||||||
		ProtectedBranchPRID+"="+fmt.Sprintf("%d", prID),
 | 
							EnvPRID+"="+fmt.Sprintf("%d", prID),
 | 
				
			||||||
		"SSH_ORIGINAL_COMMAND=gitea-internal",
 | 
							"SSH_ORIGINAL_COMMAND=gitea-internal",
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !committer.KeepEmailPrivate {
 | 
				
			||||||
 | 
							environ = append(environ, EnvPusherEmail+"="+committer.Email)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return environ
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -47,6 +47,7 @@ type ServCommandResults struct {
 | 
				
			|||||||
	KeyID       int64
 | 
						KeyID       int64
 | 
				
			||||||
	KeyName     string
 | 
						KeyName     string
 | 
				
			||||||
	UserName    string
 | 
						UserName    string
 | 
				
			||||||
 | 
						UserEmail   string
 | 
				
			||||||
	UserID      int64
 | 
						UserID      int64
 | 
				
			||||||
	OwnerName   string
 | 
						OwnerName   string
 | 
				
			||||||
	RepoName    string
 | 
						RepoName    string
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -217,6 +217,18 @@ func ServCommand(ctx *macaron.Context) {
 | 
				
			|||||||
		// so for now use the owner of the repository
 | 
							// so for now use the owner of the repository
 | 
				
			||||||
		results.UserName = results.OwnerName
 | 
							results.UserName = results.OwnerName
 | 
				
			||||||
		results.UserID = repo.OwnerID
 | 
							results.UserID = repo.OwnerID
 | 
				
			||||||
 | 
							if err = repo.GetOwner(); err != nil {
 | 
				
			||||||
 | 
								log.Error("Unable to get owner for repo %-v. Error: %v", repo, err)
 | 
				
			||||||
 | 
								ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
 | 
				
			||||||
 | 
									"results": results,
 | 
				
			||||||
 | 
									"type":    "InternalServerError",
 | 
				
			||||||
 | 
									"err":     fmt.Sprintf("Unable to get owner for repo: %s/%s.", results.OwnerName, results.RepoName),
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if !repo.Owner.KeepEmailPrivate {
 | 
				
			||||||
 | 
								results.UserEmail = repo.Owner.Email
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		// Get the user represented by the Key
 | 
							// Get the user represented by the Key
 | 
				
			||||||
		var err error
 | 
							var err error
 | 
				
			||||||
@@ -239,6 +251,9 @@ func ServCommand(ctx *macaron.Context) {
 | 
				
			|||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		results.UserName = user.Name
 | 
							results.UserName = user.Name
 | 
				
			||||||
 | 
							if !user.KeepEmailPrivate {
 | 
				
			||||||
 | 
								results.UserEmail = user.Email
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Don't allow pushing if the repo is archived
 | 
						// Don't allow pushing if the repo is archived
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -323,7 +323,7 @@ func HTTP(ctx *context.Context) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	environ = append(environ, models.ProtectedBranchRepoID+fmt.Sprintf("=%d", repo.ID))
 | 
						environ = append(environ, models.EnvRepoID+fmt.Sprintf("=%d", repo.ID))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	w := ctx.Resp
 | 
						w := ctx.Resp
 | 
				
			||||||
	r := ctx.Req.Request
 | 
						r := ctx.Req.Request
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user