summaryrefslogtreecommitdiffstats
path: root/models/webhook.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2017-10-02 00:52:35 +0800
committerLauris BH <lauris@nix.lv>2017-10-01 19:52:35 +0300
commita8717e5e3ace4dd226547faae9c3a44616bbf6f0 (patch)
tree524dc024dec64131406486556951a53655ad8510 /models/webhook.go
parent1ad902d5298202d5be14fd5a9c8ed6ce781a23c8 (diff)
downloadgitea-a8717e5e3ace4dd226547faae9c3a44616bbf6f0.tar.gz
gitea-a8717e5e3ace4dd226547faae9c3a44616bbf6f0.zip
Use AfterLoad instead of AfterSet on Structs (#2628)
* use AfterLoad instead of AfterSet on Structs * fix the comments on AfterLoad * fix the comments on action AfterLoad
Diffstat (limited to 'models/webhook.go')
-rw-r--r--models/webhook.go55
1 files changed, 17 insertions, 38 deletions
diff --git a/models/webhook.go b/models/webhook.go
index bc7926c233..b6d1dff43b 100644
--- a/models/webhook.go
+++ b/models/webhook.go
@@ -19,7 +19,6 @@ import (
"code.gitea.io/gitea/modules/sync"
api "code.gitea.io/sdk/gitea"
- "github.com/go-xorm/xorm"
gouuid "github.com/satori/go.uuid"
)
@@ -112,20 +111,15 @@ type Webhook struct {
UpdatedUnix int64 `xorm:"INDEX updated"`
}
-// AfterSet updates the webhook object upon setting a column
-func (w *Webhook) AfterSet(colName string, _ xorm.Cell) {
- var err error
- switch colName {
- case "events":
- w.HookEvent = &HookEvent{}
- if err = json.Unmarshal([]byte(w.Events), w.HookEvent); err != nil {
- log.Error(3, "Unmarshal[%d]: %v", w.ID, err)
- }
- case "created_unix":
- w.Created = time.Unix(w.CreatedUnix, 0).Local()
- case "updated_unix":
- w.Updated = time.Unix(w.UpdatedUnix, 0).Local()
+// AfterLoad updates the webhook object upon setting a column
+func (w *Webhook) AfterLoad() {
+ w.HookEvent = &HookEvent{}
+ if err := json.Unmarshal([]byte(w.Events), w.HookEvent); err != nil {
+ log.Error(3, "Unmarshal[%d]: %v", w.ID, err)
}
+
+ w.Created = time.Unix(w.CreatedUnix, 0).Local()
+ w.Updated = time.Unix(w.UpdatedUnix, 0).Local()
}
// GetSlackHook returns slack metadata
@@ -432,32 +426,17 @@ func (t *HookTask) BeforeUpdate() {
}
}
-// AfterSet updates the webhook object upon setting a column
-func (t *HookTask) AfterSet(colName string, _ xorm.Cell) {
- var err error
- switch colName {
- case "delivered":
- t.DeliveredString = time.Unix(0, t.Delivered).Format("2006-01-02 15:04:05 MST")
-
- case "request_content":
- if len(t.RequestContent) == 0 {
- return
- }
-
- t.RequestInfo = &HookRequest{}
- if err = json.Unmarshal([]byte(t.RequestContent), t.RequestInfo); err != nil {
- log.Error(3, "Unmarshal[%d]: %v", t.ID, err)
- }
+// AfterLoad updates the webhook object upon setting a column
+func (t *HookTask) AfterLoad() {
+ t.DeliveredString = time.Unix(0, t.Delivered).Format("2006-01-02 15:04:05 MST")
- case "response_content":
- if len(t.ResponseContent) == 0 {
- return
- }
+ if len(t.RequestContent) == 0 {
+ return
+ }
- t.ResponseInfo = &HookResponse{}
- if err = json.Unmarshal([]byte(t.ResponseContent), t.ResponseInfo); err != nil {
- log.Error(3, "Unmarshal [%d]: %v", t.ID, err)
- }
+ t.RequestInfo = &HookRequest{}
+ if err := json.Unmarshal([]byte(t.RequestContent), t.RequestInfo); err != nil {
+ log.Error(3, "Unmarshal[%d]: %v", t.ID, err)
}
}