blob: 78d984cfe760d58ce463e5118c4c793e7c12927e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
}
|