mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-05-28 03:00:03 +02:00
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
This commit is contained in:
parent
1ad902d529
commit
a8717e5e3a
35 changed files with 334 additions and 315 deletions
|
@ -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")
|
||||
// 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 "request_content":
|
||||
if len(t.RequestContent) == 0 {
|
||||
return
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
case "response_content":
|
||||
if len(t.ResponseContent) == 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue