aboutsummaryrefslogtreecommitdiffstats
path: root/services/repository/hooks.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-06-06 16:01:49 +0800
committerGitHub <noreply@github.com>2022-06-06 16:01:49 +0800
commit26095115f4ae90e3fdc6ab695978efd16e317f75 (patch)
tree92ec1c7ff54e0a65f4f0662baa8c0244dd9f324b /services/repository/hooks.go
parentebeb6e7c71a0c763b52153f4eb427e7c5b89a95e (diff)
downloadgitea-26095115f4ae90e3fdc6ab695978efd16e317f75.tar.gz
gitea-26095115f4ae90e3fdc6ab695978efd16e317f75.zip
Move some repository related code into sub package (#19711)
* Move some repository related code into sub package * Move more repository functions out of models * Fix lint * Some performance optimization for webhooks and others * some refactors * Fix lint * Fix * Update modules/repository/delete.go Co-authored-by: delvh <dev.lh@web.de> * Fix test * Merge * Fix test * Fix test * Fix test * Fix test Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'services/repository/hooks.go')
-rw-r--r--services/repository/hooks.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/services/repository/hooks.go b/services/repository/hooks.go
index 67931ffcb6..45a031f38e 100644
--- a/services/repository/hooks.go
+++ b/services/repository/hooks.go
@@ -10,6 +10,7 @@ import (
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
+ "code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
repo_module "code.gitea.io/gitea/modules/repository"
@@ -84,3 +85,29 @@ func GenerateGitHooks(ctx context.Context, templateRepo, generateRepo *repo_mode
}
return nil
}
+
+// GenerateWebhooks generates webhooks from a template repository
+func GenerateWebhooks(ctx context.Context, templateRepo, generateRepo *repo_model.Repository) error {
+ templateWebhooks, err := webhook.ListWebhooksByOpts(ctx, &webhook.ListWebhookOptions{RepoID: templateRepo.ID})
+ if err != nil {
+ return err
+ }
+
+ ws := make([]*webhook.Webhook, 0, len(templateWebhooks))
+ for _, templateWebhook := range templateWebhooks {
+ ws = append(ws, &webhook.Webhook{
+ RepoID: generateRepo.ID,
+ URL: templateWebhook.URL,
+ HTTPMethod: templateWebhook.HTTPMethod,
+ ContentType: templateWebhook.ContentType,
+ Secret: templateWebhook.Secret,
+ HookEvent: templateWebhook.HookEvent,
+ IsActive: templateWebhook.IsActive,
+ Type: templateWebhook.Type,
+ OrgID: templateWebhook.OrgID,
+ Events: templateWebhook.Events,
+ Meta: templateWebhook.Meta,
+ })
+ }
+ return webhook.CreateWebhooks(ctx, ws)
+}