@@ -12,6 +12,7 @@ import (
1212 "code.gitea.io/gitea/modules/log"
1313 "code.gitea.io/gitea/modules/setting"
1414 api "code.gitea.io/gitea/modules/structs"
15+ "code.gitea.io/gitea/modules/timeutil"
1516 webhook_module "code.gitea.io/gitea/modules/webhook"
1617
1718 gouuid "github.com/google/uuid"
@@ -40,15 +41,14 @@ type HookResponse struct {
4041
4142// HookTask represents a hook task.
4243type HookTask struct {
43- ID int64 `xorm:"pk autoincr"`
44- HookID int64 `xorm:"index"`
45- UUID string `xorm:"unique"`
46- api.Payloader `xorm:"-"`
47- PayloadContent string `xorm:"LONGTEXT"`
48- EventType webhook_module.HookEventType
49- IsDelivered bool
50- Delivered int64
51- DeliveredString string `xorm:"-"`
44+ ID int64 `xorm:"pk autoincr"`
45+ HookID int64 `xorm:"index"`
46+ UUID string `xorm:"unique"`
47+ api.Payloader `xorm:"-"`
48+ PayloadContent string `xorm:"LONGTEXT"`
49+ EventType webhook_module.HookEventType
50+ IsDelivered bool
51+ Delivered timeutil.TimeStampNano
5252
5353 // History info.
5454 IsSucceed bool
@@ -75,8 +75,6 @@ func (t *HookTask) BeforeUpdate() {
7575
7676// AfterLoad updates the webhook object upon setting a column
7777func (t * HookTask ) AfterLoad () {
78- t .DeliveredString = time .Unix (0 , t .Delivered ).Format ("2006-01-02 15:04:05 MST" )
79-
8078 if len (t .RequestContent ) == 0 {
8179 return
8280 }
@@ -115,12 +113,17 @@ func HookTasks(hookID int64, page int) ([]*HookTask, error) {
115113// CreateHookTask creates a new hook task,
116114// it handles conversion from Payload to PayloadContent.
117115func CreateHookTask (ctx context.Context , t * HookTask ) (* HookTask , error ) {
118- data , err := t .Payloader .JSONPayload ()
119- if err != nil {
120- return nil , err
121- }
122116 t .UUID = gouuid .New ().String ()
123- t .PayloadContent = string (data )
117+ if t .Payloader != nil {
118+ data , err := t .Payloader .JSONPayload ()
119+ if err != nil {
120+ return nil , err
121+ }
122+ t .PayloadContent = string (data )
123+ }
124+ if t .Delivered == 0 {
125+ t .Delivered = timeutil .TimeStampNanoNow ()
126+ }
124127 return t , db .Insert (ctx , t )
125128}
126129
@@ -161,13 +164,11 @@ func ReplayHookTask(ctx context.Context, hookID int64, uuid string) (*HookTask,
161164 }
162165 }
163166
164- newTask := & HookTask {
165- UUID : gouuid .New ().String (),
167+ return CreateHookTask (ctx , & HookTask {
166168 HookID : task .HookID ,
167169 PayloadContent : task .PayloadContent ,
168170 EventType : task .EventType ,
169- }
170- return newTask , db .Insert (ctx , newTask )
171+ })
171172}
172173
173174// FindUndeliveredHookTaskIDs will find the next 100 undelivered hook tasks with ID greater than the provided lowerID
0 commit comments