diff options
Diffstat (limited to 'models/webhook.go')
-rw-r--r-- | models/webhook.go | 55 |
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) } } |