diff options
author | Unknown <joe2010xtmf@163.com> | 2014-05-05 21:36:08 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-05-05 21:36:08 -0400 |
commit | 94bccbb148a4ed897eb8332fc746aa75486c5c4d (patch) | |
tree | d731481cd20e375bb62c420abdadf788db02feda /models/webhook.go | |
parent | 24f614f6db13e5c6720efa518641ffcdcb0d8947 (diff) | |
download | gitea-94bccbb148a4ed897eb8332fc746aa75486c5c4d.tar.gz gitea-94bccbb148a4ed897eb8332fc746aa75486c5c4d.zip |
Finish edit and remove web hook
Diffstat (limited to 'models/webhook.go')
-rw-r--r-- | models/webhook.go | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/models/webhook.go b/models/webhook.go index 78d984cfe7..daa4510f2d 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -6,10 +6,15 @@ package models import ( "encoding/json" + "errors" "github.com/gogits/gogs/modules/log" ) +var ( + ErrWebhookNotExist = errors.New("Webhook does not exist") +) + // Content types. const ( CT_JSON = iota + 1 @@ -27,20 +32,20 @@ type Webhook struct { ContentType int Secret string `xorm:"TEXT"` Events string `xorm:"TEXT"` + *HookEvent `xorm:"-"` IsSsl bool IsActive bool } -func (w *Webhook) GetEvent() *HookEvent { - h := &HookEvent{} - if err := json.Unmarshal([]byte(w.Events), h); err != nil { +func (w *Webhook) GetEvent() { + w.HookEvent = &HookEvent{} + if err := json.Unmarshal([]byte(w.Events), w.HookEvent); err != nil { log.Error("webhook.GetEvent(%d): %v", w.Id, err) } - return h } -func (w *Webhook) SaveEvent(h *HookEvent) error { - data, err := json.Marshal(h) +func (w *Webhook) SaveEvent() error { + data, err := json.Marshal(w.HookEvent) w.Events = string(data) return err } @@ -51,8 +56,32 @@ func CreateWebhook(w *Webhook) error { return err } +// UpdateWebhook updates information of webhook. +func UpdateWebhook(w *Webhook) error { + _, err := orm.AllCols().Update(w) + return err +} + +// GetWebhookById returns webhook by given ID. +func GetWebhookById(hookId int64) (*Webhook, error) { + w := &Webhook{Id: hookId} + has, err := orm.Get(w) + if err != nil { + return nil, err + } else if !has { + return nil, ErrWebhookNotExist + } + return w, nil +} + // GetWebhooksByRepoId returns all webhooks of repository. func GetWebhooksByRepoId(repoId int64) (ws []*Webhook, err error) { err = orm.Find(&ws, &Webhook{RepoId: repoId}) return ws, err } + +// DeleteWebhook deletes webhook of repository. +func DeleteWebhook(hookId int64) error { + _, err := orm.Delete(&Webhook{Id: hookId}) + return err +} |