diff options
Diffstat (limited to 'models/webhook/webhook.go')
-rw-r--r-- | models/webhook/webhook.go | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/models/webhook/webhook.go b/models/webhook/webhook.go index 941a3f15c7..5eea977725 100644 --- a/models/webhook/webhook.go +++ b/models/webhook/webhook.go @@ -454,8 +454,9 @@ func (opts *ListWebhookOptions) toCond() builder.Cond { return cond } -func listWebhooksByOpts(e db.Engine, opts *ListWebhookOptions) ([]*Webhook, error) { - sess := e.Where(opts.toCond()) +// ListWebhooksByOpts return webhooks based on options +func ListWebhooksByOpts(ctx context.Context, opts *ListWebhookOptions) ([]*Webhook, error) { + sess := db.GetEngine(ctx).Where(opts.toCond()) if opts.Page != 0 { sess = db.SetSessionPagination(sess, opts) @@ -469,22 +470,13 @@ func listWebhooksByOpts(e db.Engine, opts *ListWebhookOptions) ([]*Webhook, erro return webhooks, err } -// ListWebhooksByOpts return webhooks based on options -func ListWebhooksByOpts(opts *ListWebhookOptions) ([]*Webhook, error) { - return listWebhooksByOpts(db.GetEngine(db.DefaultContext), opts) -} - // CountWebhooksByOpts count webhooks based on options and ignore pagination func CountWebhooksByOpts(opts *ListWebhookOptions) (int64, error) { return db.GetEngine(db.DefaultContext).Where(opts.toCond()).Count(&Webhook{}) } // GetDefaultWebhooks returns all admin-default webhooks. -func GetDefaultWebhooks() ([]*Webhook, error) { - return getDefaultWebhooks(db.DefaultContext) -} - -func getDefaultWebhooks(ctx context.Context) ([]*Webhook, error) { +func GetDefaultWebhooks(ctx context.Context) ([]*Webhook, error) { webhooks := make([]*Webhook, 0, 5) return webhooks, db.GetEngine(ctx). Where("repo_id=? AND org_id=? AND is_system_webhook=?", 0, 0, false). @@ -506,18 +498,14 @@ func GetSystemOrDefaultWebhook(id int64) (*Webhook, error) { } // GetSystemWebhooks returns all admin system webhooks. -func GetSystemWebhooks(isActive util.OptionalBool) ([]*Webhook, error) { - return getSystemWebhooks(db.GetEngine(db.DefaultContext), isActive) -} - -func getSystemWebhooks(e db.Engine, isActive util.OptionalBool) ([]*Webhook, error) { +func GetSystemWebhooks(ctx context.Context, isActive util.OptionalBool) ([]*Webhook, error) { webhooks := make([]*Webhook, 0, 5) if isActive.IsNone() { - return webhooks, e. + return webhooks, db.GetEngine(ctx). Where("repo_id=? AND org_id=? AND is_system_webhook=?", 0, 0, true). Find(&webhooks) } - return webhooks, e. + return webhooks, db.GetEngine(ctx). Where("repo_id=? AND org_id=? AND is_system_webhook=? AND is_active = ?", 0, 0, true, isActive.IsTrue()). Find(&webhooks) } @@ -596,7 +584,7 @@ func DeleteDefaultSystemWebhook(id int64) error { // CopyDefaultWebhooksToRepo creates copies of the default webhooks in a new repo func CopyDefaultWebhooksToRepo(ctx context.Context, repoID int64) error { - ws, err := getDefaultWebhooks(ctx) + ws, err := GetDefaultWebhooks(ctx) if err != nil { return fmt.Errorf("GetDefaultWebhooks: %v", err) } |