diff options
author | Unknown <joe2010xtmf@163.com> | 2014-05-05 20:52:25 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-05-05 20:52:25 -0400 |
commit | 24f614f6db13e5c6720efa518641ffcdcb0d8947 (patch) | |
tree | 523d1d93079bed85b75859b51bff408797ed4aae /models | |
parent | cb505b22ec5133ffe3263f3857fdcd64fa64260b (diff) | |
download | gitea-24f614f6db13e5c6720efa518641ffcdcb0d8947.tar.gz gitea-24f614f6db13e5c6720efa518641ffcdcb0d8947.zip |
Finish add web hook
Diffstat (limited to 'models')
-rw-r--r-- | models/models.go | 2 | ||||
-rw-r--r-- | models/webhook.go | 58 |
2 files changed, 59 insertions, 1 deletions
diff --git a/models/models.go b/models/models.go index b565f22ab1..ebb558fcc8 100644 --- a/models/models.go +++ b/models/models.go @@ -34,7 +34,7 @@ var ( func init() { tables = append(tables, new(User), new(PublicKey), new(Repository), new(Watch), new(Action), new(Access), new(Issue), new(Comment), new(Oauth2), new(Follow), - new(Mirror), new(Release), new(LoginSource)) + new(Mirror), new(Release), new(LoginSource), new(Webhook)) } func LoadModelsConfig() { diff --git a/models/webhook.go b/models/webhook.go new file mode 100644 index 0000000000..78d984cfe7 --- /dev/null +++ b/models/webhook.go @@ -0,0 +1,58 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package models + +import ( + "encoding/json" + + "github.com/gogits/gogs/modules/log" +) + +// Content types. +const ( + CT_JSON = iota + 1 + CT_FORM +) + +type HookEvent struct { + PushOnly bool `json:"push_only"` +} + +type Webhook struct { + Id int64 + RepoId int64 + Payload string `xorm:"TEXT"` + ContentType int + Secret string `xorm:"TEXT"` + Events string `xorm:"TEXT"` + IsSsl bool + IsActive bool +} + +func (w *Webhook) GetEvent() *HookEvent { + h := &HookEvent{} + if err := json.Unmarshal([]byte(w.Events), h); 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) + w.Events = string(data) + return err +} + +// CreateWebhook creates new webhook. +func CreateWebhook(w *Webhook) error { + _, err := orm.Insert(w) + return err +} + +// GetWebhooksByRepoId returns all webhooks of repository. +func GetWebhooksByRepoId(repoId int64) (ws []*Webhook, err error) { + err = orm.Find(&ws, &Webhook{RepoId: repoId}) + return ws, err +} |