aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2025-03-16 09:12:55 -0700
committerGitHub <noreply@github.com>2025-03-16 16:12:55 +0000
commit7fd44a85ca8e2614df1fcacc5409322a6b83fe62 (patch)
treed2a676be3ab279726c4817cb1a769bec358d0a51 /modules
parent1ea5216f4a5887e585bf7de12b62cfec83b0f4e3 (diff)
downloadgitea-7fd44a85ca8e2614df1fcacc5409322a6b83fe62.tar.gz
gitea-7fd44a85ca8e2614df1fcacc5409322a6b83fe62.zip
Move hooks function to gitrepo and reduce expose repopath (#33890)
Extract from #28966 Follow #33874
Diffstat (limited to 'modules')
-rw-r--r--modules/gitrepo/hooks.go (renamed from modules/repository/hooks.go)31
-rw-r--r--modules/repository/init.go2
2 files changed, 25 insertions, 8 deletions
diff --git a/modules/repository/hooks.go b/modules/gitrepo/hooks.go
index 95849789ab..cf44f792c6 100644
--- a/modules/repository/hooks.go
+++ b/modules/gitrepo/hooks.go
@@ -1,9 +1,10 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
-package repository
+package gitrepo
import (
+ "context"
"fmt"
"os"
"path/filepath"
@@ -105,10 +106,18 @@ done
return hookNames, hookTpls, giteaHookTpls
}
-// CreateDelegateHooks creates all the hooks scripts for the repo
-func CreateDelegateHooks(repoPath string) (err error) {
+// CreateDelegateHooksForRepo creates all the hooks scripts for the repo
+func CreateDelegateHooksForRepo(_ context.Context, repo Repository) (err error) {
+ return createDelegateHooks(filepath.Join(repoPath(repo), "hooks"))
+}
+
+// CreateDelegateHooksForWiki creates all the hooks scripts for the wiki repo
+func CreateDelegateHooksForWiki(_ context.Context, repo Repository) (err error) {
+ return createDelegateHooks(filepath.Join(wikiPath(repo), "hooks"))
+}
+
+func createDelegateHooks(hookDir string) (err error) {
hookNames, hookTpls, giteaHookTpls := getHookTemplates()
- hookDir := filepath.Join(repoPath, "hooks")
for i, hookName := range hookNames {
oldHookPath := filepath.Join(hookDir, hookName)
@@ -169,11 +178,19 @@ func ensureExecutable(filename string) error {
return os.Chmod(filename, mode)
}
-// CheckDelegateHooks checks the hooks scripts for the repo
-func CheckDelegateHooks(repoPath string) ([]string, error) {
+// CheckDelegateHooksForRepo checks the hooks scripts for the repo
+func CheckDelegateHooksForRepo(_ context.Context, repo Repository) ([]string, error) {
+ return checkDelegateHooks(filepath.Join(repoPath(repo), "hooks"))
+}
+
+// CheckDelegateHooksForWiki checks the hooks scripts for the repo
+func CheckDelegateHooksForWiki(_ context.Context, repo Repository) ([]string, error) {
+ return checkDelegateHooks(filepath.Join(wikiPath(repo), "hooks"))
+}
+
+func checkDelegateHooks(hookDir string) ([]string, error) {
hookNames, hookTpls, giteaHookTpls := getHookTemplates()
- hookDir := filepath.Join(repoPath, "hooks")
results := make([]string, 0, 10)
for i, hookName := range hookNames {
diff --git a/modules/repository/init.go b/modules/repository/init.go
index 772ae3efe3..3fc1261baa 100644
--- a/modules/repository/init.go
+++ b/modules/repository/init.go
@@ -138,7 +138,7 @@ func CheckInitRepository(ctx context.Context, repo *repo_model.Repository) (err
// Init git bare new repository.
if err = git.InitRepository(ctx, repo.RepoPath(), true, repo.ObjectFormatName); err != nil {
return fmt.Errorf("git.InitRepository: %w", err)
- } else if err = CreateDelegateHooks(repo.RepoPath()); err != nil {
+ } else if err = gitrepo.CreateDelegateHooksForRepo(ctx, repo); err != nil {
return fmt.Errorf("createDelegateHooks: %w", err)
}
return nil