@@ -12,6 +12,7 @@ import (
12
12
"code.gitea.io/gitea/modules/log"
13
13
"code.gitea.io/gitea/modules/setting"
14
14
api "code.gitea.io/gitea/modules/structs"
15
+ "code.gitea.io/gitea/modules/timeutil"
15
16
webhook_module "code.gitea.io/gitea/modules/webhook"
16
17
17
18
gouuid "github.com/google/uuid"
@@ -40,15 +41,14 @@ type HookResponse struct {
40
41
41
42
// HookTask represents a hook task.
42
43
type 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
52
52
53
53
// History info.
54
54
IsSucceed bool
@@ -75,8 +75,6 @@ func (t *HookTask) BeforeUpdate() {
75
75
76
76
// AfterLoad updates the webhook object upon setting a column
77
77
func (t * HookTask ) AfterLoad () {
78
- t .DeliveredString = time .Unix (0 , t .Delivered ).Format ("2006-01-02 15:04:05 MST" )
79
-
80
78
if len (t .RequestContent ) == 0 {
81
79
return
82
80
}
@@ -115,12 +113,17 @@ func HookTasks(hookID int64, page int) ([]*HookTask, error) {
115
113
// CreateHookTask creates a new hook task,
116
114
// it handles conversion from Payload to PayloadContent.
117
115
func CreateHookTask (ctx context.Context , t * HookTask ) (* HookTask , error ) {
118
- data , err := t .Payloader .JSONPayload ()
119
- if err != nil {
120
- return nil , err
121
- }
122
116
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
+ }
124
127
return t , db .Insert (ctx , t )
125
128
}
126
129
@@ -161,13 +164,11 @@ func ReplayHookTask(ctx context.Context, hookID int64, uuid string) (*HookTask,
161
164
}
162
165
}
163
166
164
- newTask := & HookTask {
165
- UUID : gouuid .New ().String (),
167
+ return CreateHookTask (ctx , & HookTask {
166
168
HookID : task .HookID ,
167
169
PayloadContent : task .PayloadContent ,
168
170
EventType : task .EventType ,
169
- }
170
- return newTask , db .Insert (ctx , newTask )
171
+ })
171
172
}
172
173
173
174
// FindUndeliveredHookTaskIDs will find the next 100 undelivered hook tasks with ID greater than the provided lowerID
0 commit comments