@@ -7,43 +7,51 @@ package migrations
7
7
import (
8
8
"encoding/json"
9
9
10
+ "code.gitea.io/gitea/modules/setting"
11
+
10
12
"xorm.io/xorm"
11
13
)
12
14
13
15
func expandWebhooks (x * xorm.Engine ) error {
14
16
15
- type ChooseEvents struct {
17
+ type HookEvents struct {
18
+ Create bool `json:"create"`
19
+ Delete bool `json:"delete"`
20
+ Fork bool `json:"fork"`
16
21
Issues bool `json:"issues"`
17
22
IssueAssign bool `json:"issue_assign"`
18
23
IssueLabel bool `json:"issue_label"`
19
24
IssueMilestone bool `json:"issue_milestone"`
20
25
IssueComment bool `json:"issue_comment"`
26
+ Push bool `json:"push"`
21
27
PullRequest bool `json:"pull_request"`
22
28
PullRequestAssign bool `json:"pull_request_assign"`
23
29
PullRequestLabel bool `json:"pull_request_label"`
24
30
PullRequestMilestone bool `json:"pull_request_milestone"`
25
31
PullRequestComment bool `json:"pull_request_comment"`
26
32
PullRequestReview bool `json:"pull_request_review"`
27
33
PullRequestSync bool `json:"pull_request_sync"`
34
+ Repository bool `json:"repository"`
35
+ Release bool `json:"release"`
28
36
}
29
37
30
- type Events struct {
31
- PushOnly bool `json:"push_only"`
32
- SendEverything bool `json:"send_everything"`
33
- ChooseEvents bool `json:"choose_events"`
34
- BranchFilter string `json:"branch_filter"`
35
- Events ChooseEvents `json:"events"`
38
+ type HookEvent struct {
39
+ PushOnly bool `json:"push_only"`
40
+ SendEverything bool `json:"send_everything"`
41
+ ChooseEvents bool `json:"choose_events"`
42
+ BranchFilter string `json:"branch_filter"`
43
+
44
+ HookEvents `json:"events"`
36
45
}
37
46
38
47
type Webhook struct {
39
48
ID int64
40
49
Events string
41
50
}
42
51
43
- var events Events
44
52
var bytes []byte
45
53
var last int
46
- const batchSize = 50
54
+ batchSize := setting . Database . IterateBufferSize
47
55
sess := x .NewSession ()
48
56
defer sess .Close ()
49
57
for {
@@ -63,24 +71,29 @@ func expandWebhooks(x *xorm.Engine) error {
63
71
last += len (results )
64
72
65
73
for _ , res := range results {
74
+ var events HookEvent
66
75
if err = json .Unmarshal ([]byte (res .Events ), & events ); err != nil {
67
76
return err
68
77
}
69
78
70
- if events .Events .Issues {
71
- events .Events .IssueAssign = true
72
- events .Events .IssueLabel = true
73
- events .Events .IssueMilestone = true
74
- events .Events .IssueComment = true
79
+ if ! events .ChooseEvents {
80
+ continue
81
+ }
82
+
83
+ if events .Issues {
84
+ events .IssueAssign = true
85
+ events .IssueLabel = true
86
+ events .IssueMilestone = true
87
+ events .IssueComment = true
75
88
}
76
89
77
- if events .Events . PullRequest {
78
- events .Events . PullRequestAssign = true
79
- events .Events . PullRequestLabel = true
80
- events .Events . PullRequestMilestone = true
81
- events .Events . PullRequestComment = true
82
- events .Events . PullRequestReview = true
83
- events .Events . PullRequestSync = true
90
+ if events .PullRequest {
91
+ events .PullRequestAssign = true
92
+ events .PullRequestLabel = true
93
+ events .PullRequestMilestone = true
94
+ events .PullRequestComment = true
95
+ events .PullRequestReview = true
96
+ events .PullRequestSync = true
84
97
}
85
98
86
99
if bytes , err = json .Marshal (& events ); err != nil {
0 commit comments