mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Move hooks function to gitrepo and reduce expose repopath (#33890)
Extract from #28966 Follow #33874
This commit is contained in:
@@ -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 {
|
@@ -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
|
||||
|
Reference in New Issue
Block a user