Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

System-wide webhooks #10546

Merged
merged 19 commits into from
Mar 8, 2020
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Create system webhook DB methods
Based on the default webhook ones
  • Loading branch information
jamesorlakin committed Mar 1, 2020
commit 1decbb5b2764f700f393d0f69d1bc237ed0f0731
32 changes: 29 additions & 3 deletions models/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
jamesorlakin marked this conversation as resolved.
Show resolved Hide resolved
Get(webhook)
if err != nil {
return nil, err
Expand All @@ -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).
jamesorlakin marked this conversation as resolved.
Show resolved Hide resolved
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).
jamesorlakin marked this conversation as resolved.
Show resolved Hide resolved
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).
jamesorlakin marked this conversation as resolved.
Show resolved Hide resolved
Find(&webhooks)
}

Expand Down Expand Up @@ -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).
jamesorlakin marked this conversation as resolved.
Show resolved Hide resolved
Delete(&Webhook{ID: id})
if err != nil {
return err
Expand Down