Create system webhook DB methods

Based on the default webhook ones
This commit is contained in:
James Lakin 2020-02-29 20:57:51 +00:00
parent 09dbd6be0d
commit 1decbb5b27

View file

@ -316,7 +316,7 @@ func GetWebhooksByOrgID(orgID int64, listOptions ListOptions) ([]*Webhook, error
func GetDefaultWebhook(id int64) (*Webhook, error) { func GetDefaultWebhook(id int64) (*Webhook, error) {
webhook := &Webhook{ID: id} webhook := &Webhook{ID: id}
has, err := x. has, err := x.
Where("repo_id=? AND org_id=?", 0, 0). Where("repo_id=? AND org_id=? AND is_system_webhook=?", 0, 0, 0).
Get(webhook) Get(webhook)
if err != nil { if err != nil {
return nil, err return nil, err
@ -334,7 +334,33 @@ func GetDefaultWebhooks() ([]*Webhook, error) {
func getDefaultWebhooks(e Engine) ([]*Webhook, error) { func getDefaultWebhooks(e Engine) ([]*Webhook, error) {
webhooks := make([]*Webhook, 0, 5) webhooks := make([]*Webhook, 0, 5)
return webhooks, e. return webhooks, e.
Where("repo_id=? AND org_id=?", 0, 0). Where("repo_id=? AND org_id=? AND is_system_webhook=?", 0, 0, 0).
Find(&webhooks)
}
// GetSystemWebhook returns admin system webhook by given ID.
func GetSystemWebhook(id int64) (*Webhook, error) {
webhook := &Webhook{ID: id}
has, err := x.
Where("repo_id=? AND org_id=? AND is_system_webhook=?", 0, 0, 1).
Get(webhook)
if err != nil {
return nil, err
} else if !has {
return nil, ErrWebhookNotExist{id}
}
return webhook, nil
}
// GetSystemWebhooks returns all admin system webhooks.
func GetSystemWebhooks() ([]*Webhook, error) {
return getSystemWebhooks(x)
}
func getSystemWebhooks(e Engine) ([]*Webhook, error) {
webhooks := make([]*Webhook, 0, 5)
return webhooks, e.
Where("repo_id=? AND org_id=? AND is_system_webhook=?", 0, 0, 1).
Find(&webhooks) Find(&webhooks)
} }
@ -395,7 +421,7 @@ func DeleteDefaultWebhook(id int64) error {
} }
count, err := sess. count, err := sess.
Where("repo_id=? AND org_id=?", 0, 0). Where("repo_id=? AND org_id=? AND is_system_webhook=?", 0, 0, 0).
Delete(&Webhook{ID: id}) Delete(&Webhook{ID: id})
if err != nil { if err != nil {
return err return err