aboutsummaryrefslogtreecommitdiffstats
path: root/services/repository/hooks.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-11-17 23:17:31 +0800
committerGitHub <noreply@github.com>2021-11-17 23:17:31 +0800
commit5233051e64e90238bb7b6ddf9ecd1513e57bf8e9 (patch)
tree6e21565fd47954877bc14fd66f57d798c86e3300 /services/repository/hooks.go
parent750a8465f547e9f08a87612c75898d56b8ec1f88 (diff)
downloadgitea-5233051e64e90238bb7b6ddf9ecd1513e57bf8e9.tar.gz
gitea-5233051e64e90238bb7b6ddf9ecd1513e57bf8e9.zip
Move some functions into services/repository (#17677)
Diffstat (limited to 'services/repository/hooks.go')
-rw-r--r--services/repository/hooks.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/services/repository/hooks.go b/services/repository/hooks.go
new file mode 100644
index 0000000000..a50853f6af
--- /dev/null
+++ b/services/repository/hooks.go
@@ -0,0 +1,52 @@
+// Copyright 2021 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package repository
+
+import (
+ "context"
+ "fmt"
+
+ "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/modules/log"
+ repo_module "code.gitea.io/gitea/modules/repository"
+
+ "xorm.io/builder"
+)
+
+// SyncRepositoryHooks rewrites all repositories' pre-receive, update and post-receive hooks
+// to make sure the binary and custom conf path are up-to-date.
+func SyncRepositoryHooks(ctx context.Context) error {
+ log.Trace("Doing: SyncRepositoryHooks")
+
+ if err := db.Iterate(
+ db.DefaultContext,
+ new(models.Repository),
+ builder.Gt{"id": 0},
+ func(idx int, bean interface{}) error {
+ repo := bean.(*models.Repository)
+ select {
+ case <-ctx.Done():
+ return db.ErrCancelledf("before sync repository hooks for %s", repo.FullName())
+ default:
+ }
+
+ if err := repo_module.CreateDelegateHooks(repo.RepoPath()); err != nil {
+ return fmt.Errorf("SyncRepositoryHook: %v", err)
+ }
+ if repo.HasWiki() {
+ if err := repo_module.CreateDelegateHooks(repo.WikiPath()); err != nil {
+ return fmt.Errorf("SyncRepositoryHook: %v", err)
+ }
+ }
+ return nil
+ },
+ ); err != nil {
+ return err
+ }
+
+ log.Trace("Finished: SyncRepositoryHooks")
+ return nil
+}