Bug fixes and unit tests for models/webhook (#751)

This commit is contained in:
Ethan Koenig 2017-01-25 05:37:35 -05:00 committed by Lunny Xiao
parent a6832c234d
commit 0934d1b1ea
5 changed files with 312 additions and 20 deletions

View file

@ -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)