1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-05-11 05:55:29 +00:00

Finish add web hook

This commit is contained in:
Unknown
2014-05-05 20:52:25 -04:00
parent cb505b22ec
commit 24f614f6db
8 changed files with 143 additions and 22 deletions

View File

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

58
models/webhook.go Normal file
View File

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