Skip to content

Commit 4a4fc73

Browse files
authored
Fix migration (#10641)
Signed-off-by: jolheiser <[email protected]>
1 parent f7a6763 commit 4a4fc73

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

models/migrations/v130.go

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,51 @@ package migrations
77
import (
88
"encoding/json"
99

10+
"code.gitea.io/gitea/modules/setting"
11+
1012
"xorm.io/xorm"
1113
)
1214

1315
func expandWebhooks(x *xorm.Engine) error {
1416

15-
type ChooseEvents struct {
17+
type HookEvents struct {
18+
Create bool `json:"create"`
19+
Delete bool `json:"delete"`
20+
Fork bool `json:"fork"`
1621
Issues bool `json:"issues"`
1722
IssueAssign bool `json:"issue_assign"`
1823
IssueLabel bool `json:"issue_label"`
1924
IssueMilestone bool `json:"issue_milestone"`
2025
IssueComment bool `json:"issue_comment"`
26+
Push bool `json:"push"`
2127
PullRequest bool `json:"pull_request"`
2228
PullRequestAssign bool `json:"pull_request_assign"`
2329
PullRequestLabel bool `json:"pull_request_label"`
2430
PullRequestMilestone bool `json:"pull_request_milestone"`
2531
PullRequestComment bool `json:"pull_request_comment"`
2632
PullRequestReview bool `json:"pull_request_review"`
2733
PullRequestSync bool `json:"pull_request_sync"`
34+
Repository bool `json:"repository"`
35+
Release bool `json:"release"`
2836
}
2937

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"`
3645
}
3746

3847
type Webhook struct {
3948
ID int64
4049
Events string
4150
}
4251

43-
var events Events
4452
var bytes []byte
4553
var last int
46-
const batchSize = 50
54+
batchSize := setting.Database.IterateBufferSize
4755
sess := x.NewSession()
4856
defer sess.Close()
4957
for {
@@ -63,24 +71,29 @@ func expandWebhooks(x *xorm.Engine) error {
6371
last += len(results)
6472

6573
for _, res := range results {
74+
var events HookEvent
6675
if err = json.Unmarshal([]byte(res.Events), &events); err != nil {
6776
return err
6877
}
6978

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
7588
}
7689

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
8497
}
8598

8699
if bytes, err = json.Marshal(&events); err != nil {

0 commit comments

Comments
 (0)