mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-09 03:11:51 +01:00
Create system webhook DB methods
Based on the default webhook ones
This commit is contained in:
parent
09dbd6be0d
commit
1decbb5b27
1 changed files with 29 additions and 3 deletions
|
@ -316,7 +316,7 @@ func GetWebhooksByOrgID(orgID int64, listOptions ListOptions) ([]*Webhook, error
|
|||
func GetDefaultWebhook(id int64) (*Webhook, error) {
|
||||
webhook := &Webhook{ID: id}
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -334,7 +334,33 @@ func GetDefaultWebhooks() ([]*Webhook, error) {
|
|||
func getDefaultWebhooks(e Engine) ([]*Webhook, error) {
|
||||
webhooks := make([]*Webhook, 0, 5)
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -395,7 +421,7 @@ func DeleteDefaultWebhook(id int64) error {
|
|||
}
|
||||
|
||||
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})
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in a new issue