|
|
@ -174,28 +174,32 @@ func CreateWebhook(w *Webhook) error { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetWebhookByRepoID returns webhook of repository by given ID.
|
|
|
|
// getWebhook uses argument bean as query condition,
|
|
|
|
func GetWebhookByRepoID(repoID, id int64) (*Webhook, error) { |
|
|
|
// ID must be specified and do not assign unnecessary fields.
|
|
|
|
w := new(Webhook) |
|
|
|
func getWebhook(bean *Webhook) (*Webhook, error) { |
|
|
|
has, err := x.Id(id).And("repo_id=?", repoID).Get(w) |
|
|
|
has, err := x.Get(bean) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} else if !has { |
|
|
|
} else if !has { |
|
|
|
return nil, ErrWebhookNotExist{id} |
|
|
|
return nil, ErrWebhookNotExist{bean.ID} |
|
|
|
} |
|
|
|
} |
|
|
|
return w, nil |
|
|
|
return bean, nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetWebhookByRepoID returns webhook of repository by given ID.
|
|
|
|
|
|
|
|
func GetWebhookByRepoID(repoID, id int64) (*Webhook, error) { |
|
|
|
|
|
|
|
return getWebhook(&Webhook{ |
|
|
|
|
|
|
|
ID: id, |
|
|
|
|
|
|
|
RepoID: repoID, |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetWebhookByOrgID returns webhook of organization by given ID.
|
|
|
|
// GetWebhookByOrgID returns webhook of organization by given ID.
|
|
|
|
func GetWebhookByOrgID(orgID, id int64) (*Webhook, error) { |
|
|
|
func GetWebhookByOrgID(orgID, id int64) (*Webhook, error) { |
|
|
|
w := new(Webhook) |
|
|
|
return getWebhook(&Webhook{ |
|
|
|
has, err := x.Id(id).And("org_id=?", orgID).Get(w) |
|
|
|
ID: id, |
|
|
|
if err != nil { |
|
|
|
OrgID: orgID, |
|
|
|
return nil, err |
|
|
|
}) |
|
|
|
} else if !has { |
|
|
|
|
|
|
|
return nil, ErrWebhookNotExist{id} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return w, nil |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetActiveWebhooksByRepoID returns all active webhooks of repository.
|
|
|
|
// GetActiveWebhooksByRepoID returns all active webhooks of repository.
|
|
|
@ -216,23 +220,40 @@ func UpdateWebhook(w *Webhook) error { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// DeleteWebhook deletes webhook of repository.
|
|
|
|
// deleteWebhook uses argument bean as query condition,
|
|
|
|
func DeleteWebhook(id int64) (err error) { |
|
|
|
// ID must be specified and do not assign unnecessary fields.
|
|
|
|
|
|
|
|
func deleteWebhook(bean *Webhook) (err error) { |
|
|
|
sess := x.NewSession() |
|
|
|
sess := x.NewSession() |
|
|
|
defer sessionRelease(sess) |
|
|
|
defer sessionRelease(sess) |
|
|
|
if err = sess.Begin(); err != nil { |
|
|
|
if err = sess.Begin(); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if _, err = sess.Delete(&Webhook{ID: id}); err != nil { |
|
|
|
if _, err = sess.Delete(bean); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} else if _, err = sess.Delete(&HookTask{HookID: id}); err != nil { |
|
|
|
} else if _, err = sess.Delete(&HookTask{HookID: bean.ID}); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return sess.Commit() |
|
|
|
return sess.Commit() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// DeleteWebhookByRepoID deletes webhook of repository by given ID.
|
|
|
|
|
|
|
|
func DeleteWebhookByRepoID(repoID, id int64) (error) { |
|
|
|
|
|
|
|
return deleteWebhook(&Webhook{ |
|
|
|
|
|
|
|
ID: id, |
|
|
|
|
|
|
|
RepoID: repoID, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// DeleteWebhookByOrgID deletes webhook of organization by given ID.
|
|
|
|
|
|
|
|
func DeleteWebhookByOrgID(orgID, id int64) (error) { |
|
|
|
|
|
|
|
return deleteWebhook(&Webhook{ |
|
|
|
|
|
|
|
ID: id, |
|
|
|
|
|
|
|
OrgID: orgID, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetWebhooksByOrgID returns all webhooks for an organization.
|
|
|
|
// GetWebhooksByOrgID returns all webhooks for an organization.
|
|
|
|
func GetWebhooksByOrgID(orgID int64) (ws []*Webhook, err error) { |
|
|
|
func GetWebhooksByOrgID(orgID int64) (ws []*Webhook, err error) { |
|
|
|
err = x.Find(&ws, &Webhook{OrgID: orgID}) |
|
|
|
err = x.Find(&ws, &Webhook{OrgID: orgID}) |
|
|
|