diff options
author | Ethan Koenig <etk39@cornell.edu> | 2017-01-25 05:37:35 -0500 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-01-25 18:37:35 +0800 |
commit | 0934d1b1ea4f3cab5af5555116ae13a87c65f34c (patch) | |
tree | 8d05aa5b330f2a33f50313881e5dee0815d43815 /models/webhook.go | |
parent | a6832c234d5c73cfa00cb4a926f446e0b14b9732 (diff) | |
download | gitea-0934d1b1ea4f3cab5af5555116ae13a87c65f34c.tar.gz gitea-0934d1b1ea4f3cab5af5555116ae13a87c65f34c.zip |
Bug fixes and unit tests for models/webhook (#751)
Diffstat (limited to 'models/webhook.go')
-rw-r--r-- | models/webhook.go | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/models/webhook.go b/models/webhook.go index 8f5c561939..4dd10b0c79 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -231,10 +231,8 @@ func GetWebhookByOrgID(orgID, id int64) (*Webhook, error) { // GetActiveWebhooksByRepoID returns all active webhooks of repository. func GetActiveWebhooksByRepoID(repoID int64) ([]*Webhook, error) { webhooks := make([]*Webhook, 0, 5) - return webhooks, x.Find(&webhooks, &Webhook{ - RepoID: repoID, - IsActive: true, - }) + return webhooks, x.Where("is_active=?", true). + Find(&webhooks, &Webhook{RepoID: repoID}) } // GetWebhooksByRepoID returns all webhooks of a repository. @@ -243,6 +241,21 @@ func GetWebhooksByRepoID(repoID int64) ([]*Webhook, error) { return webhooks, x.Find(&webhooks, &Webhook{RepoID: repoID}) } +// GetActiveWebhooksByOrgID returns all active webhooks for an organization. +func GetActiveWebhooksByOrgID(orgID int64) (ws []*Webhook, err error) { + err = x. + Where("org_id=?", orgID). + And("is_active=?", true). + Find(&ws) + return ws, err +} + +// GetWebhooksByOrgID returns all webhooks for an organization. +func GetWebhooksByOrgID(orgID int64) (ws []*Webhook, err error) { + err = x.Find(&ws, &Webhook{OrgID: orgID}) + return ws, err +} + // UpdateWebhook updates information of webhook. func UpdateWebhook(w *Webhook) error { _, err := x.Id(w.ID).AllCols().Update(w) @@ -285,21 +298,6 @@ func DeleteWebhookByOrgID(orgID, id int64) error { }) } -// GetWebhooksByOrgID returns all webhooks for an organization. -func GetWebhooksByOrgID(orgID int64) (ws []*Webhook, err error) { - err = x.Find(&ws, &Webhook{OrgID: orgID}) - return ws, err -} - -// GetActiveWebhooksByOrgID returns all active webhooks for an organization. -func GetActiveWebhooksByOrgID(orgID int64) (ws []*Webhook, err error) { - err = x. - Where("org_id=?", orgID). - And("is_active=?", true). - Find(&ws) - return ws, err -} - // ___ ___ __ ___________ __ // / | \ ____ ____ | | _\__ ___/____ _____| | __ // / ~ \/ _ \ / _ \| |/ / | | \__ \ / ___/ |/ / @@ -505,7 +503,7 @@ func PrepareWebhooks(repo *Repository, event HookEventType, p api.Payloader) err } } - // Use separate objects so modifcations won't be made on payload on non-Gogs type hooks. + // Use separate objects so modifications won't be made on payload on non-Gogs type hooks. switch w.HookTaskType { case SLACK: payloader, err = GetSlackPayload(p, event, w.Meta) |