aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-05-09 00:46:32 +0800
committerGitHub <noreply@github.com>2022-05-08 18:46:32 +0200
commit4ca1d7547a2c32cc65ca23d1a7698d1a8c921d65 (patch)
treefee132403adea441987ce25809c764e00fd962cd /cmd
parentd4834071da9ce010fd4677ef339c598dd23dc130 (diff)
downloadgitea-4ca1d7547a2c32cc65ca23d1a7698d1a8c921d65.tar.gz
gitea-4ca1d7547a2c32cc65ca23d1a7698d1a8c921d65.zip
Move some helper files out of models (#19355)
* Move some helper files out of models * Some improvements Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/hook.go36
-rw-r--r--cmd/serv.go23
2 files changed, 30 insertions, 29 deletions
diff --git a/cmd/hook.go b/cmd/hook.go
index 2b62b61ca6..8078763b18 100644
--- a/cmd/hook.go
+++ b/cmd/hook.go
@@ -15,9 +15,9 @@ import (
"strings"
"time"
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/private"
+ repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
@@ -162,7 +162,7 @@ func (n *nilWriter) WriteString(s string) (int, error) {
}
func runHookPreReceive(c *cli.Context) error {
- if os.Getenv(models.EnvIsInternal) == "true" {
+ if isInternal, _ := strconv.ParseBool(os.Getenv(repo_module.EnvIsInternal)); isInternal {
return nil
}
ctx, cancel := installSignals()
@@ -180,12 +180,12 @@ Gitea or set your environment appropriately.`, "")
}
// the environment is set by serv command
- isWiki := os.Getenv(models.EnvRepoIsWiki) == "true"
- username := os.Getenv(models.EnvRepoUsername)
- reponame := os.Getenv(models.EnvRepoName)
- userID, _ := strconv.ParseInt(os.Getenv(models.EnvPusherID), 10, 64)
- prID, _ := strconv.ParseInt(os.Getenv(models.EnvPRID), 10, 64)
- deployKeyID, _ := strconv.ParseInt(os.Getenv(models.EnvDeployKeyID), 10, 64)
+ isWiki, _ := strconv.ParseBool(os.Getenv(repo_module.EnvRepoIsWiki))
+ username := os.Getenv(repo_module.EnvRepoUsername)
+ reponame := os.Getenv(repo_module.EnvRepoName)
+ userID, _ := strconv.ParseInt(os.Getenv(repo_module.EnvPusherID), 10, 64)
+ prID, _ := strconv.ParseInt(os.Getenv(repo_module.EnvPRID), 10, 64)
+ deployKeyID, _ := strconv.ParseInt(os.Getenv(repo_module.EnvDeployKeyID), 10, 64)
hookOptions := private.HookOptions{
UserID: userID,
@@ -314,7 +314,7 @@ func runHookPostReceive(c *cli.Context) error {
}
// Now if we're an internal don't do anything else
- if os.Getenv(models.EnvIsInternal) == "true" {
+ if isInternal, _ := strconv.ParseBool(os.Getenv(repo_module.EnvIsInternal)); isInternal {
return nil
}
@@ -343,11 +343,11 @@ Gitea or set your environment appropriately.`, "")
}
// the environment is set by serv command
- repoUser := os.Getenv(models.EnvRepoUsername)
- isWiki := os.Getenv(models.EnvRepoIsWiki) == "true"
- repoName := os.Getenv(models.EnvRepoName)
- pusherID, _ := strconv.ParseInt(os.Getenv(models.EnvPusherID), 10, 64)
- pusherName := os.Getenv(models.EnvPusherName)
+ repoUser := os.Getenv(repo_module.EnvRepoUsername)
+ isWiki, _ := strconv.ParseBool(os.Getenv(repo_module.EnvRepoIsWiki))
+ repoName := os.Getenv(repo_module.EnvRepoName)
+ pusherID, _ := strconv.ParseInt(os.Getenv(repo_module.EnvPusherID), 10, 64)
+ pusherName := os.Getenv(repo_module.EnvPusherName)
hookOptions := private.HookOptions{
UserName: pusherName,
@@ -503,10 +503,10 @@ Gitea or set your environment appropriately.`, "")
}
reader := bufio.NewReader(os.Stdin)
- repoUser := os.Getenv(models.EnvRepoUsername)
- repoName := os.Getenv(models.EnvRepoName)
- pusherID, _ := strconv.ParseInt(os.Getenv(models.EnvPusherID), 10, 64)
- pusherName := os.Getenv(models.EnvPusherName)
+ repoUser := os.Getenv(repo_module.EnvRepoUsername)
+ repoName := os.Getenv(repo_module.EnvRepoName)
+ pusherID, _ := strconv.ParseInt(os.Getenv(repo_module.EnvPusherID), 10, 64)
+ pusherName := os.Getenv(repo_module.EnvPusherName)
// 1. Version and features negotiation.
// S: PKT-LINE(version=1\0push-options atomic...) / PKT-LINE(version=1\n)
diff --git a/cmd/serv.go b/cmd/serv.go
index b106d40d28..340f591dce 100644
--- a/cmd/serv.go
+++ b/cmd/serv.go
@@ -24,6 +24,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/pprof"
"code.gitea.io/gitea/modules/private"
+ repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/services/lfs"
@@ -235,17 +236,17 @@ func runServ(c *cli.Context) error {
}
return fail("Internal Server Error", "%s", err.Error())
}
- os.Setenv(models.EnvRepoIsWiki, strconv.FormatBool(results.IsWiki))
- os.Setenv(models.EnvRepoName, results.RepoName)
- os.Setenv(models.EnvRepoUsername, results.OwnerName)
- os.Setenv(models.EnvPusherName, results.UserName)
- os.Setenv(models.EnvPusherEmail, results.UserEmail)
- os.Setenv(models.EnvPusherID, strconv.FormatInt(results.UserID, 10))
- os.Setenv(models.EnvRepoID, strconv.FormatInt(results.RepoID, 10))
- os.Setenv(models.EnvPRID, fmt.Sprintf("%d", 0))
- os.Setenv(models.EnvDeployKeyID, fmt.Sprintf("%d", results.DeployKeyID))
- os.Setenv(models.EnvKeyID, fmt.Sprintf("%d", results.KeyID))
- os.Setenv(models.EnvAppURL, setting.AppURL)
+ os.Setenv(repo_module.EnvRepoIsWiki, strconv.FormatBool(results.IsWiki))
+ os.Setenv(repo_module.EnvRepoName, results.RepoName)
+ os.Setenv(repo_module.EnvRepoUsername, results.OwnerName)
+ os.Setenv(repo_module.EnvPusherName, results.UserName)
+ os.Setenv(repo_module.EnvPusherEmail, results.UserEmail)
+ os.Setenv(repo_module.EnvPusherID, strconv.FormatInt(results.UserID, 10))
+ os.Setenv(repo_module.EnvRepoID, strconv.FormatInt(results.RepoID, 10))
+ os.Setenv(repo_module.EnvPRID, fmt.Sprintf("%d", 0))
+ os.Setenv(repo_module.EnvDeployKeyID, fmt.Sprintf("%d", results.DeployKeyID))
+ os.Setenv(repo_module.EnvKeyID, fmt.Sprintf("%d", results.KeyID))
+ os.Setenv(repo_module.EnvAppURL, setting.AppURL)
// LFS token authentication
if verb == lfsAuthenticateVerb {