Skip to content

Commit d257485

Browse files
authored
Rename models.ProtectedBranchRepoID to models.EnvRepoID and ensure EnvPusherEmail is set (#12646)
Signed-off-by: Andrew Thornton <[email protected]>
1 parent 17fbbe9 commit d257485

File tree

7 files changed

+32
-16
lines changed

7 files changed

+32
-16
lines changed

cmd/hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Gitea or set your environment appropriately.`, "")
170170
username := os.Getenv(models.EnvRepoUsername)
171171
reponame := os.Getenv(models.EnvRepoName)
172172
userID, _ := strconv.ParseInt(os.Getenv(models.EnvPusherID), 10, 64)
173-
prID, _ := strconv.ParseInt(os.Getenv(models.ProtectedBranchPRID), 10, 64)
173+
prID, _ := strconv.ParseInt(os.Getenv(models.EnvPRID), 10, 64)
174174
isDeployKey, _ := strconv.ParseBool(os.Getenv(models.EnvIsDeployKey))
175175

176176
hookOptions := private.HookOptions{

cmd/serv.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,10 @@ func runServ(c *cli.Context) error {
206206
os.Setenv(models.EnvRepoName, results.RepoName)
207207
os.Setenv(models.EnvRepoUsername, results.OwnerName)
208208
os.Setenv(models.EnvPusherName, results.UserName)
209+
os.Setenv(models.EnvPusherEmail, results.UserEmail)
209210
os.Setenv(models.EnvPusherID, strconv.FormatInt(results.UserID, 10))
210-
os.Setenv(models.ProtectedBranchRepoID, strconv.FormatInt(results.RepoID, 10))
211-
os.Setenv(models.ProtectedBranchPRID, fmt.Sprintf("%d", 0))
211+
os.Setenv(models.EnvRepoID, strconv.FormatInt(results.RepoID, 10))
212+
os.Setenv(models.EnvPRID, fmt.Sprintf("%d", 0))
212213
os.Setenv(models.EnvIsDeployKey, fmt.Sprintf("%t", results.IsDeployKey))
213214
os.Setenv(models.EnvKeyID, fmt.Sprintf("%d", results.KeyID))
214215

models/branches.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ import (
1919
"github.com/unknwon/com"
2020
)
2121

22-
const (
23-
// ProtectedBranchRepoID protected Repo ID
24-
ProtectedBranchRepoID = "GITEA_REPO_ID"
25-
// ProtectedBranchPRID protected Repo PR ID
26-
ProtectedBranchPRID = "GITEA_PR_ID"
27-
)
28-
2922
// ProtectedBranch struct
3023
type ProtectedBranch struct {
3124
ID int64 `xorm:"pk autoincr"`

models/helper_environment.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ import (
1414
const (
1515
EnvRepoName = "GITEA_REPO_NAME"
1616
EnvRepoUsername = "GITEA_REPO_USER_NAME"
17+
EnvRepoID = "GITEA_REPO_ID"
1718
EnvRepoIsWiki = "GITEA_REPO_IS_WIKI"
1819
EnvPusherName = "GITEA_PUSHER_NAME"
1920
EnvPusherEmail = "GITEA_PUSHER_EMAIL"
2021
EnvPusherID = "GITEA_PUSHER_ID"
2122
EnvKeyID = "GITEA_KEY_ID"
2223
EnvIsDeployKey = "GITEA_IS_DEPLOY_KEY"
24+
EnvPRID = "GITEA_PR_ID"
2325
EnvIsInternal = "GITEA_INTERNAL_PUSH"
2426
)
2527

@@ -48,9 +50,7 @@ func FullPushingEnvironment(author, committer *User, repo *Repository, repoName
4850
authorSig := author.NewGitSig()
4951
committerSig := committer.NewGitSig()
5052

51-
// We should add "SSH_ORIGINAL_COMMAND=gitea-internal",
52-
// once we have hook and pushing infrastructure working correctly
53-
return append(os.Environ(),
53+
environ := append(os.Environ(),
5454
"GIT_AUTHOR_NAME="+authorSig.Name,
5555
"GIT_AUTHOR_EMAIL="+authorSig.Email,
5656
"GIT_COMMITTER_NAME="+committerSig.Name,
@@ -60,9 +60,15 @@ func FullPushingEnvironment(author, committer *User, repo *Repository, repoName
6060
EnvRepoIsWiki+"="+isWiki,
6161
EnvPusherName+"="+committer.Name,
6262
EnvPusherID+"="+fmt.Sprintf("%d", committer.ID),
63-
ProtectedBranchRepoID+"="+fmt.Sprintf("%d", repo.ID),
64-
ProtectedBranchPRID+"="+fmt.Sprintf("%d", prID),
63+
EnvRepoID+"="+fmt.Sprintf("%d", repo.ID),
64+
EnvPRID+"="+fmt.Sprintf("%d", prID),
6565
"SSH_ORIGINAL_COMMAND=gitea-internal",
6666
)
6767

68+
if !committer.KeepEmailPrivate {
69+
environ = append(environ, EnvPusherEmail+"="+committer.Email)
70+
}
71+
72+
return environ
73+
6874
}

modules/private/serv.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type ServCommandResults struct {
4747
KeyID int64
4848
KeyName string
4949
UserName string
50+
UserEmail string
5051
UserID int64
5152
OwnerName string
5253
RepoName string

routers/private/serv.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,18 @@ func ServCommand(ctx *macaron.Context) {
217217
// so for now use the owner of the repository
218218
results.UserName = results.OwnerName
219219
results.UserID = repo.OwnerID
220+
if err = repo.GetOwner(); err != nil {
221+
log.Error("Unable to get owner for repo %-v. Error: %v", repo, err)
222+
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
223+
"results": results,
224+
"type": "InternalServerError",
225+
"err": fmt.Sprintf("Unable to get owner for repo: %s/%s.", results.OwnerName, results.RepoName),
226+
})
227+
return
228+
}
229+
if !repo.Owner.KeepEmailPrivate {
230+
results.UserEmail = repo.Owner.Email
231+
}
220232
} else {
221233
// Get the user represented by the Key
222234
var err error
@@ -239,6 +251,9 @@ func ServCommand(ctx *macaron.Context) {
239251
return
240252
}
241253
results.UserName = user.Name
254+
if !user.KeepEmailPrivate {
255+
results.UserEmail = user.Email
256+
}
242257
}
243258

244259
// Don't allow pushing if the repo is archived

routers/repo/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ func HTTP(ctx *context.Context) {
323323
}
324324
}
325325

326-
environ = append(environ, models.ProtectedBranchRepoID+fmt.Sprintf("=%d", repo.ID))
326+
environ = append(environ, models.EnvRepoID+fmt.Sprintf("=%d", repo.ID))
327327

328328
w := ctx.Resp
329329
r := ctx.Req.Request

0 commit comments

Comments
 (0)