|
@@ -21,12 +21,12 @@ import (
|
|
|
|
|
|
"github.com/gogs/git-module"
|
|
|
|
|
|
- "gogs.io/gogs/models"
|
|
|
- "gogs.io/gogs/models/errors"
|
|
|
- "gogs.io/gogs/pkg/httplib"
|
|
|
- "gogs.io/gogs/pkg/mailer"
|
|
|
- "gogs.io/gogs/pkg/setting"
|
|
|
- "gogs.io/gogs/pkg/template"
|
|
|
+ "gogs.io/gogs/internal/db"
|
|
|
+ "gogs.io/gogs/internal/db/errors"
|
|
|
+ "gogs.io/gogs/internal/httplib"
|
|
|
+ "gogs.io/gogs/internal/mailer"
|
|
|
+ "gogs.io/gogs/internal/setting"
|
|
|
+ "gogs.io/gogs/internal/template"
|
|
|
)
|
|
|
|
|
|
var (
|
|
@@ -70,7 +70,7 @@ func runHookPreReceive(c *cli.Context) error {
|
|
|
}
|
|
|
setup(c, "hooks/pre-receive.log", true)
|
|
|
|
|
|
- isWiki := strings.Contains(os.Getenv(models.ENV_REPO_CUSTOM_HOOKS_PATH), ".wiki.git/")
|
|
|
+ isWiki := strings.Contains(os.Getenv(db.ENV_REPO_CUSTOM_HOOKS_PATH), ".wiki.git/")
|
|
|
|
|
|
buf := bytes.NewBuffer(nil)
|
|
|
scanner := bufio.NewScanner(os.Stdin)
|
|
@@ -91,8 +91,8 @@ func runHookPreReceive(c *cli.Context) error {
|
|
|
branchName := strings.TrimPrefix(string(fields[2]), git.BRANCH_PREFIX)
|
|
|
|
|
|
// Branch protection
|
|
|
- repoID := com.StrTo(os.Getenv(models.ENV_REPO_ID)).MustInt64()
|
|
|
- protectBranch, err := models.GetProtectBranchOfRepoByName(repoID, branchName)
|
|
|
+ repoID := com.StrTo(os.Getenv(db.ENV_REPO_ID)).MustInt64()
|
|
|
+ protectBranch, err := db.GetProtectBranchOfRepoByName(repoID, branchName)
|
|
|
if err != nil {
|
|
|
if errors.IsErrBranchNotExist(err) {
|
|
|
continue
|
|
@@ -107,9 +107,9 @@ func runHookPreReceive(c *cli.Context) error {
|
|
|
bypassRequirePullRequest := false
|
|
|
|
|
|
// Check if user is in whitelist when enabled
|
|
|
- userID := com.StrTo(os.Getenv(models.ENV_AUTH_USER_ID)).MustInt64()
|
|
|
+ userID := com.StrTo(os.Getenv(db.ENV_AUTH_USER_ID)).MustInt64()
|
|
|
if protectBranch.EnableWhitelist {
|
|
|
- if !models.IsUserInProtectBranchWhitelist(repoID, userID, branchName) {
|
|
|
+ if !db.IsUserInProtectBranchWhitelist(repoID, userID, branchName) {
|
|
|
fail(fmt.Sprintf("Branch '%s' is protected and you are not in the push whitelist", branchName), "")
|
|
|
}
|
|
|
|
|
@@ -128,7 +128,7 @@ func runHookPreReceive(c *cli.Context) error {
|
|
|
|
|
|
// Check force push
|
|
|
output, err := git.NewCommand("rev-list", "--max-count=1", oldCommitID, "^"+newCommitID).
|
|
|
- RunInDir(models.RepoPath(os.Getenv(models.ENV_REPO_OWNER_NAME), os.Getenv(models.ENV_REPO_NAME)))
|
|
|
+ RunInDir(db.RepoPath(os.Getenv(db.ENV_REPO_OWNER_NAME), os.Getenv(db.ENV_REPO_NAME)))
|
|
|
if err != nil {
|
|
|
fail("Internal error", "Fail to detect force push: %v", err)
|
|
|
} else if len(output) > 0 {
|
|
@@ -136,7 +136,7 @@ func runHookPreReceive(c *cli.Context) error {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- customHooksPath := filepath.Join(os.Getenv(models.ENV_REPO_CUSTOM_HOOKS_PATH), "pre-receive")
|
|
|
+ customHooksPath := filepath.Join(os.Getenv(db.ENV_REPO_CUSTOM_HOOKS_PATH), "pre-receive")
|
|
|
if !com.IsFile(customHooksPath) {
|
|
|
return nil
|
|
|
}
|
|
@@ -147,7 +147,7 @@ func runHookPreReceive(c *cli.Context) error {
|
|
|
} else {
|
|
|
hookCmd = exec.Command(customHooksPath)
|
|
|
}
|
|
|
- hookCmd.Dir = models.RepoPath(os.Getenv(models.ENV_REPO_OWNER_NAME), os.Getenv(models.ENV_REPO_NAME))
|
|
|
+ hookCmd.Dir = db.RepoPath(os.Getenv(db.ENV_REPO_OWNER_NAME), os.Getenv(db.ENV_REPO_NAME))
|
|
|
hookCmd.Stdout = os.Stdout
|
|
|
hookCmd.Stdin = buf
|
|
|
hookCmd.Stderr = os.Stderr
|
|
@@ -170,7 +170,7 @@ func runHookUpdate(c *cli.Context) error {
|
|
|
fail("First argument 'refName' is empty", "First argument 'refName' is empty")
|
|
|
}
|
|
|
|
|
|
- customHooksPath := filepath.Join(os.Getenv(models.ENV_REPO_CUSTOM_HOOKS_PATH), "update")
|
|
|
+ customHooksPath := filepath.Join(os.Getenv(db.ENV_REPO_CUSTOM_HOOKS_PATH), "update")
|
|
|
if !com.IsFile(customHooksPath) {
|
|
|
return nil
|
|
|
}
|
|
@@ -181,7 +181,7 @@ func runHookUpdate(c *cli.Context) error {
|
|
|
} else {
|
|
|
hookCmd = exec.Command(customHooksPath, args...)
|
|
|
}
|
|
|
- hookCmd.Dir = models.RepoPath(os.Getenv(models.ENV_REPO_OWNER_NAME), os.Getenv(models.ENV_REPO_NAME))
|
|
|
+ hookCmd.Dir = db.RepoPath(os.Getenv(db.ENV_REPO_OWNER_NAME), os.Getenv(db.ENV_REPO_NAME))
|
|
|
hookCmd.Stdout = os.Stdout
|
|
|
hookCmd.Stdin = os.Stdin
|
|
|
hookCmd.Stderr = os.Stderr
|
|
@@ -204,7 +204,7 @@ func runHookPostReceive(c *cli.Context) error {
|
|
|
mailer.InitMailRender(path.Join(setting.StaticRootPath, "templates/mail"),
|
|
|
path.Join(setting.CustomPath, "templates/mail"), template.NewFuncMap())
|
|
|
|
|
|
- isWiki := strings.Contains(os.Getenv(models.ENV_REPO_CUSTOM_HOOKS_PATH), ".wiki.git/")
|
|
|
+ isWiki := strings.Contains(os.Getenv(db.ENV_REPO_CUSTOM_HOOKS_PATH), ".wiki.git/")
|
|
|
|
|
|
buf := bytes.NewBuffer(nil)
|
|
|
scanner := bufio.NewScanner(os.Stdin)
|
|
@@ -222,24 +222,24 @@ func runHookPostReceive(c *cli.Context) error {
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
- options := models.PushUpdateOptions{
|
|
|
+ options := db.PushUpdateOptions{
|
|
|
OldCommitID: string(fields[0]),
|
|
|
NewCommitID: string(fields[1]),
|
|
|
RefFullName: string(fields[2]),
|
|
|
- PusherID: com.StrTo(os.Getenv(models.ENV_AUTH_USER_ID)).MustInt64(),
|
|
|
- PusherName: os.Getenv(models.ENV_AUTH_USER_NAME),
|
|
|
- RepoUserName: os.Getenv(models.ENV_REPO_OWNER_NAME),
|
|
|
- RepoName: os.Getenv(models.ENV_REPO_NAME),
|
|
|
+ PusherID: com.StrTo(os.Getenv(db.ENV_AUTH_USER_ID)).MustInt64(),
|
|
|
+ PusherName: os.Getenv(db.ENV_AUTH_USER_NAME),
|
|
|
+ RepoUserName: os.Getenv(db.ENV_REPO_OWNER_NAME),
|
|
|
+ RepoName: os.Getenv(db.ENV_REPO_NAME),
|
|
|
}
|
|
|
- if err := models.PushUpdate(options); err != nil {
|
|
|
+ if err := db.PushUpdate(options); err != nil {
|
|
|
log.Error(2, "PushUpdate: %v", err)
|
|
|
}
|
|
|
|
|
|
// Ask for running deliver hook and test pull request tasks
|
|
|
reqURL := setting.LocalURL + options.RepoUserName + "/" + options.RepoName + "/tasks/trigger?branch=" +
|
|
|
template.EscapePound(strings.TrimPrefix(options.RefFullName, git.BRANCH_PREFIX)) +
|
|
|
- "&secret=" + os.Getenv(models.ENV_REPO_OWNER_SALT_MD5) +
|
|
|
- "&pusher=" + os.Getenv(models.ENV_AUTH_USER_ID)
|
|
|
+ "&secret=" + os.Getenv(db.ENV_REPO_OWNER_SALT_MD5) +
|
|
|
+ "&pusher=" + os.Getenv(db.ENV_AUTH_USER_ID)
|
|
|
log.Trace("Trigger task: %s", reqURL)
|
|
|
|
|
|
resp, err := httplib.Head(reqURL).SetTLSClientConfig(&tls.Config{
|
|
@@ -255,7 +255,7 @@ func runHookPostReceive(c *cli.Context) error {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- customHooksPath := filepath.Join(os.Getenv(models.ENV_REPO_CUSTOM_HOOKS_PATH), "post-receive")
|
|
|
+ customHooksPath := filepath.Join(os.Getenv(db.ENV_REPO_CUSTOM_HOOKS_PATH), "post-receive")
|
|
|
if !com.IsFile(customHooksPath) {
|
|
|
return nil
|
|
|
}
|
|
@@ -266,7 +266,7 @@ func runHookPostReceive(c *cli.Context) error {
|
|
|
} else {
|
|
|
hookCmd = exec.Command(customHooksPath)
|
|
|
}
|
|
|
- hookCmd.Dir = models.RepoPath(os.Getenv(models.ENV_REPO_OWNER_NAME), os.Getenv(models.ENV_REPO_NAME))
|
|
|
+ hookCmd.Dir = db.RepoPath(os.Getenv(db.ENV_REPO_OWNER_NAME), os.Getenv(db.ENV_REPO_NAME))
|
|
|
hookCmd.Stdout = os.Stdout
|
|
|
hookCmd.Stdin = buf
|
|
|
hookCmd.Stderr = os.Stderr
|